0

My app was compiling properly, before i added an google maps activity. Then i get this error

FAILURE: Build failed with an exception.

* What went wrong:
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 '/usr/lib/jvm/java-8-openjdk-amd64/bin/java'' finished with non-zero exit value 2

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.






Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
: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 '/usr/lib/jvm/java-8-openjdk-amd64/bin/java'' finished with non-zero exit value 2

build.gradle

android {
    compileSdkVersion 24
    buildToolsVersion "23.0.3"
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "zupportdesk.desk.zupport.chatsystem"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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

    compile 'com.android.support:appcompat-v7:24.2.0'
    compile 'com.android.support:recyclerview-v7:24.2.0'
    compile 'com.android.support:design:24.2.0'
    compile 'com.android.support:cardview-v7:24.2.0'
    compile 'org.java-websocket:Java-WebSocket:1.3.0'
    compile 'com.google.android.gms:play-services:9.4.0'
    compile 'br.com.liveo:navigationdrawer-material:2.5.1'



    compile files('libs/gson-2.2.2.jar')
    compile files('libs/signalr-client-sdk-android.jar')
    compile files('libs/signalr-client-sdk.jar')

}

Can someone help me to fix this issue. tnx

Sathya Baman
  • 3,424
  • 7
  • 44
  • 77

5 Answers5

2

After adding the google maps, the method and references count exceed 64K:

Error:The number of method references in a .dex file cannot exceed 64K.

This is a big problem that every big project encounter such a problem. But the Google gave a solution : Configure Apps with Over 64K Methods.

Hope this can help you.

L. Swifter
  • 3,179
  • 28
  • 52
1

According to your question

Instead of

compile 'com.google.android.gms:play-services:9.4.0'

Use this

com.google.android.gms:play-services-maps:9.4.0

This will only include play service required for maps only.Your code will import all packages of play services which will cause your app to cross 64K method limits

Vivek Mishra
  • 5,669
  • 9
  • 46
  • 84
0

Add this to your build.gradle after the buildTypes{ ... }:

 dexOptions {
    javaMaxHeapSize "4g"
}
Aman Grover
  • 1,621
  • 1
  • 21
  • 41
0

Add this dependency in gradle... your app has reached the 64k reference limit. More of it here

compile 'com.android.support:multidex:1.0.0'

also add this

android {

    defaultConfig {

        // Enabling multidex support.
        multiDexEnabled true
}
}
Darshan Miskin
  • 844
  • 14
  • 25
0

According to Google's suggestion: Selectively compiling APIs into your executable, you can try to replace the following line in your build.gradle file:

compile 'com.google.android.gms:play-services:9.6.1'

with what you need:

compile 'com.google.android.gms:play-services-maps:9.6.1' compile 'com.google.android.gms:play-services-xxx2:9.6.1' compile 'com.google.android.gms:play-services-xxx3:9.6.1'

J.W
  • 671
  • 7
  • 23