【问题标题】:unable to use custom buildType - Active build variant "debug" does not have a test artifact无法使用自定义 buildType - 活动构建变体“调试”没有测试工件
【发布时间】:2020-05-28 13:45:44
【问题描述】:

我环顾四周,发现一些与我的问题非常相似的问题,但它似乎确实有与我相同的解决方案,但无法解决问题。

当我尝试运行方法测试时,我在 android studio 的页脚中收到一条错误消息,指出“Active build variant “debug”没有测试工件”

我想使用不同的 buildType 进行仪器测试,以便我可以更改 API 路径。除非我设置testBuildType "debug"

,否则它似乎不会构建和运行

这是我的 gradle 的样子

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    ...
    testBuildType "staging"

    defaultConfig {
        ...
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        debug {
            manifestPlaceholders.enableCrashReporting = "false"
            manifestPlaceholders.disableAnalytics = "true"

            buildConfigField "String", "API_DOMAIN", '"https://domain/dev/"'
        }

        staging {
            initWith debug
            buildConfigField "String", "API_DOMAIN", '"/"'
        }

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

            manifestPlaceholders.enableCrashReporting = "true"
            manifestPlaceholders.disableAnalytics = "false"

            buildConfigField "String", "API_DOMAIN", '"https://domain/prod/"'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    viewBinding {
        enabled = true
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }

    testOptions {
        unitTests.includeAndroidResources = true
        unitTests.returnDefaultValues = true
    }
}

dependencies {
    ...
}

【问题讨论】:

    标签: android build.gradle android-testing android-build-type instrumented-test


    【解决方案1】:

    在这篇文章中找到了答案。似乎 Active Build Variant 不会像预期的那样自行更改。

    android testBuildType not working

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多