[英]proguard can't find referenced class
我正在尝试在发布apk上运行proguard,但在控制台中收到很多“找不到引用的类”错误。
[2014-05-06 17:35:05 - DesiDime] Warning: library class android.net.http.AndroidHttpClient extends or implements program class org.apache.http.client.HttpClient
[2014-05-06 17:35:05 - DesiDime] Warning: com.google.api.client.http.protobuf.ProtoHttpContent: can't find referenced class com.google.protobuf.MessageLite
[2014-05-06 17:35:05 - DesiDime] Warning: com.google.api.client.http.protobuf.ProtoHttpContent: can't find referenced class com.google.protobuf.MessageLite
[2014-05-06 17:35:05 - DesiDime] Warning: com.google.api.client.http.protobuf.ProtoHttpContent: can't find referenced class com.google.protobuf.MessageLite
[2014-05-06 17:35:05 - DesiDime] Warning: com.google.api.client.http.protobuf.ProtoHttpContent: can't find referenced class com.google.protobuf.MessageLite
[2014-05-06 17:35:05 - DesiDime] Warning: com.google.api.client.http.protobuf.ProtoHttpContent: can't find referenced class com.google.protobuf.MessageLite
[2014-05-06 17:35:05 - DesiDime] Warning: com.google.api.client.http.protobuf.ProtoHttpContent: can't find referenced class com.google.protobuf.MessageLite
[2014-05-06 17:35:05 - DesiDime] Warning: com.google.api.client.http.protobuf.ProtoHttpContent: can't find referenced class com.google.protobuf.MessageLite
[2014-05-06 17:35:05 - DesiDime] Warning: com.google.api.client.json.gson.GsonFactory: can't find referenced class com.google.gson.stream.JsonReader
[2014-05-06 17:35:05 - DesiDime] Warning: com.google.api.client.json.gson.GsonFactory: can't find referenced class com.google.gson.stream.JsonReader
[2014-05-06 17:35:05 - DesiDime] Warning: com.google.api.client.json.gson.GsonFactory: can't find referenced class com.google.gson.stream.JsonWriter
[2014-05-06 17:35:05 - DesiDime] Warning: com.google.api.client.json.gson.GsonFactory: can't find referenced class com.google.gson.stream.JsonWriter
[2014-05-06 17:35:05 - DesiDime] Warning: com.google.api.client.json.gson.GsonGenerator: can't find referenced class com.google.gson.stream.JsonWriter
[2014-05-06 17:35:05 - DesiDime] Warning: com.google.api.client.json.gson.GsonGenerator: can't find referenced class com.google.gson.stream.JsonWriter
[2014-05-06 17:35:05 - DesiDime] Warning: com.google.api.client.json.gson.GsonGenerator: can't find referenced class com.google.gson.stream.JsonWriter
[2014-05-06 17:35:05 - DesiDime] Warning: com.google.api.client.json.gson.GsonGenerator: can't find referenced class com.google.gson.stream.JsonWriter
[2014-05-06 17:35:05 - DesiDime] Warning: com.google.api.client.json.gson.GsonGenerator: can't find referenced class com.google.gson.stream.JsonWriter
下面是我的proguard-project.txt文件,摘自此处
-injars bin/classes
-injars libs
-outjars bin/classes-processed.jar
-libraryjars /home/vihaan/Downloads/adt-bundle-linux-x86-20131030/sdk/platforms/android-19/android.jar
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.content.Context {
public void *(android.view.View);
public void *(android.view.MenuItem);
}
-keepclassmembers class * implements android.os.Parcelable {
static ** CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
我已在我的project.properties文件中取消注释此行
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
我的libs目录包含必需的库
我不明白为什么会出现这些错误?
如我所见,您在使用Gson和protobuf时遇到了问题。 为了将Gson与proguard一起使用,请在proguard-project.txt文件中添加以下行:
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# For using GSON @Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }
整个例子可以在这里找到
为了解决protobuf错误,请尝试:
-keep class com.google.protobuf.** { *; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.