Active build variant does not have a test artifact

烂漫一生 提交于 2020-12-29 11:47:29

问题


I have created a new build type called 'bitrise' based on the 'debug' build variant. The instrumented androidTests build and run fine when using the 'debug' build variant however when I switch over to my new 'bitrise' build variant I get the following errors:

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

And this warning when I select "Edit Configurations..." -> "Android Instrumented Tests"

Versions

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

Android Studio 3.5.2

This is an extract from my Gradle file:

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'
}

My unit tests run fine in all configurations, I only have an issue with Android Instrumented Tests

I have tried these steps: 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


回答1:


You can add this to your build.gradle file

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


来源:https://stackoverflow.com/questions/59153826/active-build-variant-does-not-have-a-test-artifact

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!