Active build variant does not have a test artifact
Asked Answered
V

2

13

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" Warning: Active build variant "myCompanyBitrise" does not have a test artifact.

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

Victual answered 3/12, 2019 at 9:24 Comment(0)
Q
20

You can add this to your build.gradle file

android {
    testBuildType "MycompanyBitrise" // or whatever build varient where you are getting 
                                       such error
}
Quinta answered 9/12, 2019 at 12:51 Comment(2)
hello thanks for this fix, could you please expand on why this error occurs and why adding this line fixes it? Perhaps any link? Thank you.Berton
developer.android.com/studio/build/…Radiotransparent
C
1

Or Just switch to debuggable flavour/buildType. Solved issue for me :)

Cordate answered 25/2, 2021 at 6:53 Comment(1)
I just kept changing the active build variant until I found one that workedKimberlykimberlyn

© 2022 - 2024 — McMap. All rights reserved.