Problems with gradle.bundle libraries (Android Studio)

4

Good morning, I have a problem that always happens to me. It is with the issue of adding libraries to the project, it usually happens when I place several google libraries, when I run the compatibility error comes out in the libraries, I think it is because there are libraries that use the same module and therefore the error . These are the libraries that I use in the project:

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.github.PhilJay:MPAndroidChart:v2.2.4'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile files('libs/poi-315.jar')
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
compile 'com.google.android.gms:play-services-plus:9.0.2'
compile 'com.mikhaellopez:circularimageview:3.0.2'
compile 'jp.wasabeef:blurry:2.0.2'
compile 'com.squareup.picasso:picasso:2.5.2'
compile group: 'com.google.android', name: 'support-v4', version: 'r7'

The compilation error comes to me when I add this library to add Google Maps Api v2 to my project:

compile group: 'com.google.android', name: 'support-v4', version: 'r7'

Someone to tell me why this happens? Any good practice so that it does not happen again? What things I have to take into account when adding libraries.

This is the error that comes out:

  

Error: Error converting bytecode to dex:   Cause: com.android.dex.DexException: Multiple dex files define Landroid / support / v4 / accessibilityservice / AccessibilityServiceInfoCompat $ AccessibilityServiceInfoVersionImpl;   : app: transformClassesWithDexForDebug FAILED   Error: Execution failed for task ': app: transformClassesWithDexForDebug'.   com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process. internal.ExecException: Process 'command' C: \ Program Files \ Java \ jdk1.8.0_91 \ bin \ java.exe '' finished with non-zero exit value 2

Thank you very much!

    
asked by Lean Vitale 16.06.2016 в 17:02
source

2 answers

2

I notice 2 problems that can have several causes:

  

Error converting bytecode to dex: Cause: com.android.dex.DexException:   Multiple dex files

and

  

Process 'command' C: \ Program Files \ Java \ jdk1.8.0_91 \ bin \ java.exe ''   finished with non-zero exit value 2

could be solved by adding in your build.gradle :

dexOptions {
    ...
    preDexLibraries = false
    ...
}

and enable the support MultiDex since I see you have several libraries and the problem can be caused for the large number of methods in your project:

defaultConfig {
        ...
        multiDexEnabled true
        ...
    }

At the end I recommend you make a Clean > Rebuild all and synchronize the build.gradle with your project.

    
answered by 16.06.2016 в 19:12
0

How it indicates this answer seems to be easy to resolve. In build.gradle in android block add:

dexOptions {
    preDexLibraries = false
}
    
answered by 16.06.2016 в 17:16