Nivrutti Pawar
Nivrutti Pawar

Reputation: 524

how to use proguard toothpick rule?

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.

Upvotes: 3

Views: 578

Answers (1)

kingargyle
kingargyle

Reputation: 1239

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.** { *; }

Upvotes: 2

Related Questions