Question

I have proguard and roboguice working together as long as I don't turn on the obfuscate option. Once I remove dontobfuscate from my progaurd-project.txt file, I receive the following error:

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)

Does anyone have any ideas on how to fix that error? Here is my configuration file

-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
Was it helpful?

Solution

I'm not a proguard expert, but it looks like it is still obfuscating the roboguice library even though you have it included in the -libraryjars section. You could try to exclude it via its package.

-keep class roboguice.** { *; }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top