androidproguardroboguice

Proguard issues with Roboguice 3


I'm trying to import Roboguice but when I do I get a bunch of Proguard errors.

I have looked at the other questions but none of the answers seem to work for me. I am trying to import Roboguice 3 to use the Coinbase Android SDK which looks to be required. It seems to be looking for the sherlock libraries which i dont use.

My gradle error is long so it can be found here.

My Proguard is:

-dontobfuscate
-dontoptimize
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-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

-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 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.**
-dontwarn javax.**
-dontwarn com.actionbarsherlock.internal.**
-dontwarn robojuice.activity.**

Solution

  • To make the final warnings go away so it will complete the compile:

    -dontwarn roboguice.**
    -dontwarn org.roboguice.**
    

    However, this only works if it truly doesn't need that library (and the other classes it mentions in the Warning: lines) and doesn't try loading it. If it does try at runtime, it will crash.

    As always, TEST ALL CODE PATHS since it is common for dependency injection errors to show up at runtime, especially when using ProGuard.