2016-02-03 94 views
2

我想與和GoogleApiclient實現View.OnClickListener界面如下導入谷歌Play服務,使DexIndexOverflowException

public class MainActivity extends Activity implements 
View.OnClickListener,GoogleApiClient.ConnectionCallbacks,OnConnectionFailedListener, com.google.android.gms.location.LocationListener{ 
    } 

但這種失敗,下面的錯誤

Error:Execution failed for task ':app:dexDebug'. com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe'' finished with non-zero exit value 2

下面是搖籃控制檯錯誤 ote:

H:\xxx\app\src\main\java\com\dbprox\css\MainActivity.java uses or overrides a deprecated API. 
Note: Recompile with -Xlint:deprecation for details. 

:app:compileDebugNdk UP-TO-DATE 
:app:compileDebugSources 
:app:preDexDebug UP-TO-DATE 
:app:dexDebug 
AGPBI: {"kind":"simple","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","sources":[{}]} 
AGPBI: {"kind":"simple","text":"com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536","sources":[{}]} 
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:484)","sources":[{}]} 
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:261)","sources":[{}]} 
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:473)","sources":[{}]} 
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:161)","sources":[{}]} 
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:188)","sources":[{}]} 
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)","sources":[{}]} 
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)","sources":[{}]} 
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.run(Main.java:277)","sources":[{}]} 
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.main(Main.java:245)","sources":[{}]} 
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.Main.main(Main.java:106)","sources":[{}]} 


FAILED 

FAILURE: Build failed with an exception. 
  • 出錯: 任務':app:dexDebug'的執行失敗。

    com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe'' finished with non-zero exit value 2

  • 嘗試: 與--stacktrace選項獲取堆棧跟蹤運行。使用--info或--debug選項運行以獲取更多日誌輸出。

構建失敗

回答

14

由於您正在導入的庫的數量,您的項目已超過65536個方法。

儘管您很幸運,因爲Google Play服務現在允許您選擇要導入的子模塊,而不是導入整個事物。 這使您可以快速輕鬆地解決此問題。

the documentation:有了這個

compile 'com.google.android.gms:play-services:9.2.0' 

In versions of Google Play services prior to 6.5, you had to compile the entire package of APIs into your app. In some cases, doing so made it more difficult to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit.

From version 6.5, you can instead selectively compile Google Play service APIs into your app.

因此,如果谷歌Drive是你所需要的,然後更換這個

compile 'com.google.android.gms:play-services-drive:9.2.0' 
0

,我認爲你的一些jar文件不編譯。您應該進入build.gradle文件並查看您的依賴關係。如果你只是導入一些jar文件,你可以嘗試刪除並一次添加一個。這將幫助您確定哪一個會導致錯誤。

對於錯誤:MainActivity.java使用或覆蓋棄用的API。 注意:使用-Xlint:deprecation重新編譯以獲取詳細信息。,您可能正在使用較舊版本的appcompat庫。你可以參考這個link

+0

問題是編譯「COM .google.android.gms:play-services:8.3.0',將它從build.girdle中移除。我能夠建立這個項目。我需要這個庫連接到谷歌drive.How我可以添加這個庫與任何issue.compile'c​​om.android.support:appcompat-v7:23.1.1' compile'c​​om.android.support:design:23.1.1 ' compile'c​​om.dropbox.core:dropbox-core-sdk:2.0-beta-5' compile'c​​om.google.code.gson:gson:2.3.1' compile'c​​om.microsoft.services.msa: msa-auth:0.8.4' compile'c​​om.microsoft.aad:adal:1.1.7' // compile'c​​om.google.android.gms:play-services:8.3.0' –