Hi,
I'm trying to create a proguard configuration that doesn't brake the generated code made by dagger-compiler.
The thing is dagger uses the names of some classes, members, etc. as keys. so it is important that this names are preserved.
So far I made these rules to allow dagger to work:
#Keep the annotated things annotated
-keepattributes *Annotation*
#Keep the dagger annotation classes themselves
-keep @interface dagger.*,javax.inject.*
#Keep classes annotated with @Module
-keepnames @dagger.Module class *
#-Keep the the fields annotated with @Inject of any class that is not deleted.
-keepclassmembers class * {
@javax.inject.* <fields>;
}
#-Keep the names of classes that have fields annotated with @Inject and the fields themselves.
-keepclasseswithmembernames class * {
@javax.inject.* <fields>;
}
# Keep the generated classes by dagger-compile
-keep class **$$ModuleAdapter
-keep class **$$InjectAdapter
-keep class **$$StaticInjection
The problem is that these rules saves the name of classes that have a field annotated with the @Inject annotation. but there are cases in which a class that inherits another class that has this annotated members, has to have its name preserved as well, but since it doesn't have a @Inject annotation itself, proguard obfuscates this inheriting class.
It would be nice to be able to write something like this:
-keepclassesandchildrenwithmembernames class * {
@javax.inject.* <fields>;
}
In order to preserve the names of all the children of this class.
Meanwhile I have to manually search for this classes and put them on the proguard config.
Thanks.
Thanks for the suggestion. Dagger's reflection is difficult to express indeed. I'm still looking for a more natural notation though. The goal here is to keep pairs of classes like '**' and '**$$ModuleAdapter'. Maybe just
I'm not sure I follow your notation. But as long as it serves the purpose.
By the way, its not the ModuleAdapter that is givving me trouble.
Its all the classes that are injected and then another class inherts them.
Any class that needs injection is easily covered by:
But any child class that inherits, is not going to be covered by the above rule and is going to be obfuscated. Hence my need for being able to pass the
-keepto the next generation. Kind of a recursive keep. Which I'm sure could be used in more use cases.In this case, I think the point of keeping the names is to make sure they remain consistent with their corresponding $$..... classes. A -keep option with multiple classes would allow this, based on some kind of matching of corresponding wildcards.
For the record, Dagger 2.0 will not have these problems, as its generated code will be statically referenced, and not reliant on stringified keys, so it should be far more pro-guardable.
That's nice to hear. It will make static analysis a lot easier and more effective.
Yeah, I have read and find the new dagger approach quite nice. I have decided to use a very similar approach like in dagger 2.0 except I will make all the classes manually and avoid the code generation altogether since android plugin does not support it out of the box.
Thanks anyway.