-1

This is the my build.gradle and when I build the apk by clicking on the build apk this error shown.I have seen the some of the queries before but not able to figure out the problem solution

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.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "com.example.ranjeet.location"
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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:appcompat-v7:25.3.1'
    testCompile 'junit:junit:4.12'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'com.google.android.gms:play-services:10.2.6'
    compile 'com.google.android.gms:play-services-maps:10.2.6'
}
  • 1
    Whats the error? Paste error log and also tell the android studio version you are using. – Omkar Nath Singh Jun 09 '17 at 06:08
  • i have edited and paste it above – Ranjeet Yadav Jun 09 '17 at 06:16
  • Possible duplicate of [DexIndexOverflowException issue after updating to latest appcompat and support library](https://stackoverflow.com/questions/26515378/dexindexoverflowexception-issue-after-updating-to-latest-appcompat-and-support-l) – Selvin Jun 10 '17 at 11:37

4 Answers4

2

You have too many methods. There can only be 65536 methods for dex.

So, enable multidex as following:

 android {    
    defaultConfig {
        // Enabling multidex support.
        multiDexEnabled true
    }  
}



dependencies {
 compile 'com.android.support:multidex:1.0.0'
 }
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
0

You have too many methods. There can only be 65536 methods for dex.

So, enable multidex as following:

android {

    defaultConfig {
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

And paste this code as well,

dexOptions {
    javaMaxHeapSize "4g"
    preDexLibraries = false
}
0
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

The underlying problem is imposed by the current set of Dalvik instructions. Specifically, any of the invoke-* methods. These expect a 16-bit argument, representing the target method's reference index. Being limited to 16-bits, valid values are between 0 and 65536. This means, that if you end up calling more than 65,536 defined methods, you are going to exceed this limit.

Solutions: MultiDex allows you to use multiple DEX files contained within one APK. With a few steps, your classes will split automatically into several DEX files (classes.dex, classes2.dex, classes3.dex, etc) in case you reach the method index limit.

Get more infomation : https://www.contentful.com/blog/2014/10/30/android-and-the-dex-64k-methods-limit/

Mick
  • 61
  • 3
0

If your minSdkVersion is set to 21 or higher, all you need to do is set multiDexEnabled to true in your app-level build.gradle file, as shown here:

android {
    defaultConfig {
        ...
        minSdkVersion 21 
        targetSdkVersion 25
        multiDexEnabled true
    }
    ...
}

However, if your minSdkVersion is set to 20 or lower, then you must use the multidex support library as follows:

Modify the app-level build.gradle file to enable multidex and add the multidex library as a dependency, as shown here:

android {
    defaultConfig {
        ...
        minSdkVersion 15 
        targetSdkVersion 25
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.1'
}

Create an Application class like this:

public class MyApplication extends MultiDexApplication {
  @Override
  protected void attachBaseContext(Context base) {
     super.attachBaseContext(base);
     MultiDex.install(this);
  }
}

Add this application class in Manifest.

You can also check this link:

https://developer.android.com/studio/build/multidex.html

Avijit Karmakar
  • 8,890
  • 6
  • 44
  • 59