Android Build failed at ':app:dexDebug' with exception ( library and app project )

160 views Asked by At

I am using some third party libraries in my library project. The following is my library project build.gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    //dexOptions {
    //    javaMaxHeapSize "4g"
    //}
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.adobe.creativesdk:image:4.0.0'
    compile 'com.google.android.gms:play-services:7.5.0'
}
repositories {
    jcenter()

    mavenCentral()

    maven {
        //url "${project.rootDir}/mobilexpresslib/creativesdk-repo"
        url "${project.projectDir}/creativesdk-repo"
        //java.lang.System.println(${project(':mobilexpresslib').projectDir});
        // println "[$project.rootDir]"
        println "[$project.projectDir]"

        //  url "${project(':mobilexpresslib').projectDir}/creativesdk-repo"
        //ADD THE CORRECT LOCATION OF THE CREATIVESDK LIBRARY FILES
    }
}

The following is my app build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.dgflick.mxpro.mobilexpresspro"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {

        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':mobilexpressprolib')
}
repositories {
    jcenter()

    mavenCentral()

    maven {
        //url "${project.rootDir}/creativesdk-repo"
        //ADD THE CORRECT LOCATION OF THE CREATIVESDK LIBRARY FILES
        url "${project(":mobilexpressprolib").projectDir}/creativesdk-repo"
    }
}

After today's update of Android Studio with Android SDK, I am getting the following error.

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
 at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
 at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)
 at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
 at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
 at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
 at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
 at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
 at com.android.dx.command.dexer.Main.run(Main.java:246)
 at com.android.dx.command.dexer.Main.main(Main.java:215)
 at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_71\bin\java.exe'' finished with non-zero exit value 2
Information:BUILD FAILED

I have updated the 'compile' lines in library build.gradle to the latest one.

After searching other links, still I could not find the problem. It is possibly related to the version of library or multiple occurrence of library entries.

There is also a possibility of 'creativesdk' library has older non-compatible version.

Please comment on what could be wrong.

Thanks in advance .....

2

There are 2 answers

0
sdex On BEST ANSWER

Your app has reached a limit of the Android app methods number. You have to use Multidex (https://developer.android.com/tools/building/multidex.html#mdex-gradle)

0
SHS On

The Answer by Yuriy Mysochenko is Perfect.

While reading the link in the answer, I figured out, when I changed the Google Play service library link to current new version, the error started appearing.

As in our Project, we are only using Google Maps feature, I tried changing the library link in Build.gradle as following. ( We can use different component of the Google Play library, instead of using full library )

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

Now as I was not using full Google Play Library, 'the limit of Android app methods number' was not reached. The app built properly.

So currently I have not used Multidex. May be in future when we grow the app, we may have to use Multidex.