4

I am running android studio template code for Maps Application. But getting error. I am following this link to run just a simple maps application.

https://developers.google.com/maps/documentation/android-api/utility/setup

Following is the error.

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

My question is why I am getting this error, Since I am following all the steps provided by the official Google link above.

Here is my Gradle Code for app.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"
    defaultConfig {
        applicationId "app.com.example.android.mapsnew"
        minSdkVersion 16
        targetSdkVersion 24
        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:24.0.0'
    compile 'com.google.android.gms:play-services:9.4.0'
    compile 'com.google.android.gms:play-services-maps:9.4.0'
    testCompile 'junit:junit:4.12'
}

Here is the image of this error.

enter image description here

Kind Regards, Abr.

Abr
  • 41
  • 1
  • 1
  • 3
  • 1
    Possible duplicate of [Unable to execute dex: method ID not in \[0, 0xffff\]: 65536](http://stackoverflow.com/questions/15209831/unable-to-execute-dex-method-id-not-in-0-0xffff-65536) – K Neeraj Lal Aug 19 '16 at 13:46
  • Thanks @KNeerajLal Actually I am following this official link. >> developers.google.com/maps/documentation/android-api/utility‌​/… So why this is giving error in my case. It should work as described in the link. The answer you are referring, is telling to do a lot of procedure related to MultiDexing. Hope you understand my point. – Abr Aug 19 '16 at 16:44
  • One or more of your dependencies in your `build.gradle` is causing the number of methods in your apk to go beyond the 65k method limit. You available options are, Remove the dependencies which cause this or Multidex. – K Neeraj Lal Aug 20 '16 at 04:33
  • In your case I think removing `compile 'com.google.android.gms:play-services:9.4.0'` will work. – K Neeraj Lal Aug 20 '16 at 04:34
  • I have already tried that, removing 'compile 'com.google.android.gms:play-services:9.4.0'' . It didn't worked and lead to more errors. I am trying to say that I haven't add anything in the code except the ApiKey from google. This should work as it is, Since I am following the tutorial: [link](https://developers.google.com/maps/documentation/android-api/utility/setup) – Abr Aug 20 '16 at 08:02
  • I have the same problem, at least you are not alone. – Sulung Nugroho Nov 25 '16 at 00:16

2 Answers2

2

add multiDexEnabled true in your build.gradle(Module:app) file

defaultConfig {
    multiDexEnabled true
}
Amit Singh
  • 609
  • 7
  • 7
0

The number of method references in your app exceeds the 65K limit, your app may fail to compile. You may be able to mitigate this problem when compiling your app by specifying only the specific Google Play services APIs your app uses, instead of all of them

That's sort of the problem in your application. You might not need all of google play services. So don't totally remove the line

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

in gradle-app file as you have mentioned in the comments instead of that line just add

compile 'com.google.android.gms:play-services-maps:10.0.1'

There's another work around to the problem wherein your make your app support even all of google play services for that you can follow the this link.

Hope this helps

Nobody
  • 397
  • 1
  • 5
  • 25