-
Notifications
You must be signed in to change notification settings - Fork 824
ProGuard
Donn Felker edited this page Oct 12, 2012
·
1 revision
Storage space on android devices can be heavily constrained, particularly for users of the older generation of devices. The guice library isn't small, but we can reduce its footprint by using proguard to remove unnecessary classes and methods.
Make sure you're using the SDK tools release 8 or later and visit http://developer.android.com/intl/fr/guide/developing/tools/proguard.html. Then use a configuration like the following::
-target 1.6
-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.**
If proguard is erroneously stripping out any classes you need, chances are you'll need to add some additional -keep
directives to your config.txt
. Consult the proguard manual for more details.
Look at this blog post on how to make obfuscation to work and some more tips.
- For Projects Using Gradle
- For Projects Using Maven
- Manual Installation for Older Projects
- Inheriting from RoboGuice Classes
- Upgrade Instructions from RoboGuice 2
- Your First View Injection
- Your First Resource Injection
- Your First System Service Injection
- Your First POJO Injection
- Singletons and ContextSingletons (wiki/Understanding Scopes)
- Your First Custom Binding
- Your First Injected Fragment
- Your First Injected Service and BroadcastReceiver
- Your First Testcase
- Your First Injection into a Custom View class
- Your First Injected ContentProvider
- Using Events in your RoboGuice application
- Logging via Ln
- RoboGuice Standard Injections
- How Injection Works
- When Injection Just Works, and when you have to call injectMembers()
- The Difference between Global and Context-scoped Injection
- Analyzing a Guice Stack Trace
- What's the difference between Nullable and Optional?
- RoboBlender wiki
- Use ProGuard with RoboGuice
- Define advanced custom bindings
- Remove or replace RoboGuice's default bindings
- Use your own BaseActivity with RoboGuice
- Inject into an object that you don't instantiate
- Dealing with Circular Dependencies
- Work with Library Projects
- Deal with ComputationException due to StackOverflowError
- Taming Fragmentation using RoboGuice