导入Google Play服务会导致DexIndexOverflowException [英] Importing Google Play Services causes DexIndexOverflowException

查看:142
本文介绍了导入Google Play服务会导致DexIndexOverflowException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图实现View.OnClickListener接口和GoogleApiclient,如下所示:

  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:\程序文件\Java\jdk1 .8.0_51 \\\\\\\\\\\\''''''用'
非零退出值2'结束

Gradle控制台错误
ote:

  H:\xxx\app\src\main\ java\com\dbprox\css\MainActivity.java使用或覆盖弃用的API。 
注意:使用-Xlint:deprecation重新编译以获取详细信息。

:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:preDexDebug UP-TO-DATE
:app:dexDebug
AGPBI:{kind:simple,text:意外的顶级例外:,sources:[{}]}
AGPBI:{kind:simple,text :com.android.dex.DexIndexOverflowException:方法ID不在[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),来源:[{}]}
AGPBI:{kind:simple,text:\tat com.android.dx.command.Main.main(Main.java:106) ,来源:[{}]}


失败

失败:构建失败,出现异常。




  • 出错:
    执行失败任务':app:dexDebug'。


    com.android.ide.common.process.ProcessException:org.gradle.process.internal。 ExecException:进程'命令'C:\程序文件\Java\jdk1.8.0_51\bin\java.exe''以非零退出值2结束



  • 尝试:
    使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项来获得更多的日志输出。


  • $ b

    BUILD FAILED

    解决方案

    由于您正在导入的库数量众多,您的项目已超过65536个方法。 >尽管您很幸运,因为Google Play服务现在允许您挑选和选择要导入的子模块,而不是导入整个事物。
    这使您可以快速轻松地解决此问题。



    文档
    $ b


    在6.5之前的Google Play服务版本中,您必须将
    整个包的API编译到您的应用程序中。在某些情况下,这样做使
    更难以在65,536
    限制下保持应用程序中的方法数量(包括
    框架API,库方法和您自己的代码)。



    从版本6.5开始,您可以选择性地将Google Play
    服务API编译到您的应用中。


    因此,如果您需要Google Drive,请将其替换为:

      compile'c​​om。 google.android.gms:play-services:9.2.0'

    有了这个:

      compile'c​​om.google.android.gms:play-services-drive:9.2.0'


    I am trying to implement View.OnClickListener interface with and GoogleApiclient as below

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

    But this fails with below error

    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

    Below is the Gradle Console Error 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.
    

    • What went wrong: 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

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

    BUILD FAILED

    解决方案

    Your project has exceeded 65536 methods due to the amount of libraries you are importing.

    You are in luck though, because Google Play Services now allows you to pick and choose sub-modules to import, instead of importing the entire thing. This allows you to quickly and easily fix this issue.

    From the documentation:

    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.

    So, if Google Drive is all you need, then replace this:

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

    With this:

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

    这篇关于导入Google Play服务会导致DexIndexOverflowException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