發佈日期:

加入 Google Maps Activity 遇到執行錯誤

在Android Studio App Project 加入 Google Maps Activity 遇到執行錯誤,在 Gradle Console 訊息如下:

:app:transformClassesWithDexForDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
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


 

Google 老半天,有的說程式需要減肥,有的是Android Studio Invalidate Caches 需要清乾淨,或是有人 clean project……不過,還是比較多人提到版本衝突問題:

試了老半天,在Build.Grandle 找到這一段,修改後有效:

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.0.0'
compile 'com.google.android.gms:play-services-appindexing:9.8.0'
compile 'com.google.android.gms:play-services:9.8.0'
testCompile 'junit:junit:4.12'
}

把這兩列改為:

compile 'com.google.android.gms:play-services-appindexing:8.1.0'
compile 'com.google.android.gms:play-services:8.1.0'

這樣就能順利執行,至於Google Service 版本號碼,可以搜尋 google play service previous versions