仅在构建.apk时出错

时间:2016-08-30 19:29:45

标签: android android-studio gradle apk

我有一个Android应用程序。我可以在我的设备上运行它没有问题,但是当我尝试构建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:+'}

我该怎么办?

由于

3 个答案:

答案 0 :(得分:2)

这是你真正的问题:

  

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

答案 1 :(得分:1)

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

-keepattributes InnerClasses,EnclosingMethod
-dontoptimize

答案 2 :(得分:1)

您超出了64k方法限制。

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

您只能包含所需的Google Play服务中的选择性API。获取要在此处添加的确切名称 - official documentation