I'm using Proguard to obfuscate my code, and I need to keep every third party libraries like:
-keep class com.layer.** -dontwarn com.layer.** -keep class com.twitter.** -keep class android.support.** -keep class com.crashlytics.** { *; } -dontwarn com.crashlytics.** ...
And whenever I add a new third party library, I need to check its package name and add it to my proguard config file, or the app may crashes.
Can't I write the rule just like this? I don't care about codes that's not mine.
-keep class !(my.package.name.**)
-dontwarn !(my.package.name.**)
Thanks!
No shrinking, no obfuscation; not for classes, not for members. In real use cases, you can let ProGuard do at least some of it’s work. Even if your variables are accessed by reflection, you could remove and rename unused classes, for example. So let’s look through the more specific -keep variants.
This is the most permissive keep directive; it lets ProGuard do almost all of its work. Unused classes are removed, the remaining classes are renamed, unused members of those classes are removed, but then the remaining members keep their original names. This one doesn’t get a table, because it’s the same as -keep.
You can prevent ProGuard from removing anything in a certain package as follows; -keep,allowoptimization,allowobfuscation class com.example.mypackage.** { *; } Using the modifiers allowoptimization and allowobfuscation will make sure that ProGuard still obfuscates and optimizes the code.
By default, ProGuard shrinks the code: it removes all unused classes and class members. It only keeps the ones listed by the various -keep options, and the ones on which they depend, directly or indirectly.
To keep everything except classes in your own package you can use the rule that you already pointed out (excluding the brackets):
-keep class !my.package.name.** { *; }
This will implicitly keep everything else. You still can add additionally -keep rules for your classes if needed.
The rule for the -dontwarn should work in a similar way:
-dontwarn !my.package.name.**,**
You can also add similar -dontnote rules if needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With