好吧这让我抓狂了一天。我主要是iOS开发者,所以我不太了解Proguard之类的东西。我做了一个安卓应用程序,其中包括dropbox和谷歌驱动器API。如果我通过Eclipse在手机上部署该应用程序,则该应用程序工作得很好,但当我试图导出apk文件生成应用程序时,我在控制台上遇到了一个令人讨厌的错误。我的项目。属性文件是这样的…
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt:proguard-google-api-client.txt
# Project target.
target=android-17
android.library=false
错误对话框是这样的…PROJECT_FOLDER_NAME/proguard-project.txt不存在或不是常规文件
所以我编辑了我的项目。proguard-project.txt部分。
现在当创建apk时,我在控制台得到这些错误…
[2013-05-15 18:48:28 - BackMyAppUp] Proguard returned with error code 1. See console
[2013-05-15 18:48:28 - BackMyAppUp] Note: there were 367 duplicate class definitions.
[2013-05-15 18:48:28 - BackMyAppUp] Warning: org.apache.commons.logging.impl.ServletContextCleaner: can't find superclass or interface javax.servlet.ServletContextListener
[2013-05-15 18:48:28 - BackMyAppUp] Warning: org.apache.http.entity.mime.FormBodyPart: can't find superclass or interface org.apache.james.mime4j.message.BodyPart
[2013-05-15 18:48:28 - BackMyAppUp] Warning: org.apache.http.entity.mime.HttpMultipart: can't find superclass or interface org.apache.james.mime4j.message.Multipart
[2013-05-15 18:48:28 - BackMyAppUp] Warning: org.apache.http.entity.mime.MinimalField: can't find superclass or interface org.apache.james.mime4j.parser.Field
[2013-05-15 18:48:28 - BackMyAppUp] Warning: org.apache.http.entity.mime.content.AbstractContentBody: can't find superclass or interface org.apache.james.mime4j.message.SingleBody
[2013-05-15 18:48:28 - BackMyAppUp] Warning: org.apache.http.entity.mime.content.ContentBody: can't find superclass or interface org.apache.james.mime4j.message.Body
[2013-05-15 18:48:28 - BackMyAppUp] Warning: org.apache.http.entity.mime.content.ContentBody: can't find superclass or interface org.apache.james.mime4j.descriptor.ContentDescriptor
[2013-05-15 18:48:28 - BackMyAppUp] Warning: library class android.net.http.AndroidHttpClient extends or implements program class org.apache.http.client.HttpClient
[2013-05-15 18:48:28 - BackMyAppUp] Warning: com.google.android.gms.auth.GoogleAuthUtil: can't find referenced class com.google.android.gms.R
[2013-05-15 18:48:28 - BackMyAppUp] Warning: com.google.android.gms.auth.GoogleAuthUtil: can't find referenced class com.google.android.gms.R$string
[2013-05-15 18:48:28 - BackMyAppUp] Warning: com.google.android.gms.auth.GoogleAuthUtil: can't find referenced class com.google.android.gms.R$string
[2013-05-15 18:48:28 - BackMyAppUp] Warning: com.google.android.gms.auth.GoogleAuthUtil: can't find referenced class com.google.android.gms.R$string
和大约300个类似的行。
如果我使用从bin文件夹生成的apk, google drive功能在手机上不起作用,但如果我通过eclipse部署,它可以工作。
FWIW,升级到ADT 22后,我有超过800个类似的错误与Proguard配置,以前工作正常,该应用程序在没有Proguard构建时也崩溃了ClassDefNotFound错误的设备。
最后的解决方案是在我的主要项目和所有库项目的构建路径编辑器的Order和Export选项卡上勾选"Android Private Libraries"。
你要么使用Proguard(优化,混淆,…),要么不使用
如果你不需要,只需注释(用#)指向项目中proguard配置的部分。属性:
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt:proguard-google-api-client.txt
如果您愿意,解决方案是保持行不变,并创建以下文件:proguard-project.txt和proguard-google-api-client.txt
对于proguard-google-api-client.txt,你可以在这里找到一个例子:https://google-api-java-client.googlecode.com/hg/google-api-client-assembly/proguard-google-api-client.txt
对于proguard-project.txt,它将取决于您在归档另一个错误后得到的错误。您可能需要添加几个:
-libjars <path_to_a_jar_used_in_app>
这感觉有点愚蠢,3天来我用proguard搞砸了,但问题是我在发布apk中使用了调试密钥库SHA1密钥,因此Google drive应用程序崩溃,我在Google API控制台使用了正确的SHA1密钥来解决它。