[英]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: 我按照此链接中的说明进行操作: https : //developers.google.com/maps/documentation/android-api/start使用Google Maps API制作一个简单的android应用程序,但是当我在我的手机:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'. 错误:任务':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 com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:java.util.concurrent.ExecutionException:com.android.dex.DexIndexOverflowException:方法ID不在[0,0xffff]中: 65536
clean and see still error is there if yes, 清理并查看是否存在错误(如果是),
1.go to your build.gradle
file. 1.转到您的build.gradle
文件。 add multiDexEnabled true
添加multiDexEnabled true
defaultConfig {
multiDexEnabled true
}
2.in your dependencies add compile 'com.android.support:multidex:1.0.1'
2.在您的依赖项中添加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"
3.在清单中的应用程序标签内添加android:name="android.support.multidex.MultiDexApplication"
<application
android:name="android.support.multidex.MultiDexApplication"
....
4.use this override method on your launching activity 4.在启动活动中使用此替代方法
@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. 检查您是否仅依赖整个Google Play服务,而不是仅依赖于地图组件。 From the documentation 从文档中
If the number of method references in your app exceeds the 65K limit, your app may fail to compile. 如果您应用程序中方法引用的数量超过65K限制,则您的应用程序可能无法编译。 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. 您可以通过仅指定应用程序使用的特定Google Play服务API而不是全部指定这些API,来缓解编译应用程序时的问题。 For information on how to do this, see Selectively compiling APIs into your executable. 有关如何执行此操作的信息,请参阅选择性地将API编译到可执行文件中。
For example (using the last Play Services version), change this in your build.gradle
例如(使用最新的Play服务版本),请在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. 如果您添加其他Play服务模块,则需要将它们分别添加到build.gradle
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.