[英]Jacoco in Android project - what am I missing?
Seemed like adding Jacoco to an Android project would be a straightforward process, but so far it's been nothing but pain.似乎将 Jacoco 添加到 Android 项目将是一个简单的过程,但到目前为止,它只是痛苦。
Having tried a few guides to getting it working, this one seems to give the best results for me so far:在尝试了一些让它工作的指南之后,到目前为止,这个似乎对我来说是最好的结果:
https://medium.com/nerd-for-tech/setup-jacoco-code-coverage-with-your-multimodule-android-app-kotlin-a0f82573a1 https://medium.com/nerd-for-tech/setup-jacoco-code-coverage-with-your-multimodule-android-app-kotlin-a0f82573a1
But shortly after it all goes wrong.但不久之后一切都出错了。 Turns out that to use kotlin 1.5+ (which the project I'm adding to does) you need to use jacoco version 0.8.7 or higher.
事实证明,要使用 kotlin 1.5+(我正在添加的项目),您需要使用 jacoco 版本 0.8.7 或更高版本。 So I've done that.
所以我已经做到了。
But using versions of jacoco beyond 0.8.3 causes the build to fail with complaints about $jacocoData.但是使用超过 0.8.3 的 jacoco 版本会导致构建失败并抱怨 $jacocoData。
A search on the error message from that suggests setting the compile/target versions to VERSION_1_8 instead of VERSION_11.对错误消息的搜索建议将编译/目标版本设置为 VERSION_1_8 而不是 VERSION_11。 Okay, give that a go, but then the build fails with errors like:
好的,给它一个 go,但是构建失败并出现如下错误:
> Duplicate class com.google.android.gms.common.api.internal.zza found in modules jetified-play-services-base-15.0.1-runtime (com.google.android.gms:play-services-base:15.0.1) and jetified-play-services-basement-17.2.1-runtime (com.google.android.gms:play-services-basement:17.2.1)
Is there a clear guide anywhere to getting code coverage data out of an Android project written in Java 11 and kotlin 1.5+ with multiple variants?从 Java 11 和 kotlin 1.5+ 中编写的具有多个变体的 Android 项目中获取代码覆盖率数据是否有明确的指南? Because this is something that seems like it should be easy but is actually turning out to be incredibly painful...
因为这是一件看起来应该很容易但实际上却非常痛苦的事情......
I already faced this situation this is working for me.我已经遇到过这种情况,这对我有用。
Build.gradle(project) Build.gradle(项目)
Build.gradle(Module ) Build.gradle(模块)
plugins{
id 'jacoco'
}
jacoco {
toolVersion = "0.8.7"
}
android{
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
testCoverageEnabled true //jacoco see https://stackoverflow.com/a/39262886/6478047
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
testOptions {
animationsDisabled true
unitTests.includeAndroidResources = true
}
packagingOptions {
resources.excludes.add("META-INF/*")
exclude "**/attach_hotspot_windows.dll"
exclude "META-INF/licenses/**"
exclude "META-INF/AL2.0"
exclude "META-INF/LGPL2.1"
}
}
dependencies {}
configurations.all {
resolutionStrategy {
eachDependency { details ->
if ('org.jacoco' == details.requested.group) {
details.useVersion "0.8.7"
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.