导入 Google Play 服务导致 DexIndexOverflowException
Importing Google Play Services causes DexIndexOverflowException
我正在尝试实现 View.OnClickListener 与 GoogleApiclient 的接口,如下所示
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
下面是 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.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 选项以获得更多日志输出。
构建失败
我认为您的某些 jar 文件无法编译。您应该进入 build.gradle
文件并查看您的依赖项。如果您只是导入一些 jar 文件,您可以尝试一次一个地删除和添加它们。这将帮助您确定是哪一个导致了错误。
对于错误:MainActivity.java 使用或覆盖了已弃用的 API。
注意:使用 -Xlint:deprecation 重新编译以获得详细信息。,您可能正在使用旧版本的 appcompat 库。你可以参考这个link.
由于要导入的库数量,您的项目已超过 65536 个方法。
不过你很幸运,因为 Google Play Services 现在允许你选择要导入的子模块,而不是导入整个模块。
这使您可以快速轻松地解决此问题。
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.
因此,如果 Google 驱动器是您所需要的,那么替换为:
compile 'com.google.android.gms:play-services:9.2.0'
有了这个:
compile 'com.google.android.gms:play-services-drive:9.2.0'
我正在尝试实现 View.OnClickListener 与 GoogleApiclient 的接口,如下所示
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
下面是 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.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 选项以获得更多日志输出。
构建失败
我认为您的某些 jar 文件无法编译。您应该进入 build.gradle
文件并查看您的依赖项。如果您只是导入一些 jar 文件,您可以尝试一次一个地删除和添加它们。这将帮助您确定是哪一个导致了错误。
对于错误:MainActivity.java 使用或覆盖了已弃用的 API。 注意:使用 -Xlint:deprecation 重新编译以获得详细信息。,您可能正在使用旧版本的 appcompat 库。你可以参考这个link.
由于要导入的库数量,您的项目已超过 65536 个方法。
不过你很幸运,因为 Google Play Services 现在允许你选择要导入的子模块,而不是导入整个模块。 这使您可以快速轻松地解决此问题。
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.
因此,如果 Google 驱动器是您所需要的,那么替换为:
compile 'com.google.android.gms:play-services:9.2.0'
有了这个:
compile 'com.google.android.gms:play-services-drive:9.2.0'