-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Codegen should survive ProGuard #202
Comments
Adding this to the 1.0 milestone. I'd love to see this land in the next two or three weeks! |
That's pretty ambitious. I'm not ready to ship this yet! |
Hey, I'd like to know if there are any plans to rebase & integrate this pull request? I'd love to use Dagger in my project but one of the critical requirements is obfuscation. M. |
@mgrzechocinski see this SO answer and the comments on this G+ thread. |
Thanks for those links, they are very helpful. I have a requirement that the app has to be obfuscated as much as possible. Keeping e.g. names of classes which contains injects (coffee.* in sample app) seems to be unacceptable. I definitely need to play with it. |
Dagger's codegen changed quite a bit since I've forked it and I'm afraid I now don't have the time to rebase my changes. I also lack a will to do it, since it's clearly not a way Dagger's creators meant for it to go. Otherwise they'd have probably already done it. |
This is still an open enhancement issue for milestone 2.0, but it looks like we should we forget about any other approach in dagger regarding ProGuard integration rather than tweaking the latter (as my SO question mentioned above suggests). |
I have been trying to make a generic proguard file that makes it possible to use dagger-compiler.
I'm sure I'm missing more things, but the one that is currently blocking me is this use case: If I have a base class: public class Parent {
@Inject Something something;
...
} And an inherited class: public class Child extends Parent {
...
} I will have to declare both in the Module like this: @Module(injects = {Parent.class, Child.class})
public class Module {
@Provide
Something provideSomething() {
return new Something();
}
} Now, the parent class is covered by the fact that it has an This could be solved kind of easy if the dagger-compiler generated a Proguard config file which simply adds all classes declared in the So far my proguard file covers all modules (and its provide methods) and all classes with Injected methods. Don't know what other use cases are needed to be covered. What you think of generating this config file? |
That's not the direction we want to go for ProGuard safety, but it would work in the interim. |
Oh, what's the direction you aim at? |
Using |
Is this already implemented in a snapshot or is it a work in progress, our |
Distant. Nobody is currently working on this. Additionally, this type of thing is not required with the current version 2 design. |
What do you mean is not requiered in version 2? will version not have Also, if that is the case, will a PR for version 1.1.x be welcome? |
No. There will be zero reflection.
Yes. We can make a v1.3 with something like this if it proves to be valuable without causing runtime penalty. |
Well, If I where to submit a PR it would be the generation of a Proguard |
V2.0 should be mostly in usable shape by end of Q2, though a good chunk |
Another question. Will version 2 require to change annotations in the code? |
It is 100% backwards incompatible. You can learn more at #366. |
Eh. We've been tossing around some compatibility aids to make it less |
From what I see in the document, classes injected would stay very similar. |
Ok, trying to figure out what rules would be missing in my generic proguard config, I've found the following:
I do not use the Of all this points, the ones that would need to be incorporated in the generation of a proguard config file would be the entrypoints, the first father of the entrypoints and the types that the providers return. I'm not sure if sending a PR for this or waiting for version 2 is a better idea. |
@SuperJugy your generic config works pretty well for me. |
Are you using the @Module(injects=AnotherClassThatInheritsFromAnInjectedClass.class)
public class Module {
@Provide
Something provideSomething() {
...
}
} Because with the above approach, proGuard obfuscates the class Notice that I'm using the My current approach was to remove all the classes from |
@SuperJugy yeah I'm still testing it. I pretty much exclusively use: @Inject
public Something(){
} for my none Interestingly I think because I very rarely do:
Or I have explicitly defined |
@SuperJugy I don't do: I just made the following change to make sure #-Keep the names of classes that have fields annotated with @Inject and the fields themselves.
-keepclasseswithmembernames class * {
@javax.inject.* <fields>;
@javax.inject.* <init>(...);
} Noticed though that barely anything is obfuscated. Not ideal but better than nothing. Guess the full swing to 2.0 will improve this greatly when very little reflection is done. |
Yeah I really hope for it. |
What's the state of this? I've been through many variations of PG config, none of which worked. Still trying to get to the bottom of it, but what I believe happens is that ProGuard renames a base type from which injectable classes inherit, but the inject adapters are still referring to that base type by its unobfuscated name. I'm not sure why Dagger is even looking at that class, as it has neither Inject annotations nor injectable fields or constructors (it's a plain old base class), but that's what's happening. |
Ah, it's because of this:
so what we'd need in addition to what's been mentioned here is a rule that says: whenever a class is used as part of injection, keep the super class, too. |
I've got a pro guard config that seems to work well. I'll post it in a sec.
|
@chrisjenx I had some success with this config:
meaning, I couldn't make it work without turning off obfuscation entirely for any classes referenced by Dagger. Good enough I guess. |
Oh and, I had to add exceptions for any classes that PG decided to completely remove (or merge with others) and which were referenced by Dagger. We only had the one I mentioned above though, so I had to fully |
@chrisjenx Can you please post the config that you got working? |
+1 @Balauru |
See Dagger 2. |
Update the readme to account for Dagger 2.0.1 release
See this G+ thread & branch from @cermakcz:
https://plus.google.com/u/0/117878637395157279424/posts/HMiCxi4wh7J
https://github.com/cermakcz/dagger/compare/obfuscatable
The text was updated successfully, but these errors were encountered: