Running Checker Framework on Android - android

I want to use Checker Framework to do some static analysis of my app- checking for Nullability failures, UI constraint failures, etc at runtime. I followed the instructions at https://checkerframework.org/manual/#android-gradle to try and make it run, but I'm getting an error that checkTypes is not a task. I think I followed the instructions correctly, and I fixed the capitalization mismatch they had. ANy ideas how to fix it? My build.gradle is below:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
google()
}
apply plugin: 'jacoco'
apply plugin: 'com.getkeepsafe.dexcount'
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xmaxerrs" << "500"
}
}
android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.handshake.hsdm"
minSdkVersion 19
targetSdkVersion 25
versionCode 35
versionName "0.0.35"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
testCoverageEnabled = false
}
debug {
testCoverageEnabled = false
}
checkTypes {
javaCompileOptions.annotationProcessorOptions.
classNames.add("org.checkerframework.checker.guieffect.GuiEffectChecker")
// You can pass options like so:
// javaCompileOptions.annotationProcessorOptions.arguments.put("warns", "")
}
}
dexOptions {
preDexLibraries = false
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
}
}
packagingOptions {
//These files constantly step on each other from multiple libraries, don't include them
exclude 'META-INF/ASL2.0'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/*'
exclude 'plugin.xml'
exclude 'plugin.properties'
exclude 'about_files/LICENSE-2.0.txt'
}
testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
}
}
jacoco {
version = '0.7.3.201502191951'
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:2.0.1'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
configurations {
checkerFrameworkAnnotatedJDK {
description = 'a copy of JDK classes with Checker Framework type qualifers inserted'
}
}
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
reports {
xml.enabled = true
html.enabled = true
}
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*',
'com/handshake/hsdm/demo/**','com/handshake/hsdm/localstorage/schema1/*Dao*',
'com/handshake/hsdm/localstorage/schema1/*Factory*', 'com/handshake/hsdm/dagger2',
'**/*Module*', '**/*_Factory*', '**/*_MembersInjector*'
]
def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter)
def mainSrc = "${project.projectDir}/src/main/java"
sourceDirectories = files([mainSrc])
classDirectories = files([debugTree])
executionData = fileTree(dir: "$buildDir", includes: [
"jacoco/testDebugUnitTest.exec",
"outputs/code-coverage/connected/*coverage.ec"
])
afterEvaluate {
classDirectories = files(classDirectories.files.collect {
fileTree(dir: it, exclude: ['com/handshake/hsdm/demo/**'])
})
}
}
dependencies {
//Clipping dependencies
ext.checkerFrameworkVersion = '2.2.1'
implementation "org.checkerframework:checker-qual:${checkerFrameworkVersion}"
annotationProcessor "org.checkerframework:checker:${checkerFrameworkVersion}"
checkerFrameworkAnnotatedJDK "org.checkerframework:jdk8:${checkerFrameworkVersion}"
}
apply plugin: 'com.google.gms.google-services'
gradle.projectsEvaluated {
tasks.withType(JavaCompile).all { compile ->
if (compile.name.contains("checkTypes")) {
compile.options.compilerArgs += [
"-Xbootclasspath/p:${configurations.checkerFrameworkAnnotatedJDK.asPath}"
]
}
}
}
Edit: For future readers- the line javaCompileOptions.annotationProcessorOptions.classNames +=["org.checkerframework.checker.nullness.NullnessChecker"] seems to be the problem. removing it runs dagger and other annotation processors, but obviously won't run the checker.

So apparently if you specify 1 annotation processor via classnames, it overwrites any others. So I had to specify dagger and autofactory as well. Then I can either run it from Android Studio as a build, or from command line as:
gradlew assembleCheckTypes

Related

Failed to load library from git in androidStudio

