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.
Related
I am trying to implement Unsplash API according to this website:
https://unsplash.com/documentation#creating-a-developer-account
But got stuck pretty quickly. I don't know why Gradle refuses to compile so here are some files:
build.gradle (Project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
maven { url 'https://jitpack.io' }
}
dependencies {
def nav_version = "2.5.2"
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
}
}
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (App)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'androidx.navigation.safeargs.kotlin'
id "kotlin-parcelize"
}
android {
compileSdk 33
defaultConfig {
applicationId "com.example.gallery"
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
namespace 'com.example.gallery'
}
dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation "androidx.recyclerview:recyclerview:1.2.1"
// Unsplash
implementation 'com.github.unsplash:unsplash-photopicker-android:1.0.1'
// Kotlin
implementation("androidx.navigation:navigation-fragment-ktx:2.5.3")
implementation("androidx.navigation:navigation-ui-ktx:2.5.3")
// tests
testImplementation "com.google.truth:truth:1.1.3"
testImplementation "android.arch.core:core-testing:1.1.1"
testImplementation 'org.robolectric:robolectric:4.8'
}
All I try to do is to add those lines (from the GitHub specification):
To integrate UnsplashPhotoPicker into your Android Studio project
using Gradle, specify in your project build.gradle file:
allprojects { repositories {
...
maven { url 'https://jitpack.io' } } } And in your app module build.gradle file, replacing x.y.x by the latest tag:
dependencies { implementation
'com.github.unsplash:unsplash-photopicker-android:x.y.z' }
The problem occured(8 similar problem):
Execution failed for task ':gallery:desugarDebugFileDependencies'.
Could not resolve all files for configuration ':gallery:debugRuntimeClasspath'.
Could not find com.github.unsplash:unsplash-photopicker-android:1.0.1.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/github/unsplash/unsplash-photopicker-android/1.0.1/unsplash-photopicker-android-1.0.1.pom
- https://repo.maven.apache.org/maven2/com/github/unsplash/unsplash-photopicker-android/1.0.1/unsplash-photopicker-android-1.0.1.pom
Required by:
project :gallery
This question was asked Here but got no answer...
Add the
maven { url 'https://jitpack.io' }
in setting.gradle(project level)
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
//...
maven { url 'https://jitpack.io' }
}
}
I have Two lines of error when i run the simple Jetpack Compose Material 3 Project
build.gradle(Project:)
buildscript {
ext {
compose_version = '1.3.0-beta02'
core_ktx_version = '1.9.0-rc01'
material3_version = 'material3:1.3.0-beta02'
lifecycle_version = '2.4.1'
activity_compose_version = '1.5.1'
nav_version = "2.5.2"
hilt_version = "2.42"
hilt_nav_fragment = "1.0.0"
lottieVersion = "5.2.0"
timber_version = "5.0.1"
hilt_navigation_compose = "1.0.0"
room_version = "2.3.0-beta02"
kotlin_version = "1.6.21"
}
dependencies {
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
classpath "com.android.tools.build:gradle:4.2.1"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (Module : )
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
android {
compileSdk 33
defaultConfig {
applicationId "com.jetpackcompose.jp1"
minSdk 24
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation "androidx.core:core-ktx:$core_ktx_version"
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material3:$material3_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
implementation "androidx.activity:activity-compose:$activity_compose_version"
implementation "androidx.compose.compiler:compiler:1.3.1"
implementation 'androidx.appcompat:appcompat:1.6.0-beta01'
// hilt -android
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
// To Integrate Navigation
implementation "androidx.navigation:navigation-compose:$nav_version"
// To use additional extensions of navigation frameworks like hiltViewModel()
implementation "androidx.hilt:hilt-navigation-fragment:$hilt_nav_fragment"
implementation "androidx.hilt:hilt-navigation-compose:$hilt_navigation_compose"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}
settings.gradle:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
maven {
url "https://maven.google.com"
}
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven {
url "https://maven.google.com"
}
}
}
rootProject.name = "jp1"
include ':app'
when i run the project i have an error of :
Execution failed for task ':app:desugarDebugFileDependencies'.
Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
Could not find androidx.compose.material3:material3:1.3.0-beta02.
Compose compiler and the other compose dependencies have different releases.
The version androidx.compose.compiler:compiler:1.3.0-beta02 doesn't exist.
You can check it in the google maven repo
You can in any case use the stable version of the module compiler 1.3.1 and all the other compose dependencies at 1.2.1 or 1.3.0-beta02:
buildscript {
ext {
compose_compiler = '1.3.1' //compiler
compose_version = '1.3.0-beta02' //compose dependencies
compose_material3 = '1.0.0-beta02' //material3 release
}
//...
}
and then:
composeOptions {
kotlinCompilerExtensionVersion compose_compiler
}
dependencies {
// beta 1.3.0 releases
implementation "androidx.compose.material:material:$compose_version"
//...
//material3
implementation "androidx.compose.material3:material3:$compose_material3"
}
As described in the documentation the compiler 1.3.x requires kotlin 1.7.10:
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.
I have created a maven repository and uploaded it to Github. When I add it as a dependency to a sample project, the gradle sync completes successfully. But when I try to run the app, it crashes with a java.lang.NoClassDefFoundError.
Link to repository: https://github.com/rjain90/sdk
Sample project code:
Project build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext{
kotlin_version = '1.3.20'
realm_version = '5.8.0'
}
repositories {
google()
jcenter()
maven { url "https://raw.githubusercontent.com/rjain90/sdk/master/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.realm:realm-gradle-plugin:$realm_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://raw.githubusercontent.com/rjain90/sdk/master/" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ext{
lifecycle_version = '2.0.0'
android_support_version = '1.1.0-alpha01'
legacy_support_version = '1.0.0'
constraint_version = '1.1.3'
retrofit_version = '2.4.0'
dagger_version = '2.16'
rxjava_version = '2.1.7'
rxandroid_version = '2.0.1'
}
Module build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
// Load keystore
def keystorePropertiesFile = rootProject.file("keystore.properties");
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android {
signingConfigs {
release {
keyAlias keystoreProperties['ANDROID_KEY_ALIAS']
keyPassword keystoreProperties['ANDROID_KEY_PASSWORD']
storeFile file(keystoreProperties['ANDROID_KEYSTORE_LOCATION'])
storePassword keystoreProperties['ANDROID_STORE_PASSWORD']
}
}
compileSdkVersion 28
defaultConfig {
applicationId "com.bowstring.godworld"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
debuggable true
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
signingConfig signingConfigs.release
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation "androidx.appcompat:appcompat:$android_support_version"
implementation "androidx.constraintlayout:constraintlayout:$constraint_version"
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
implementation "io.reactivex.rxjava2:rxandroid:$rxandroid_version"
implementation "androidx.legacy:legacy-support-v4:$legacy_support_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.cabfare.android:sdk:0.0.18#aar'
}
For GitHub hosted, you can use https://jitpack.io as a Maven repository.
Add maven { url 'https://jitpack.io' } into the project build.gradle's allprojects -> repositories block, then in your module build.gradle, add a dependency implementation 'com.github.rjain90:sdk:0.0.17', for example.
However, your two releases are both containing build errors. Solve them first.
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