I am using TP in my project.
And I am Injecting some objects using TP. But when I applied the proguard rule in my application. It is working fine with debug mode But give null objects in release mode all the Objects I have injected through the @Inject annotations.
Asked
Active
Viewed 548 times
3

Phantômaxx
- 37,901
- 21
- 84
- 115

Nivrutti Pawar
- 514
- 3
- 17
-
There is not enough details to help you. At least, your proguard block should be added. Did you try this? https://github.com/stephanenicolas/toothpick/issues/146 – Snicolas Nov 02 '17 at 20:33
-
I have tried this already. But didnt worked for me.@Snicolas – Nivrutti Pawar Nov 03 '17 at 06:41
1 Answers
2
I have this working in our project, beyond what was in Issue #146, you need to add a few more things. There is an @Keep annotation setting from the android support annotations library that can be used to mark a class not to be obfuscated, I've had to do this on some kotlin data classes as Retrofit and the kotlin-reflect library couldn't play nice with the obfuscation. Anyways, the gist can be found here. In addition, you may want to specifically tell it to not obfuscate anything in the generated FactoryRegistry class in the package you told toothpick to generate the non-reflection registry and factory implementations.
# Note that if we could use kapt to generate registries, possible to get rid of this
-keepattributes Annotation
# Do not obfuscate classes with Injected Constructors
-keepclasseswithmembernames class * {
@javax.inject.Inject (...);
}
# Do not obfuscate classes with Injected Fields
-keepclasseswithmembernames class * {
@javax.inject.Inject ;
}
# Do not obfuscate classes with Injected Methods
-keepclasseswithmembernames class * {
@javax.inject.Inject ;
}
-keep @android.support.annotation.Keep class *
-keep @javax.inject.Singleton class *
-dontwarn javax.inject.**
-dontwarn javax.annotation.**
-keep class **$$Factory { *; }
-keep class **$$MemberInjector { *; }
-adaptclassstrings
-keep class toothpick.** { *; }

kingargyle
- 1,239
- 10
- 15
-
1Almost 90% of my classes are classes with some type of injections. Another 10% - model classes that should not be obfuscated because of Retrofit and Gson. It looks like it is simpler to just add -dontobfuscate for Proguard config... But I don't like this solution. – Gaket Mar 04 '18 at 11:41