在Android Studio上构建失败

前端之家收集整理的这篇文章主要介绍了在Android Studio上构建失败前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
将所有Google支持库更新到最新版本(从v21到v22.2.0以及将Play服务更新到v7.5)后,我的项目不再成功构建.我得到的日志如下:
app:preDexDebug
AGPBI: {"kind":"simple","text":"Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar ","sources":[{}]}

AGPBI: {"kind":"simple","sources":[{}]}


:app:dexDebug
AGPBI: {"kind":"simple","sources":[{}]}
AGPBI: {"kind":"simple","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","text":"com.android.dex.DexIndexOverflowException: method ID not in [0,0xffff]: 65536","text":"\tat com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)","text":"\tat com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)","text":"\tat com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)","text":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)","text":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:189)","text":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)","text":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)","text":"\tat com.android.dx.command.dexer.Main.run(Main.java:246)","text":"\tat com.android.dx.command.dexer.Main.main(Main.java:215)","text":"\tat com.android.dx.command.Main.main(Main.java:106)","sources":[{}]}


 Failed

FAILURE: Build Failed with an exception.

* What went wrong:
Execution Failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-7-openjdk-amd64/bin/java'' finished with non-zero exit value 2

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD Failed

Total time: 1 mins 46.623 secs

我已经尝试将库恢复到早期版本,但仍然出现相同的错误.有没有人建议如何解决这个问题?

解决方法

Play服务是一个很大的库,有成千上万的方法可以满足你的dex限制.更好地用您需要的部件替换播放服务导入.从6.5版开始,您可以选择性地将Google Play服务API编译到您的应用中.
Google+ com.google.android.gms:play-services-plus:7.5.0
Google Account Login    com.google.android.gms:play-services-identity:7.5.0
Google Actions,Base Client Library com.google.android.gms:play-services-base:7.5.0
Google App Indexing com.google.android.gms:play-services-appindexing:7.5.0
Google App Invites  com.google.android.gms:play-services-appinvite:7.5.0
Google Analytics    com.google.android.gms:play-services-analytics:7.5.0
Google Cast com.google.android.gms:play-services-cast:7.5.0
Google Cloud Messaging  com.google.android.gms:play-services-gcm:7.5.0
Google Drive    com.google.android.gms:play-services-drive:7.5.0
Google Fit  com.google.android.gms:play-services-fitness:7.5.0
Google Location,Activity Recognition,and Places   com.google.android.gms:play-services-location:7.5.0
Google Maps com.google.android.gms:play-services-maps:7.5.0
Google Mobile Ads   com.google.android.gms:play-services-ads:7.5.0
Google Nearby   com.google.android.gms:play-services-nearby:7.5.0
Google Panorama Viewer  com.google.android.gms:play-services-panorama:7.5.0
Google Play Game services   com.google.android.gms:play-services-games:7.5.0
SafetyNet   com.google.android.gms:play-services-safetynet:7.5.0
Google Wallet   com.google.android.gms:play-services-wallet:7.5.0
Android Wear    com.google.android.gms:play-services-wearable:7.5.0

猜你在找的Android相关文章