【问题标题】:Getting errors only when building .apk仅在构建 .apk 时出现错误
【发布时间】:2016-08-30 19:29:45
【问题描述】:

我有一个安卓应用。我可以在我的设备上毫无问题地运行它,但是当我尝试构建 apk 文件时,出现以下错误。

Error:warning: Ignoring InnerClasses attribute for an anonymous innerclass
Error:(org.joda.time.DateTimeZone$1) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably  produced by a
Error:compiler that did not target the modern .class file format. The  recommended
Error:solution is to recompile the class from source, using an up-to-  date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
:app:transformClassesWithDexForDebug FAILED
Error:Execution failed for task     ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException:   com.android.ide.common.process.ProcessException:   java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command  '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

这是我的依赖项:

dependencies {
compile 'com.google.android.gms:play-services:+'
compile 'com.google.code.gson:gson:2.1'
compile 'com.google.guava:guava:11.0.1'
compile 'com.google.protobuf:protobuf-java:2.2.0'
compile files('libs/acra-4.5.0.jar')
compile files('libs/google-api-client-1.10.3-beta.jar')
compile files('libs/google-api-client-android2-1.10.3-beta.jar')
compile files('libs/google-http-client-1.10.3-beta.jar')
compile files('libs/google-http-client-android2-1.10.3-beta.jar')
compile files('libs/google-oauth-client-1.10.1-beta.jar')
compile files('libs/jackson-core-asl-1.9.4.jar')
compile files('libs/jsr305-1.3.9.jar')
compile files('/Users/emredurmus/Documents/Projects/CrmMobile1/Libs/odata4j-0.7.0-clientbundle.jar')
compile 'com.google.android.gms:play-services:+'}

我该怎么办?

谢谢

【问题讨论】:

  • 您是否尝试过清理和重建项目?我之前也遇到了同样的错误。我也做过同样的事情。它对我有用
  • 是的,我做到了。它在我的真实设备上也能正常工作。问题是当我尝试创建 apk 时。

标签: android android-studio gradle apk


【解决方案1】:

这是你真正的问题:

Error:The number of method references in a .dex file cannot exceed 64K.

这是你的解决方案:

Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

【讨论】:

    【解决方案2】:

    将以下行添加到我的 proguard-rules.pro 文件中:

    -keepattributes InnerClasses,EnclosingMethod
    -dontoptimize
    

    【讨论】:

      【解决方案3】:

      您已超过 64k 方法限制。

      仅将 compile 'com.google.android.gms:play-services:+'} 替换为您需要的 GMS 服务。

      您只能包含您需要的来自 google play 服务的选择性 API。获取要在此处添加的确切名称 - official documentation

      【讨论】:

        猜你喜欢
        • 2018-08-13
        • 1970-01-01
        • 1970-01-01
        • 2016-08-10
        • 2018-09-28
        • 2018-06-25
        • 1970-01-01
        • 1970-01-01
        • 2017-11-13
        相关资源
        最近更新 更多