1

I created a new Android Studio project with a MapsActivity, if i try to launch the app on my Huawei P8 Lite device this error appears:

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 Build.Gradle(Module: app):

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 25
        buildToolsVersion "24.0.2"
        defaultConfig {
            applicationId "com.example.de.maptestdel"
            minSdkVersion 15
            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'
        compile 'com.android.support:design:25.1.0'
        testCompile 'junit:junit:4.12'
    }

Is there another way to solve it except enabling Multidex? I heard that it's not so good to activate it.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Aaron Waller
  • 175
  • 4
  • 21
  • First answer has pretty much pin pointed at your problem. That should solve the problem for now. But there is always a possibility that with the addition of more and more features, you might face the problem yet again. Basically , the issue is because of the limit imposed on the method count allowed per dex file. So in case you face the problem sometime later in future, Google for the words 'Android Multidex'. Android has the option of splitting your APK into multiple dex files – Dibzmania Feb 08 '17 at 06:21
  • http://stackoverflow.com/questions/36785014/the-number-of-method-references-in-a-dex-file-cannot-exceed-64k-api-17/36786721#36786721 – Gabriele Mariotti Feb 08 '17 at 15:05

1 Answers1

3

Use specific/individual API from Google Play Services library. You have used compile 'com.google.android.gms:play-services:10.0.1' and this library method count is 79958.

Refer this link : https://developers.google.com/android/guides/setup

In versions of Google Play services prior to 6.5, you had to compile the entire package of APIs into your app. In some cases, doing so made it more difficult to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit.

From version 6.5, you can instead selectively compile Google Play service APIs into your app.

For e.g.

For Google Maps, use :

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

method count : 17984

For Google Cloud Messaging :

com.google.android.gms:play-services-gcm:10.0.1

method count : 15784

So, using individual API will reduced apk method count. Then, no need to enable multidex.

Mayur Gangurde
  • 1,552
  • 12
  • 22