Skip to content

Instantly share code, notes, and snippets.

@orip
Last active April 19, 2016 11:56
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save orip/6807041 to your computer and use it in GitHub Desktop.
Save orip/6807041 to your computer and use it in GitHub Desktop.
ProGuard rules for using Dagger 1.1.0 with gradle.
dependencies {
def dagger_version = "1.1.0"
compile "com.squareup.dagger:dagger:${dagger_version}"
compile "com.squareup.dagger:dagger-compiler:${dagger_version}"
}
# http://stackoverflow.com/a/18177491/37020
# https://plus.google.com/114746422988923214718/posts/fhFucCgy8gr
-keepattributes *Annotation*
-keepclassmembers,allowobfuscation class * {
@javax.inject.* *;
@dagger.* *;
<init>();
}
-keep class **$$ModuleAdapter
-keep class **$$InjectAdapter
-keep class **$$StaticInjection
-keepnames !abstract class com.example.mypackage.**
-keepnames class dagger.Lazy
# Gradle includes dagger-compiler and javawriter in the final package
-dontwarn dagger.internal.codegen.**
-dontwarn com.squareup.javawriter.**
@Jogan
Copy link

Jogan commented Feb 7, 2014

Does this work? I'm still getting errors in the release apk. Even when using keep names for my package.

@chakrit
Copy link

chakrit commented Mar 24, 2014

Just tried with dagger 1.2, does not work. Still getting a lot of proguard errors.

@cgruber
Copy link

cgruber commented Jun 5, 2014

This is insufficient for Dagger 1.2 as module reflective fall-back was disabled, and the string-keys that Dagger uses are not obfuscatable. It should work for mere unused-code-stripping, but not for obfuscation.

Side note - you should do "-keepattributes Signature" as well if you have any generics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment