簡體   English   中英

導入Google Play服務會導致DexIndexOverflowException

[英]Importing Google Play Services causes DexIndexOverflowException

我正在嘗試使用和GoogleApiclient實現View.OnClickListener接口,如下所示

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

但這失敗了以下錯誤

錯誤:任務':app:dexDebug'的執行失敗。 com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:進程'命令'C:\\ Program Files \\ Java \\ jdk1.8.0_51 \\ bin \\ java.exe''以非完成零退出值2

以下是Gradle控制台錯誤注意:

 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:進程'命令'C:\\ Program Files \\ Java \\ jdk1.8.0_51 \\ bin \\ java.exe''以非完成零退出值2

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

建築失敗

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

你很幸運,因為Google Play服務現在允許你挑選和選擇要導入的子模塊,而不是導入整個東西。 這使您可以快速輕松地解決此問題。

文檔

在6.5之前的Google Play服務版本中,您必須將整個API包編譯到您的應用中。 在某些情況下,這樣做會使您的應用程序中的方法數量(包括框架API,庫方法和您自己的代碼)在65,536限制下更加困難。

從6.5版開始,您可以選擇性地將Google Play服務API編譯到您的應用中。

因此,如果您只需要Google雲端硬盤,請將其替換為:

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

有了這個:

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

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM