Error: Execution failed for task ': app: transformClassesWithDexForRelease' from Lcom / google / android / gms / internal / zzbw; Would anyone know this error?

0

In my Android Studio is giving the following error when trying to make an apk to store:

  

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.dex.DexException:   Multiple dex files define Lcom / google / android / gms / internal / zzbw;

Someone could help me with this error.

Here are the dependencies of my project in build.gradle

dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', 

        {
                exclude group: 'com.android.support', module: 'support-annotations'
            })

            compile 'com.android.support:support-v4:24.2.1'
            compile 'com.android.support:appcompat-v7:24.2.1'
            compile 'com.android.support:recyclerview-v7:24.2.1'

            compile 'com.nispok:snackbar:2.10.10'
            compile 'com.android.support:design:24.2.1'
            compile 'com.android.support:support-vector-drawable:24.2.1'

            compile 'com.google.android.gms:play-services-appindexing:9.6.1'
            compile 'com.google.android.gms:play-services-auth:9.6.1' 
            compile 'com.google.android.gms:play-services-fitness:9.6.1'
            compile 'com.google.android.gms:play-services-wearable:9.6.1' 

            compile 'com.google.firebase:firebase-core:9.6.1' 
            compile 'com.google.firebase:firebase-messaging:9.6.1' 
            compile 'com.google.firebase:firebase-auth:9.6.1'  
            compile 'com.google.firebase:firebase-database:9.6.1' 

            testCompile 'junit:junit:4.12'


        }
    
asked by anonymous 11.10.2016 / 13:56

1 answer

6

As far as we can tell, you are using many external libraries. Considering this, we have perhaps, I say perhaps, that it is exceeding the total limit of methods to be referenced in your project.

Explanation: Building Apps with Over 65K Methods

  

Android Application Files (APK) contain bytecode files   executable files in the Dalvik Executable (DEX) format, which contain   compiled, used to run your application. The Dalvik specification   Executables limit the total number of methods that can be   referenced within a single DEX file at 65,536, including the   Android framework methods, library methods, and methods in   your own code. To exceed this limit you will have to   configure the build process for your application to generate more   of a DEX file, a setting known as multidex.

Solution:

  • You should try to format the dependencies (libraries), wipe as much as possible of your code to remove excess classes to try not to exceed the limit. Then sync Gradle into Android Studio and check to see if the error will occur again. If it does not resolve, go to the second option.

  • Add in build.gradle (app module).

  • android {
       ...
       defaultConfig {
          ...
          multiDexEnabled true
       }
    }
    

    Several great developers have written about this topic, and some examples are here:

    11.10.2016 / 14:41