![](/img/trans.png)
[英]Error:Execution failed for task ':app:transformClassesWithDexForDebug'
[英]I get: Error:Execution failed for task ':app:transformClassesWithDexForDebug'. when making Google maps App
我按照此鏈接中的說明進行操作: https : //developers.google.com/maps/documentation/android-api/start使用Google Maps API制作一個簡單的android應用程序,但是當我在我的手機:
錯誤:任務':app:transformClassesWithDexForDebug'的執行失敗。 com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:java.util.concurrent.ExecutionException:com.android.dex.DexIndexOverflowException:方法ID不在[0,0xffff]中: 65536
清理並查看是否存在錯誤(如果是),
1.轉到您的build.gradle
文件。 添加multiDexEnabled true
defaultConfig {
multiDexEnabled true
}
2.在您的依賴項中添加compile 'com.android.support:multidex:1.0.1'
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
3.在清單中的應用程序標簽內添加android:name="android.support.multidex.MultiDexApplication"
<application
android:name="android.support.multidex.MultiDexApplication"
....
4.在啟動活動中使用此替代方法
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
檢查您是否僅依賴整個Google Play服務,而不是僅依賴於地圖組件。 從文檔中
如果您應用程序中方法引用的數量超過65K限制,則您的應用程序可能無法編譯。 您可以通過僅指定應用程序使用的特定Google Play服務API而不是全部指定這些API,來緩解編譯應用程序時的問題。 有關如何執行此操作的信息,請參閱選擇性地將API編譯到可執行文件中。
例如(使用最新的Play服務版本),請在build.gradle
更改
dependencies {
compile 'com.google.android.gms:play-services:10.0.1'
}
對此
dependencies {
compile 'com.google.android.gms:play-services-maps:10.0.1'
}
如果您添加其他Play服務模塊,則需要將它們分別添加到build.gradle
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.