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

人走茶凉 提交于 2019-11-28 06:44:30

问题


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


回答1:


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);
    }



回答2:


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.



来源:https://stackoverflow.com/questions/40958192/i-get-errorexecution-failed-for-task-apptransformclasseswithdexfordebug-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!