8

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!

Romulus Urakagi Ts'ai
  • 3,699
  • 10
  • 42
  • 68

1 Answers1

18

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.

T. Neidhart
  • 6,060
  • 2
  • 15
  • 38
  • I tried this but it third party library warnings are still popping up. I only have -keep, -dontwarn, -verbose, and -keepattributes SourceFile,LineNumberTable,Annotation. – Romulus Urakagi Ts'ai Sep 12 '16 at 03:10
  • Then you can try using -dontwarn !my.package.name.**,** – T. Neidhart Sep 12 '16 at 05:16
  • Thanks, the `, **` was necessary for -dontwarn line. – Romulus Urakagi Ts'ai Sep 12 '16 at 06:29
  • Does it still work for you? I can't get it running: [Proguard (R8) negate operator not working to keep anything except certain packages](https://stackoverflow.com/questions/59248681/proguard-r8-negate-operator-not-working-to-keep-anything-except-certain-packag?noredirect=1&lq=1) – OneWorld Dec 10 '19 at 15:28
  • I had to use below syntax to keep class and methods intact `-keep class !my.package.name.**,** { *; }` – Lahiru Chandima Dec 06 '20 at 09:30