1

I recently had a lot of problems trying to debug in my application when using Retrolambda, because of that I wanted to include Jack on my Gradle for debugging purposes.

jackOptions {
   enabled true
}

Because of that, I have been going through this error and I still without finding a way to solve it.

Jackson : NoSuchMethodError for com.google.common.base.Preconditions.checkState

I have check different posts looking for a solution:

Android Studio: Gradle - build fails -- Execution failed for task ':dexDebug'

Lambda expressions crash with IncompatibleClassChangeError in Android when using jack

A larger heap for the Gradle daemon is recommended for running jack

But none of the solutions have fixed my problems. Right now my Gradle looks like:

buildscript {
    ext {
        use_jack = true
        dagger_version = "2.8"
        firebase_version = "9.6.1"
        rx_version = "2.0.3"
        rx_firebase_version = "1.0.0"
        rx_android_version = "2.0.1"
        gson_version = "2.8.0"
        butterkinfe_version = "8.4.0"
        support_version = "25.0.0"
        target_sdk_version = 24
    }
}


apply plugin: 'com.android.application'
if (!use_jack) { //Backport to apt / RetroLambda
    apply plugin: 'me.tatarka.retrolambda'
    apply plugin: 'com.neenbedankt.android-apt'
}
android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.myaplicattion"
        minSdkVersion 15
        targetSdkVersion project.properties.target_sdk_version
        versionCode 1
        versionName "0.1"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        jackOptions {
            enabled use_jack
        }
    }
    buildTypes {
        debug {
            minifyEnabled false
            testCoverageEnabled = true
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')

    //Support
    compile "com.android.support:appcompat-v7:$support_version"
    compile "com.android.support:design:$support_version"

    //Util
    compile 'com.intellij:annotations:12.0'
    compile 'com.jakewharton.timber:timber:4.3.1'
    compile "com.jakewharton:butterknife:$butterkinfe_version"
    if (use_jack) annotationProcessor "com.jakewharton:butterknife-compiler:$butterkinfe_version"
    else apt "com.jakewharton:butterknife-compiler:$butterkinfe_version"
    compile 'com.github.mukeshsolanki:country-picker-android:1.1.6'
    compile 'com.theartofdev.edmodo:android-image-cropper:2.3.+'
    //Glide
    compile 'com.github.bumptech.glide:glide:3.7.0'

    //Firebase
//    compile "com.firebaseui:firebase-ui-database:0.4.0"
    compile "com.google.firebase:firebase-storage:$firebase_version"
    compile "com.google.firebase:firebase-messaging:$firebase_version"
    compile "com.google.firebase:firebase-common:$firebase_version"
    compile "com.google.firebase:firebase-auth:$firebase_version"
    compile "com.google.firebase:firebase-core:$firebase_version"
    compile "com.google.firebase:firebase-database:$firebase_version"
    compile "com.google.firebase:firebase-crash:$firebase_version"
    compile "com.github.frangsierra:rx2firebase:$rx_firebase_version"

    //GSON
    compile "com.google.code.gson:gson:$gson_version"
    //Facebook
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'

    //Dagger
    compile "com.google.dagger:dagger:$dagger_version"
    if (use_jack) annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"
    else apt "com.google.dagger:dagger-compiler:$dagger_version"

    //Rx
    compile "io.reactivex.rxjava2:rxjava:$rx_version"
    compile "io.reactivex.rxjava2:rxandroid:$rx_android_version"

    //Test
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'
    compile 'com.android.support.test:runner:0.5'
}

apply plugin: 'com.google.gms.google-services'

And my appgradle :

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'me.tatarka:gradle-retrolambda:3.2.5'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven { url "https://jitpack.io" }
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Francisco Durdin Garcia
  • 12,540
  • 9
  • 53
  • 95
  • 3
    AFAIK if you enable jack you can use java 8 and you don't need retrolambda anymore. Haven't tried it yet though. – Benito Bertoli Mar 09 '17 at 15:41
  • I tried already, but it doesn't work well if your minimum sdk is not API 25 – Francisco Durdin Garcia Mar 09 '17 at 15:48
  • What do you mean by "doesn't work well"? In theory, retrolambda should be of no use and API 25 is no requirement when you work with Jack. Btw., as for debugging I've heard reports that it's even more problematic with Jack than with retrolamda (however, don't know if that's true since I don't use Jack). – Sartorius Mar 09 '17 at 16:05
  • Maybe I expressed bad myself in the last comment. Using retrolambda when your minimum SDK is not 25 makes debug really anwful cause you can debug pretty well using interruption points cause a lot of variables are never retrieved by the debugger or the expression evaluator. In the other hand, as you can see in my gradle, retrolambda is disabled when I enable Jack. But although it is disabled I got this errors, but if I just delete retrolambda from the gradle it works fine. – Francisco Durdin Garcia Mar 09 '17 at 16:15
  • 3
    Do you have the exact signature of the missing `checkState` method? It looks like you have multiple versions of `com.google.common.base.Preconditions` on your classpath. A lot of `checkState` overloads have been added in [Guava 20.0](https://github.com/google/guava/commit/892e323fca32945cdfb25395ca6e346dd0fffa5b). Not sure, if this helps though. – Sartorius Mar 09 '17 at 16:45

0 Answers0