1

I'm getting the below error while attempting to build APK. I have read several posts on how to resolve the problem, but as I have not been developing for that long, i'm unsure what I am doing. So, hope someone can help.

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

This is my build.gradle (Module)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.dawnlp.mymap"
        minSdkVersion 22
        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(dir: 'libs', include: ['*.jar'])
    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.1.0'
    compile 'com.google.android.gms:play-services:10.0.1'
    testCompile 'junit:junit:4.12'
}

and this is my build.gradle project

/ Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

Would appreciate it if someone could help out, also bare in mind I'm a little inexperienced.

Mark James
  • 481
  • 2
  • 6
  • 18
  • you have to enable multidex as your methods are more than 65536 or you can simple replace play-services library with what ever is needed like ad etc – Manohar Feb 28 '17 at 08:43
  • Enable [multidex](http://stackoverflow.com/questions/15209831/unable-to-execute-dex-method-id-not-in-0-0xffff-65536) – azizbekian Feb 28 '17 at 08:46

3 Answers3

1

Use it :

android{
    defaultConfig {

            multiDexEnabled true
        }
}

And use it too

   dependencies {
    compile 'com.android.support:multidex:1.0.1'
}
Vinesh Chauhan
  • 1,288
  • 11
  • 27
aslamhossin
  • 1,217
  • 12
  • 22
  • Thanks. Do you mean place defaultConfig { multiDexEnabled true } into dependencies { compile 'com.android.support:multidex:1.0.1' } – Mark James Feb 28 '17 at 08:51
  • Like this dependencies { defaultConfig { multiDexEnabled true } compile fileTree(dir: 'libs', include: ['*.jar']) 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.1.0' compile 'com.google.android.gms:play-services:10.0.1' testCompile 'junit:junit:4.12' } – Mark James Feb 28 '17 at 08:52
1

You need to enable multidex, add this line to your defaultConfig :

multiDexEnabled true

And this line to your dependencies :

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

Also, as you are running unit tests, you need to create a class that extends the application and install MultiDex :

public class YouApplication extends Application {
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}
Nika Kurdadze
  • 2,502
  • 4
  • 18
  • 28
0

use this block in your module level gradle : dexOptions { javaMaxHeapSize "4g" }

And in manifest change the application name to .multidex. hope your code will work fine now

Ghanshyam Sharma
  • 451
  • 9
  • 21