Android connectedCheck 任务在 运行 与构建任务一起失败时失败,但在单独 运行 时失败
Android connectedCheck task fails when run with the build task but not when run alone
$ ./gradlew clean build connectedCheck
产量
Unable to find instrumentation target package: my.package
com.android.builder.testing.ConnectedDevice > hasTests FAILED
No tests found.
:app:connectedAndroidTest FAILED
而
$ ./gradlew clean check connectedCheck
结果
...
:app:connectedAndroidTest
BUILD SUCCESSFUL
我的设置的唯一独特之处在于我有一个纯 java 模块,该模块使用 'java'
Gradle 插件旁边的 android 应用程序使用 android 构建工具 Gradle 插件:
project
- core (pure java)
- app (com.android.application)
并且应用项目对核心项目的工件具有编译时依赖性:
# app/build.gradle
depenedencies {
compile project(':core')
}
我正在使用构建工具 21.1.2 和 sdk 工具 24.0.2.
编辑
我忘了说我还做了一个不寻常的步骤,就是重命名 apk 的输出文件:
android.applicationVariants.all { variant ->
def apkVariant = variant.outputs[0]
def outputFile = apkVariant.outputFile
def versionName = android.defaultConfig.versionName
def newName = outputFile.getName().replace(".apk", "-${versionName}.apk")
apkVariant.outputFile = file("${outputFile.parentFile}/newName")
}
删除此代码可以解决问题。但是,我想知道为什么。
重命名逻辑中存在拼写错误。
def newName = outputFile.getName().replace(".apk", "-${versionName}.apk")
apkVariant.outputFile = file("${outputFile.parentFile}/newName")
我忘了 '$'
。应该是:
apkVariant.outputFile = file("${outputFile.parentFile}/$newName")
由于拼写错误,所有应用程序变体都共享相同的输出文件,而我的测试 apk 被构建中的下一个变体覆盖。
$ ./gradlew clean build connectedCheck
产量
Unable to find instrumentation target package: my.package
com.android.builder.testing.ConnectedDevice > hasTests FAILED
No tests found.
:app:connectedAndroidTest FAILED
而
$ ./gradlew clean check connectedCheck
结果
...
:app:connectedAndroidTest
BUILD SUCCESSFUL
我的设置的唯一独特之处在于我有一个纯 java 模块,该模块使用 'java'
Gradle 插件旁边的 android 应用程序使用 android 构建工具 Gradle 插件:
project
- core (pure java)
- app (com.android.application)
并且应用项目对核心项目的工件具有编译时依赖性:
# app/build.gradle
depenedencies {
compile project(':core')
}
我正在使用构建工具 21.1.2 和 sdk 工具 24.0.2.
编辑
我忘了说我还做了一个不寻常的步骤,就是重命名 apk 的输出文件:
android.applicationVariants.all { variant ->
def apkVariant = variant.outputs[0]
def outputFile = apkVariant.outputFile
def versionName = android.defaultConfig.versionName
def newName = outputFile.getName().replace(".apk", "-${versionName}.apk")
apkVariant.outputFile = file("${outputFile.parentFile}/newName")
}
删除此代码可以解决问题。但是,我想知道为什么。
重命名逻辑中存在拼写错误。
def newName = outputFile.getName().replace(".apk", "-${versionName}.apk")
apkVariant.outputFile = file("${outputFile.parentFile}/newName")
我忘了 '$'
。应该是:
apkVariant.outputFile = file("${outputFile.parentFile}/$newName")
由于拼写错误,所有应用程序变体都共享相同的输出文件,而我的测试 apk 被构建中的下一个变体覆盖。