proguard无法找到引用的类

时间:2014-05-06 12:08:57

标签: android release proguard

我试图在我的发布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文件,取自here

-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目录包含所需的库

enter image description here

我不明白为什么我会收到这些错误?

1 个答案:

答案 0 :(得分:1)

我可以看到你有Gson和protobuf的问题。 为了使用带有proguard的Gson,在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.** { *; }

可以找到整个示例here

为了解决protobuf错误,请尝试:

 -keep class com.google.protobuf.** { *; }