2016-08-21 44 views
4

我開始爲我的小遊戲使用Google Play服務。像導遊說的,我在我的build.gradle(Module: app)中加入了compile 'com.google.android.gms:play-services:9.4.0'無法使用'com.google.android.gms:play-services:9.4.0'創建APK'

由於該更改,我無法構建我的apk,但我仍然可以在手機上運行它。我得到以下錯誤,而建設的APK:

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

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 Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

感謝

+1

可以通過導入完整庫發生,您應該從谷歌只需要進口玩類的lib。在表1中列出了哪些部分可用:https://developers.google.com/android/guides/setup – Opiatefuchs

回答

6

multiDexEnabledbuild.gradle第一。

defaultConfig { 
    // ... 
    multiDexEnabled true 
} 

而我想推薦的另一件事是不要使用com.google.android.gms:play-services:9.4.0。它包括您的項目可能不需要的所有服務。所以我想建議更具體地設置你的dependencies

例如,我只能添加gcmplaces

dependencies { 
    //... 
    compile 'com.google.android.gms:play-services-gcm:9.2.0' 
    compile 'com.google.android.gms:play-services-places:9.2.0' 
    compile 'com.android.support:multidex:1.0.1' 
} 

你會發現特定要求from here

Sample image from the link

+0

謝謝,「multiDexEnabled true」似乎有所幫助。現在我只使用「compile」com.google.android.gms:play-services:9.4.0'「。 –