I'm trying to barteksc/AndroidPdfViewer in my android project but it fail to load the lib and I can't figure out why... Any Idea?
Here's my config :
build.gradle (:app)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'jacoco'
id 'com.google.gms.google-services'
id 'dagger.hilt.android.plugin'
}
apply plugin: 'kotlin-kapt'
android {
compileSdk 31
defaultConfig {
applicationId "com.github.multimatum_team.multimatum"
minSdk 26
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "com.github.multimatum_team.multimatum.MultimatumTestRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
testOptions {
unitTests {
includeAndroidResources = true
returnDefaultValues = true
}
}
testCoverage {
jacocoVersion = "0.8.7"
}
}
dependencies {
implementation fileTree(dir: "libs", include:["*.jar"])
implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'
implementation 'com.google.code.gson:gson:2.8.9'
implementation "androidx.preference:preference-ktx:1.2.0"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
....
testImplementation 'org.mockito:mockito-core:4.4.0'
testImplementation 'com.linkedin.dexmaker:dexmaker-mockito:2.28.1'
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
jacoco.includes = ["com.application.*"]
}
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
reports {
xml.enabled true
html.enabled true
}
def fileFilter = [
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*',
'android/**/*.*',
// Exclude Hilt generated classes
'**/*Hilt*.*',
'hilt_aggregated_deps/**',
'**/*_Factory.class',
'**/*_MembersInjector.class'
]
def debugTree = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)
def mainSrc = "$project.projectDir/src/main/java"
sourceDirectories.setFrom(files([mainSrc]))
classDirectories.setFrom(files([debugTree]))
executionData.setFrom(fileTree(dir: project.buildDir, includes: [
'outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec',
'outputs/code_coverage/debugAndroidTest/connected/*/coverage.ec'
]))
}
connectedCheck {
finalizedBy jacocoTestReport
}
// Allow references to generated code
kapt {
correctErrorTypes = true
}
build.gradle (project
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories{
google()
}
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
classpath("com.google.dagger:hilt-android-gradle-plugin:2.38.1")
}
}
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
error : "Could not resolve com.github.barteksc:android-pdf-viewer:3.2.0-beta.1."
I haven't found why I cannot load a library from github. Do I have to use something like jitpack?
I cannot use maven since the lib doesn't support it.
You can't just link to code in github like that. It needs to be packaged into a library and downloaded in compiled form. You have to use maven or similar repository. Gradle doesn't even know how to download source code from git for a dependency, it only expects packaged code.
I wouldn't use this library in any case. It hasn't been updated in 3 years, and the first line of its readme is that its looking for a new maintainer. And since it has no updates, it didn't find one. I would be vary wary of some random library on github, and doubly wary of one that's not maintained.

Jacoco shows 0% coverage even though 100% tests are passing

