android - Activity 构建变体没有测试 Artifact

标签 android gradle android-gradle-plugin android-testing android-gradle-3.0

我基于“调试”构建变体创建了一个名为“bitrise”的新构建类型。使用“调试”构建变体时,检测的 androidTests 构建并运行良好,但是当我切换到新的“bitrise”构建变体时,出现以下错误:

Process finished with exit code 1
Class not found: "com.mycompany.app.ui.race.RaceFragmentUiTest"

当我选择“Edit Configurations...”->“Android Instrumented Tests”时出现此警告
Warning: Active build variant "myCompanyBitrise" does not have a test artifact.

版本

'com.android.tools.build:gradle:3.5.2'

安卓工作室 3.5.2

这是 摘录从我的 Gradle 文件中:
buildTypes {
    debug {
        debuggable true
        testCoverageEnabled = false
        applicationIdSuffix ".debug"
        buildConfigField("String", "BASE_ENDPOINT", BASE_ENDPOINT_DEBUG)
    }
    release {
        minifyEnabled true
        zipAlignEnabled true
        shrinkResources true
        buildConfigField("String", "BASE_ENDPOINT", BASE_ENDPOINT_PROD)
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    bitrise {
        initWith debug
        buildConfigField("String", "BASE_ENDPOINT", BASE_ENDPOINT_PROD)
    }
}

flavorDimensions "version"

productFlavors {
    mycompany {
        dimension "version"
        applicationId "com.mycompany.app"
    }
    second {
        dimension "version"
        applicationId "com.second.app"
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'com.squareup.okhttp3:okhttp:3.10.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.newrelic.agent.android:android-agent:5.24.1'
    implementation 'com.github.bumptech.glide:glide:4.3.0'
    implementation 'io.supercharge:shimmerlayout:2.0.0'
    implementation 'com.google.firebase:firebase-core:17.2.1'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    kapt 'androidx.lifecycle:lifecycle-common-java8:2.1.0'
    testImplementation 'org.hamcrest:hamcrest-library:1.3'
    testImplementation 'commons-logging:commons-logging:1.2'

    /**
     * Google architecture components
     */
    implementation 'androidx.lifecycle:lifecycle-viewmodel:2.1.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
    testImplementation 'androidx.arch.core:core-testing:2.1.0'
    testImplementation 'androidx.annotation:annotation:1.1.0'
    androidTestImplementation 'androidx.arch.core:core-testing:2.1.0'
    androidTestImplementation 'androidx.annotation:annotation:1.1.0'

    /**
     * AWS IoT
     */
    implementation 'com.amazonaws:aws-android-sdk-iot:2.15.2'
    implementation 'com.amazonaws:aws-android-sdk-mobile-client:2.15.2'
    testImplementation 'com.amazonaws:aws-android-sdk-iot:2.15.2'

    /**
     * Dagger DI dependencies
     */
    implementation 'com.google.dagger:dagger:2.24'
    kapt 'com.google.dagger:dagger-compiler:2.24'

    /**
     * Volley for network communication
     */
    implementation 'com.android.volley:volley:1.1.1'

    /**
     * Unit testing
     */
    testImplementation 'org.json:json:20190722'
    testImplementation 'org.mockito:mockito-core:3.0.0'
    testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
    testImplementation 'junit:junit:4.12'

    /**
     * Instrumentation testing
     */
    androidTestImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0'
    androidTestImplementation 'org.mockito:mockito-android:2.25.0'
    androidTestImplementation 'androidx.test:rules:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    debugImplementation 'androidx.fragment:fragment-testing:1.2.0-rc02'

    /**
     * Json parsing
     */
    implementation 'com.squareup.moshi:moshi:1.9.2'
    kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.9.2'
}

我的单元测试在所有配置中都运行良好,我只有 Android Instrumented Tests 存在问题

我已经尝试了这些步骤:https://developer.android.com/studio/build/build-variants#sourcesets , TestCase class not found by Android Studio , Android Studio Unit Testing: unable to find instrumentation OR class not found ex

最佳答案

您可以将其添加到您的 build.gradle 文件中

android {
    testBuildType "MycompanyBitrise" // or whatever build varient where you are getting 
                                       such error
}

关于android - Activity 构建变体没有测试 Artifact ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59153826/

相关文章:

android - 在 Maps V2 中使用自定义字体

java - 尝试读取我编写的文件时出现 FileNotFoundException

android - 项目刷新失败,JetGradlePlugin$_apply_closure2$_closure4

android - gradle-experimental:0.1.0 buildConfigField

android - 错误:无法获得类型为org.gradle.api.Project的项目 'appcompat'的未知属性 ':app'

android - 有超时的Android InputStream类吗?

android - Gradle依赖项Groovy关闭语法

android - 如何使用 Java 8 在 Android 和桌面(IntelliJ 2018 CE/Gradle)上使用 libGDX 进行开发

android - Gradle with java 8 for retrolambda - Android 找不到注释 TargetApi

Android 资源链接失败 Android Studio 3.3