无法使用自定义构建类型 - 活动构建变体"调试"没有测试工件



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

当我尝试运行方法测试时,我在 android 工作室的页脚中收到一个错误,指出"活动构建变体"调试"没有测试工件">

我想使用不同的 buildType 进行插桩测试,以便我可以更改 API 路径。除非我设置testBuildType "debug"否则它似乎不会构建和运行

这是我的成绩长什么样子

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 {
...
}

在这篇文章中找到了答案。 似乎活动构建变体不会像人们预期的那样自行更改。

安卓测试构建类型不起作用

最新更新