I have been working on an android project in kotlin where I have a few packages: app, package1, package2, package3 each package has its own build.gradle like build.gradle for app, package1, package2, package3 in the respective package.
There is also a top-level build.gradle. Now each package has a src and a tests folder. Now I have created a jacoco.gradle file in the package.root. and applied apply from: "$project.rootDir/jacoco.gradle" in each package's build.gradle.
Here is my jacoco.gradle file for reference.
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.8.6"
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
project.afterEvaluate {
(android.hasProperty('applicationVariants')
? android.'applicationVariants'
: android.'libraryVariants').all { variant ->
def variantName = variant.name
def unitTestTask = "test${variantName.capitalize()}UnitTest"
def uiTestCoverageTask = "create${variantName.capitalize()}CoverageReport"
tasks.create(name: "${unitTestTask}Coverage", type: JacocoReport, dependsOn: [
"$unitTestTask",
"$uiTestCoverageTask"
]) {
group = "Reporting"
description = "Generate Jacoco coverage reports for the ${variantName.capitalize()} build"
reports {
html.enabled = true
xml.enabled = false
csv.enabled = false
}
def fileFilter = [
// data binding
'android/databinding/**/*.class',
'**/android/databinding/*Binding.class',
'**/android/databinding/*',
'**/androidx/databinding/*',
'**/BR.*',
// android
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*',
'android/**/*.*',
// kotlin
'**/*MapperImpl*.*',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/BuildConfig.*',
'**/*Component*.*',
'**/*BR*.*',
'**/Manifest*.*',
'**/*$Lambda$*.*',
'**/*Companion*.*',
'**/*Module*.*',
'**/*Dagger*.*',
'**/*MembersInjector*.*',
'**/*_MembersInjector.class',
'**/*_Factory*.*',
'**/*_Provide*Factory*.*',
'**/*Extensions*.*',
// sealed and data classes
'**/*$Result.*',
'**/*$Result$*.*'
]
classDirectories.setFrom(files([
fileTree(dir: "${buildDir}/tmp/kotlin-classes/${variantName}", excludes: fileFilter)
]))
def variantSourceSets = variant.sourceSets.java.srcDirs.collect { it.path }.flatten()
sourceDirectories.setFrom(project.files(variantSourceSets))
def uiTestsData = fileTree(dir: "${buildDir}/outputs/code_coverage/${variantName}AndroidTest/connected/", includes: ["**/*.ec"])
executionData(files([
"$project.buildDir/jacoco/${unitTestTask}.exec",
uiTestsData
]))
}
}
}
Now the problem is when I run the testDebugUnitTestCoverage task even though all tests present in a package pass the results show 0% code coverage and all lines are missed. Can someone help me find a solution?
Update
The coverage is reported with app package and package2(without any change in any files) but jacoco still reports 0 coverage for package1 and package3
Edit
added gradle file for 1 of the failing package
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply from: "$project.rootDir/jacoco.gradle"
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
multiDexEnabled true
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
testOptions {
unitTests {
includeAndroidResources = true
all {
forkEvery = 1
maxParallelForks = Runtime.getRuntime().availableProcessors()
testLogging {
events "passed", "skipped", "failed"
showExceptions = true
exceptionFormat = "full"
showCauses = true
showStackTraces = true
showStandardStreams = false
}
}
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation(
'androidx.appcompat:appcompat:1.0.2',
'androidx.exifinterface:exifinterface:1.0.0-rc01',
'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-alpha03',
'androidx.work:work-runtime-ktx:2.4.0',
'com.google.dagger:dagger:2.24',
'com.google.firebase:firebase-analytics-ktx:17.5.0',
'com.google.firebase:firebase-crashlytics:17.0.0',
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
)
testImplementation(
'android.arch.core:core-testing:1.1.1',
'androidx.test.espresso:espresso-core:3.2.0',
'androidx.test.ext:junit:1.1.1',
'androidx.work:work-testing:2.4.0',
'com.google.dagger:dagger:2.24',
'com.google.truth:truth:0.43',
'junit:junit:4.12',
"org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version",
'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.2',
'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.2.2',
'org.mockito:mockito-core:2.19.0',
'org.robolectric:robolectric:4.3',
project(":package2"),
)
kapt(
'com.google.dagger:dagger-compiler:2.24',
)
kaptTest(
'com.google.dagger:dagger-compiler:2.24',
)
api project(':package1')
implementation project(':package4')
implementation project(':package3')
}
repositories {
mavenCentral()
}
configurations {
all*.exclude module: 'protobuf-java'
}
update
when I run coverage from run configurations in android studio I get the correct data but when I run it from gradle tasks it shows 0 coverage.

Class Dependency Is Duplicated "Program type already present"

Error
Program type already present: androidx.versionedparcelable.NonParcelField","sources":[{}],"tool":"D8"}
I Couldn't figure out which entry is duplicated anyone help me to resolve this ? does it cause of Androidx core library ? but i think there is no duplicate entry for androidx core
Project.gradle
buildscript {
ext.kotlinVersion = '1.3.10'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0'
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
ext {
minSdkVersion = 19
targetSdkVersion = 28
buildToolsVersion = '28.0.3'
versionName = '4.5.1'
versionCode_lite = 98
versionCode_plus = 96
}
App.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.getkeepsafe.dexcount'
apply plugin: 'jacoco'
apply plugin: 'com.github.ben-manes.versions'
android {
compileSdkVersion project.targetSdkVersion
buildToolsVersion project.buildToolsVersion
defaultConfig {
minSdkVersion project.minSdkVersion
targetSdkVersion project.targetSdkVersion
versionName project.versionName
vectorDrawables.useSupportLibrary = true
}
sourceSets {
lightningPlus.setRoot('src/LightningPlus')
lightningLite.setRoot('src/LightningLite')
}
buildTypes {
debug {
// TODO: debug cannot be used on SDK < 21
multiDexEnabled true
minifyEnabled false
shrinkResources false
proguardFiles 'proguard-project.txt'
testCoverageEnabled true
}
release {
multiDexEnabled true
minifyEnabled true
shrinkResources true
proguardFiles 'proguard-project.txt'
testCoverageEnabled false
}
}
testOptions {
unitTests.all {
jacoco {
// This option needs to be included for robolectric tests
includeNoLocationClasses = true
}
}
}
flavorDimensions "capabilities"
productFlavors {
lightningPlus {
dimension "capabilities"
buildConfigField "boolean", "FULL_VERSION", "Boolean.parseBoolean(\"true\")"
applicationId "acr.browser.lightning"
versionCode project.versionCode_plus
}
lightningLite {
dimension "capabilities"
buildConfigField "boolean", "FULL_VERSION", "Boolean.parseBoolean(\"false\")"
applicationId "acr.browser.barebones"
versionCode project.versionCode_lite
}
}
lintOptions {
abortOnError true
}
packagingOptions {
exclude '.readme'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
configurations.all {
resolutionStrategy.force 'com.android.support:support-v4:26.1.0' // the lib is old dependencies version;
}
}
jacoco {
toolVersion = '0.7.9' // See http://www.eclemma.org/jacoco/
}
dexcount {
includeClasses = false
includeFieldCount = false
format = "tree"
orderByMethodCount = true
verbose = false
}
dependencies {
// test dependencies
testImplementation 'junit:junit:4.12'
testImplementation 'org.assertj:assertj-core:3.11.1'
testImplementation 'org.mockito:mockito-core:2.23.0'
testImplementation 'com.nhaarman:mockito-kotlin:1.6.0', {
exclude group: 'org.jetbrains.kotlin'
}
testImplementation 'org.robolectric:robolectric:3.8'
implementation 'com.android.support:multidex:1.0.3'
// support libraries
implementation "androidx.palette:palette:1.0.0"
implementation "androidx.annotation:annotation:1.0.0"
implementation "androidx.vectordrawable:vectordrawable-animated:1.0.0"
implementation "androidx.appcompat:appcompat:1.0.0"
implementation "com.google.android.material:material:1.0.0"
implementation "androidx.recyclerview:recyclerview:1.0.0"
implementation "androidx.fragment:fragment:1.0.0"
implementation "androidx.drawerlayout:drawerlayout:1.0.0"
// html parsing for reading mode
implementation 'org.jsoup:jsoup:1.11.3'
// file reading
final def mezzanineVersion = '1.1.1'
implementation "com.anthonycr.mezzanine:mezzanine:$mezzanineVersion"
kapt "com.anthonycr.mezzanine:mezzanine-compiler:$mezzanineVersion"
// dependency injection
final def daggerVersion = '2.17'
implementation "com.google.dagger:dagger:$daggerVersion"
kapt "com.google.dagger:dagger-compiler:$daggerVersion"
compileOnly 'javax.annotation:jsr250-api:1.0'
// view binding
final def butterKnifeVersion = '9.0.0-rc1'
implementation "com.jakewharton:butterknife:$butterKnifeVersion"
kapt "com.jakewharton:butterknife-compiler:$butterKnifeVersion"
// permissions
implementation 'com.anthonycr.grant:permissions:1.1.2'
// proxy support
implementation 'net.i2p.android:client:0.8'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
// rx
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.2'
implementation 'io.reactivex.rxjava2:rxkotlin:2.3.0'
// tor proxy
final def netCipherVersion = '2.0.0-alpha1'
implementation "info.guardianproject.netcipher:netcipher:$netCipherVersion"
implementation "info.guardianproject.netcipher:netcipher-webkit:$netCipherVersion"
implementation 'com.anthonycr.progress:animated-progress:1.0'
// memory leak analysis
final def leakCanaryVersion = '1.6.1'
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion"
// kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
implementation 'androidx.core:core-ktx:1.0.0'
}
kapt {
arguments {
arg("mezzanine.projectPath", project.rootDir)
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
kotlinOptions {
jvmTarget = '1.6'
kotlinOptions {
freeCompilerArgs += ['-XXLanguage:+InlineClasses']
freeCompilerArgs += ['-progressive']
}
}
}
task jacocoTestReport(type: JacocoReport, dependsOn: ['testLightningPlusDebugUnitTest', 'createLightningPlusDebugCoverageReport']) {
reports {
xml.enabled = true
html.enabled = true
}
final def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
final def debugTree = fileTree(dir: "$buildDir/intermediates/classes/lightningPlus/debug", excludes: fileFilter)
final def kotlinDebugTree = fileTree(dir: "$buildDir/tmp/kotlin-classes/lightningPlusDebug", excludes: fileFilter)
final def mainSrc = "${project.projectDir}/src/test/java"
sourceDirectories = files([mainSrc])
classDirectories = files([debugTree], [kotlinDebugTree])
executionData = fileTree(dir: "$buildDir", includes: [
"jacoco/testLightningPlusDebugUnitTest.exec",
"outputs/code-coverage/connected/*coverage.ec"
])
}
Gradle.properties
kotlin.incremental=false
android.useAndroidX=true
android.enableJetifier=true
android.debug.obsoleteApi=true

jacoco code coverage not working for Android applications

My root build.gradle file
buildscript {
repositories {
google()
mavenCentral()
jcenter()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jacoco:org.jacoco.core:0.8.0"
}
}
apply plugin: 'android-sdk-manager'
allprojects {
apply plugin: 'jacoco'
apply plugin: 'com.github.ben-manes.versions'
repositories {
google()
mavenCentral()
jcenter()
flatDir {
dirs 'libs'
}
}
tasks.withType(JavaCompile) {
sourceCompatibility = JavaVersion.VERSION_1_10
targetCompatibility = JavaVersion.VERSION_1_10
// report all Java errors even if the IDE does not
configure(options) {
compilerArgs << '-Xlint:all' << '-Xlint:-options'
deprecation = true
encoding = 'UTF-8'
}
}
// print errors from test in the terminal
tasks.withType(Test) {
testLogging {
exceptionFormat 'full'
}
}
project.plugins.whenPluginAdded { plugin ->
if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) {
println "Disable pre dexing for module ${project.name}"
project.android.dexOptions.preDexLibraries = false
} else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
println "Disable pre dexing for module ${project.name}"
project.android.dexOptions.preDexLibraries = false
}
}
}
app/build.gradle file
apply plugin: 'com.android.application'
apply from: '../jacoco.gradle'
android {
compileSdkVersion COMPILE_SDK_VERSION as int
buildToolsVersion BUILD_TOOLS_VERSION
defaultConfig {
applicationId "..."
minSdkVersion MIN_SDK_VERSION as int
targetSdkVersion TARGET_SDK_VERSION as int
project.ext.set("archivesBaseName", "..." + versionName)
multiDexEnabled true
renderscriptTargetApi RENDERSCRIPT_TARGET_API as int
renderscriptSupportModeEnabled true
}
signingConfigs {
debugKey {
...
}
releaseKey {
...
}
}
buildTypes {
debug {
versionNameSuffix ''
debuggable true
minifyEnabled false
zipAlignEnabled true
signingConfig signingConfigs.debugKey
testCoverageEnabled true
}
staging {
versionNameSuffix ''
debuggable false
minifyEnabled true
zipAlignEnabled true
signingConfig signingConfigs.stagKey
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
matchingFallbacks = ['release']
}
release {
versionNameSuffix ''
debuggable false
minifyEnabled true
zipAlignEnabled true
signingConfig signingConfigs.releaseKey
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'LICENSE.txt'
}
testOptions {
animationsDisabled true
unitTests {
returnDefaultValues = true
includeAndroidResources = true
}
}
lintOptions {
lintConfig file('lint.xml')
abortOnError false
}
sourceSets {
main {
java.srcDirs = ['src/main/java']
}
}
dexOptions {
javaMaxHeapSize "3g"
jumboMode = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Espresso
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
// Junit
testImplementation "junit:junit:${JUNIT_VERSION}"
//Mockito
testImplementation "org.mockito:mockito-core:2.22.0"
...
}
and jacoco.gradle file
apply plugin: 'jacoco'
def buildDir = "$project.buildDir"
def taskName = "debug"
def testTaskName = "testDebugUnitTest"
jacoco {
toolVersion "0.7.7.201606060606"
}
task "${testTaskName}Coverage"(type: JacocoReport, dependsOn: ["${testTaskName}", "createDebugCoverageReport"]) {
group = "Reporting"
description = "Generate Jacoco coverage reports on the ${testTaskName} build."
reports {
xml.enabled = true
html.enabled = true
html.destination file("$buildDir/jacoco")
csv.enabled false
}
def coverageSourceDirs = ["src/main/java"]
def fileFilter = [
'**/R.class',
'**/R$*.class',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/BuildConfig.*',
'**/Manifest*.*',
'android/**',
'com/google/**',
'com/intellij/**',
'junit/**',
'net/**',
'okhttp/**',
'org/**',
'rx/**',
'**/*_MembersInjector.class',
'**/Dagger*Component.class', // covers component implementations
'**/Dagger*Component$Builder.class', // covers component builders
'**/*Module_*Factory.class'
]
def javaClasses = fileTree(
dir: "$buildDir/intermediates/app_classes/${taskName}",
excludes: fileFilter
)
classDirectories = files([javaClasses])
sourceDirectories = files([coverageSourceDirs])
additionalSourceDirs = files([coverageSourceDirs])
executionData = fileTree(dir: "$buildDir", includes: [
"jacoco/testDebugUnitTest.exec"
])
}
and I am running following command on mac
./gradlew clean testDebugUnitTestCoverage
When I run this command, it shows message
Task ':app:testDebugUnitTestCoverage' is not up-to-date because:
Output property 'reports.enabledDirectoryReportDestinations.html' file .../app/build/jacoco/index.html has been removed.
Output property 'reports.enabledDirectoryReportDestinations.html' file .../app/build/jacoco/jacoco-sessions.html has been removed.
Output property 'reports.enabledDirectoryReportDestinations.html' file .../app/build/jacoco/jacoco-resources has been removed.
[ant:jacocoReport] Loading execution data file .../app/build/jacoco/testDebugUnitTest.exec
[ant:jacocoReport] Writing bundle 'app' with 3040 classes
and no coverage gets calculated in folder
reports/coverage/debug
however folder
tests/testDebugUnitTest
shows passed unit tests data with success.
I found solution here.
Just change path of classes directory
def javaClasses = fileTree(
dir: "$buildDir/intermediates/javac/debug",
excludes: fileFilter
)
I wrote an article a while ago about jacoco.
https://github.com/uriel-frankel/android-code-coverage/
The jacoco version should change as well:
apply plugin: 'jacoco'
jacoco {
toolVersion = '0.7.5.201505241946'
}

Project refresh failed - Error:Cause: org/gradle/internal/TrueTimeProvider

Importing this project from github, I've run into this message:
Gradle 'GameOfLife-master' project refresh failed
Error:Cause: org/gradle/internal/TrueTimeProvider
I've tried solutions posted here, cleaned/rebuilt (at least attempted to) the project, invalidated caches and tried a different version of Gradle. None of that worked. Anyone else got any ideas?
Module: app - build.gradle
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath "com.neenbedankt.gradle.plugins:android-apt:1.8"
classpath 'com.jakewharton.hugo:hugo-plugin:1.1.0'
classpath "net.rdrei.android.buildtimetracker:gradle-plugin:0.5.+"
classpath 'io.fabric.tools:gradle:1.+'
classpath 'hu.supercluster:paperwork-plugin:1.2.7'
}
}
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply plugin: 'io.fabric'
apply plugin: 'hugo'
apply plugin: "build-time-tracker"
apply plugin: 'hu.supercluster.paperwork'
paperwork {
set = [
gitInfo: gitInfo(),
gitSha: gitSha(),
buildTime: buildTime("yyyy-MM-dd HH:mm:ss", "GMT+01:00")
]
}
def versionMajor = 1
def versionMinor = 2
def versionPatch = 0
android {
compileSdkVersion androidCompileSdkVersion
buildToolsVersion androidBuildToolsVersion
defaultConfig {
applicationId 'hu.supercluster.gameoflife'
minSdkVersion androidMinSdkVersion
targetSdkVersion androidTargetSdkVersion
versionCode versionMajor * 10000 + versionMinor * 100 + versionPatch
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
signingConfigs {
alpha {}
beta {}
release {}
}
buildTypes {
debug {
applicationIdSuffix ".debug"
versionNameSuffix "-debug"
resValue "string", "app_name_for_buildtype", "Game of Life (debug)"
minifyEnabled false
testCoverageEnabled = false
}
alpha {
applicationIdSuffix ".alpha"
versionNameSuffix "-alpha"
resValue "string", "app_name_for_buildtype", "Game of Life (alpha)"
minifyEnabled false
testCoverageEnabled = false
lintOptions {
disable 'MissingTranslation'
}
}
beta {
applicationIdSuffix ".beta"
versionNameSuffix "-beta"
resValue "string", "app_name_for_buildtype", "Game of Life (beta)"
minifyEnabled false
testCoverageEnabled = false
}
release {
resValue "string", "app_name_for_buildtype", "Game of Life"
minifyEnabled false
proguardFile 'proguard-project.txt'
}
}
sourceSets.main {
// src/gen is the target for generated content like json model
java.srcDirs += 'build/generated/source/db'
}
// avoid errors with message 'Duplicate files copied in APK ...'
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}
}
afterEvaluate {
def propsFile = rootProject.file('keystore.properties')
def configName = 'release'
if (propsFile.exists() && android.signingConfigs.hasProperty(configName)) {
def props = new Properties()
props.load(new FileInputStream(propsFile))
android.signingConfigs[configName].storeFile = rootProject.file(props['storeFile'])
android.signingConfigs[configName].storePassword = props['storePassword']
android.signingConfigs[configName].keyAlias = props['keyAlias']
android.signingConfigs[configName].keyPassword = props['keyPassword']
}
}
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:support-annotations:24.2.0'
compile 'com.android.support:support-v13:24.2.0'
compile 'com.android.support:support-v4:24.2.0'
// ---------
compile 'com.github.tslamic.adn:library:1.0'
compile('com.crashlytics.sdk.android:crashlytics:2.5.5#aar') { transitive = true }
compile 'com.jakewharton.timber:timber:2.5.1'
compile 'com.squareup:otto:1.3.6'
compile 'hu.supercluster:paperwork:1.2.7'
// ---------
apt "org.androidannotations:androidannotations:" + androidAnnotationsVersion
compile("org.androidannotations:androidannotations-api:" + androidAnnotationsAPIVersion )
testCompile 'junit:junit:4.11'
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile('com.squareup:fest-android:1.0.+') { exclude module: 'support-v4' }
testCompile "org.robolectric:robolectric:3.0"
androidTestCompile 'com.google.guava:guava:14.0.1',
'com.squareup.dagger:dagger:1.1.0',
'org.hamcrest:hamcrest-integration:1.1',
'org.hamcrest:hamcrest-core:1.1',
'org.hamcrest:hamcrest-library:1.1',
'com.jakewharton.espresso:espresso:1.1-r3'
}
apt {
arguments {
resourcePackageName android.defaultConfig.applicationId
androidManifestFile variant.outputs[0]?.processResources?.manifestFile
}
}
apply plugin: 'idea'
idea {
module {
//and some extra test source dirs
testSourceDirs += file('src/test')
}
}
apply from: 'build-time-tracker.gradle'
You could run with --stacktrace to get a full exception stack trace
Gradle has the concept of public API and private API. Basically anything in org.gradle.internal is a part of the private API and the gradle team can change / remove these classes between gradle versions. Ideally plugins should never reference internal classes. Any plugin author referencing internal API's must understand that this code may break with a new release of Gradle.
It looks like one of your plugins is referencing the internal API (org.gradle.internal.TrueTimeProvider) and the plugin was built against one version of Gradle and you are running with a different version of gradle.
To fix, you'll need to determine which plugin is throwing the exception (--stacktrace will help here). Then you'll either need to change the plugin version to one compatible with your version of gradle, or change the gradle version you are running with.

Categories

Resources