简体   繁体   中英

com.android.dex.DexIndexOverflowException when compiling from command line

I have a small Android application that is failing to compile from command line. I can build and deploy the application to the emulator in Android Studio without issues, however when I try to build from the command line I get the error below.

gradle clean assembleDebug

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:transformClassesWithDexForRelease'.

    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

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

BUILD FAILED

I understand it's saying I've exceeded the Android 64k method limit described here:

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

However why would the application compile fine in Android Studio? Any idea what I'm doing wrong when compiling from the command line? Thanks in advance.

As it turned out I was including all the Google Play Service libraries in my dependencies, ie in build.gradle:

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

I removed that dependency and added each Play Service library separately, ie:

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

per their documentation:

https://developers.google.com/android/guides/setup

That way I'm only including the libraries I use. Now the app compiles both in Android Studio and on the command line. I assume Android Studio replaces the entire Play Services library with what the application needs at compile time which is why I could previously compile in Android Studio but not on the command line, but I could not confirm this. Hope this helps someone else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM