Proguard RoboGuice在ViewListener上混淆了错误

时间:2014-03-29 23:36:23

标签: android proguard roboguice

只要我没有打开混淆选项,我就有proguard和roboguice一起工作。从我的progaurd-project.txt文件中删除dontobfuscate后,收到以下错误:

NullPointerException:
roboguice.inject.ViewListener$ViewMembersInjector.reallyInjectMemberViews (SourceFile:172)
roboguice.inject.ViewListener$ViewMembersInjector.reallyInjectMembers (SourceFile:138)
roboguice.inject.ViewListener$ViewMembersInjector.injectViews (SourceFile:246)
roboguice.inject.ContextScopedRoboInjector.injectViewMembers (SourceFile:270)
roboguice.fragment.RoboFragment.onViewCreated (SourceFile:19)

有没有人对如何修复该错误有任何想法?这是我的配置文件

-libraryjars libs/android-support-v4.jar
-libraryjars libs/commons-codec.jar
-libraryjars libs/crashlytics.jar
-libraryjars libs/eventbus-2.2.0.jar
-libraryjars libs/guava-16.0.1.jar
-libraryjars libs/guice-3.0-no_aop.jar
-libraryjars libs/javax.inject-1.jar
-libraryjars libs/jsr305-1.3.9.jar
-libraryjars libs/library-1.0.1-SNAPSHOT.jar
-libraryjars libs/prettytime-3.2.4.Final.jar
-libraryjars libs/roboguice-2.0.jar
-libraryjars libs/sqlcipher.jar

-libraryjars <java.home>/lib/rt.jar

-dontwarn org.apache.http.**
-dontwarn com.xtremelabs.robolectric.**
-dontwarn com.xtremelabs.robolectric.**
-dontwarn org.junit.runners.**

-optimizationpasses 5
#-dontobfuscate
-dontoptimize
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses 
-verbose 
-dump ../bin/class_files.txt
-printseeds ../bin/seeds.txt
-printusage ../bin/unused.txt
-printmapping ../bin/mapping.txt 

# The -optimizations option disables some arithmetic simplifications that Dalvik 1.0 and 1.5 can't handle. 
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-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

-keepattributes *Annotation*

-keep class com.google.inject.Binder
-keepclassmembers class * {
    @com.google.inject.Inject <init>(...);
}
# There's no way to keep all @Observes methods, so use the On*Event convention to identify event handlers
-keepclassmembers class * { 
    void *(**On*Event); 
}
-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*(...);
} 
-keep public class roboguice.**
-keep class **.Finalizer
-keepclassmembers class ** { *** startFinalizer( ... ); }

##---------------Experimental  ----------

-allowaccessmodification
-renamesourcefileattribute SourceFile
-repackageclasses ''

-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-dontnote com.android.vending.licensing.ILicensingService

# Explicitly preserve all serialization members. The Serializable interface
# is only a marker interface, so it wouldn't save them.
-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

# Preserve all native method names and the names of their classes.
-keepclasseswithmembernames class * {
    native <methods>;
}


-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}


-keepclasseswithmembernames 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 * extends android.app.Activity {
   public void *(android.view.View);
   public void *(android.view.MenuItem);
}

# Preserve static fields of inner classes of R classes that might be accessed
# through introspection.
-keepclassmembers class **.R$* {
  public static <fields>;
}


# Preserve the special static methods that are required in all enumeration classes.
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keepclassmembers class * implements android.os.Parcelable {
    static android.os.Parcelable$Creator CREATOR;
}


##---------------Begin: proguard configuration for SQLCipher library  ----------

-keep class net.sqlcipher.** {*;}

##---------------Begin: proguard configuration for EventBus library  ----------

-keepclassmembers class ** {
    public void onEvent*(**);
}


##---------------Begin: proguard configuration for Gson  ----------
# 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


# 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.** { *; }


##---------------End: proguard configuration for Gson  ----------

##---------------Begin: proguard configuration for PrettyTime  ----------
-keep class org.ocpsoft.prettytime.i18n.**

##---------------Begin: proguard configuration for Crashliytics  ----------
-keepattributes SourceFile,LineNumberTable

1 个答案:

答案 0 :(得分:2)

我不是一名程序专家,但看起来它仍然使roboguice库变得模糊,即使你将它包含在-libraryjars部分中也是如此。您可以尝试通过其包裹将其排除。

-keep class roboguice.** { *; }