简体   繁体   中英

I get: Error:Execution failed for task ':app:transformClassesWithDexForDebug'. when making Google maps App

I followed the instructions in this link: https://developers.google.com/maps/documentation/android-api/start to make a simple android app with Google Maps API but I always get this error below when I run the app on my phone:

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

clean and see still error is there if yes,

1.go to your build.gradle file. add multiDexEnabled true

 defaultConfig {
    multiDexEnabled true
}

2.in your dependencies add compile 'com.android.support:multidex:1.0.1'

dependencies {
 compile 'com.android.support:multidex:1.0.1'
}

3.inside your application tag in menifest add android:name="android.support.multidex.MultiDexApplication"

<application
        android:name="android.support.multidex.MultiDexApplication"
    ....

4.use this override method on your launching activity

 @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

Check whether you are depending on the whole Google Play Services instead of just depending on the maps component. From the documentation

If 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. For information on how to do this, see Selectively compiling APIs into your executable.

For example (using the last Play Services version), change this in your build.gradle

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

To this

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

If you add other Play Services modules you will need to add them to your build.gradle individually.

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