DexArchiveBuilderException with Guava 21.0

0

I just received an exception when I was updating versions of frameworks and running an application that had been standing still for a long time. My dependencies are these:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:27.1.0'
    annotationProcessor 'com.jakewharton:butterknife:7.0.1'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.google.code.gson:gson:2.8.2'
    compile 'com.google.guava:guava:23.3-android'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.squareup.okhttp:okhttp:'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.7.5'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.google.code.gson:gson:2.8.2'
    compile 'com.squareup.dagger:dagger:1.2.5'
    compile 'com.android.support:design:27.1.0'
    compile 'com.google.zxing:core:3.2.0'
    compile 'com.google.zxing:android-core:3.2.0'
    compile 'com.google.zxing:android-integration:3.2.0'
    compile 'commons-codec:commons-codec:1.5'
    annotationProcessor 'com.squareup.dagger:dagger-compiler:1.2.5'
    provided 'com.squareup.dagger:dagger-compiler:1.2.5'
    androidTestCompile 'org.mockito:mockito-core:'
    androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
    androidTestCompile 'com.android.support:support-annotations:27.1.0'
    androidTestCompile 'com.android.support.test:runner:1.0.1'
    androidTestCompile 'com.android.support.test:rules:1.0.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
    androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2'){
        exclude module: 'support-annotations'
        exclude module: 'support-v4'
        exclude module: 'support-v13'
        exclude module: 'recyclerview-v7'
    }
    androidTestCompile 'com.android.support.test.espresso:espresso-intents:3.0.1'
}

And the exception I received was this:

    Error:com.android.builder.dexing.DexArchiveBuilderException: Failed to process /home/tassio/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/21.0/3a3d111be1be1b745edfa7d91678a12d7ed38709/guava-21.0.jar
    Error:com.android.builder.dexing.DexArchiveBuilderException: Error while dexing com/google/common/collect/ImmutableSortedAsList.class
    Error:com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
    Error:Execution failed for task ':app:transformClassesWithDexBuilderForQuiosqueDebug'.
    > com.android.build.api.transform.TransformException: com.android.builder.dexing.DexArchiveBuilderException: com.android.builder.dexing.DexArchiveBuilderException: Failed to process /home/tassio/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/21.0/3a3d111be1be1b745edfa7d91678a12d7ed38709/guava-21.0.jar

Why does guava in version 21 on Android throw the exception when compiled into the Dalvik (DEX) format?

    
asked by anonymous 04.04.2018 / 17:26

1 answer

0

Guava version 21 can only be used in Java 8 environment, and the application is probably in version 7.

The solution is to upgrade the library to a unique and compatible version of android. Follow below:

dependencies {
  compile 'com.google.guava:guava:23.3-android'
}
    
04.04.2018 / 17:26