Ying Wang | 7311a34 | 2013-08-21 18:32:49 -0700 | [diff] [blame] | 1 | # We have moved -dontobfuscate and -dontoptimize to the makefiles. |
Ying Wang | 3b2bdf1 | 2010-02-01 09:51:23 -0800 | [diff] [blame] | 2 | # dex does not like code run through proguard optimize and preverify steps. |
Ying Wang | 7311a34 | 2013-08-21 18:32:49 -0700 | [diff] [blame] | 3 | # -dontoptimize |
Ying Wang | 3b2bdf1 | 2010-02-01 09:51:23 -0800 | [diff] [blame] | 4 | -dontpreverify |
| 5 | |
| 6 | # Don't obfuscate. We only need dead code striping. |
Ying Wang | 7311a34 | 2013-08-21 18:32:49 -0700 | [diff] [blame] | 7 | # -dontobfuscate |
Ying Wang | 3b2bdf1 | 2010-02-01 09:51:23 -0800 | [diff] [blame] | 8 | |
| 9 | # Add this flag in your package's own configuration if it's needed. |
| 10 | #-flattenpackagehierarchy |
| 11 | |
Jared Duke | da0d73e | 2023-02-01 10:27:04 -0800 | [diff] [blame] | 12 | # Keep classes and members with the platform-defined @VisibleForTesting annotation. |
| 13 | -keep @com.android.internal.annotations.VisibleForTesting class * |
| 14 | -keepclassmembers class * { |
| 15 | @com.android.internal.annotations.VisibleForTesting *; |
| 16 | } |
| 17 | |
Yifei Zhang | f0581e6 | 2024-02-09 00:14:25 +0000 | [diff] [blame^] | 18 | # Keep classes and members with platform @TestApi annotations, similar to |
| 19 | # @VisibleForTesting. |
| 20 | -keep @android.annotation.TestApi class * |
| 21 | -keepclassmembers class * { |
| 22 | @android.annotation.TestApi *; |
| 23 | } |
| 24 | |
Jared Duke | da0d73e | 2023-02-01 10:27:04 -0800 | [diff] [blame] | 25 | # Keep classes and members with non-platform @VisibleForTesting annotations, but |
| 26 | # only within platform-defined packages. This avoids keeping external, library-specific |
| 27 | # test code that isn't actually needed for platform testing. |
Jared Duke | 97a9903 | 2022-08-02 16:05:03 -0700 | [diff] [blame] | 28 | # TODO(b/239961360): Migrate away from androidx.annotation.VisibleForTesting |
| 29 | # and com.google.common.annotations.VisibleForTesting use in platform code. |
Jared Duke | da0d73e | 2023-02-01 10:27:04 -0800 | [diff] [blame] | 30 | -keep @**.VisibleForTesting class android.**,com.android.**,com.google.android.** |
| 31 | -keepclassmembers class android.**,com.android.**,com.google.android.** { |
Jared Duke | 97a9903 | 2022-08-02 16:05:03 -0700 | [diff] [blame] | 32 | @**.VisibleForTesting *; |
Ying Wang | 38cdd44 | 2013-05-30 10:45:46 -0700 | [diff] [blame] | 33 | } |
Ying Wang | 3b2bdf1 | 2010-02-01 09:51:23 -0800 | [diff] [blame] | 34 | |
Jared Duke | 7d0c90b | 2022-05-09 18:09:01 -0700 | [diff] [blame] | 35 | # Keep rule for members that are needed solely to keep alive downstream weak |
| 36 | # references, and could otherwise be removed after tree shaking optimizations. |
| 37 | -keepclassmembers,allowaccessmodification,allowobfuscation,allowshrinking class * { |
| 38 | @com.android.internal.annotations.KeepForWeakReference <fields>; |
| 39 | } |
| 40 | |
Jared Duke | 4bd749b | 2021-12-14 15:28:33 -0800 | [diff] [blame] | 41 | # Understand the common @Keep annotation from various Android packages: |
| 42 | # * android.support.annotation |
| 43 | # * androidx.annotation |
| 44 | # * com.android.internal.annotations |
| 45 | -keep class **android**.annotation*.Keep |
Colin Cross | 38b48de | 2019-03-26 09:48:28 -0700 | [diff] [blame] | 46 | |
Jared Duke | 4bd749b | 2021-12-14 15:28:33 -0800 | [diff] [blame] | 47 | -keep @**android**.annotation*.Keep class * { *; } |
Colin Cross | 38b48de | 2019-03-26 09:48:28 -0700 | [diff] [blame] | 48 | |
| 49 | -keepclasseswithmembers class * { |
Jared Duke | 4bd749b | 2021-12-14 15:28:33 -0800 | [diff] [blame] | 50 | @**android**.annotation*.Keep <methods>; |
Colin Cross | 38b48de | 2019-03-26 09:48:28 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | -keepclasseswithmembers class * { |
Jared Duke | 4bd749b | 2021-12-14 15:28:33 -0800 | [diff] [blame] | 54 | @**android**.annotation*.Keep <fields>; |
Colin Cross | 38b48de | 2019-03-26 09:48:28 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | -keepclasseswithmembers class * { |
Jared Duke | 4bd749b | 2021-12-14 15:28:33 -0800 | [diff] [blame] | 58 | @**android**.annotation*.Keep <init>(...); |
Colin Cross | 38b48de | 2019-03-26 09:48:28 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Jared Duke | cb3505c | 2023-09-01 21:27:30 +0000 | [diff] [blame] | 61 | # Keep Dalvik optimization annotations. These annotations are special in that |
| 62 | # 1) we want them preserved for visibility with ART, but 2) they don't have |
| 63 | # RUNTIME retention. These minimal keep rules ensure they're not stripped by R8. |
| 64 | # TODO(b/215417388): Export this rule from the owning library, core-libart, |
| 65 | # via export_proguard_flags_files. |
| 66 | -keepclassmembers,allowshrinking,allowoptimization,allowobfuscation,allowaccessmodification class * { |
| 67 | @dalvik.annotation.optimization.** *; |
| 68 | } |
| 69 | |
Ying Wang | 5745351 | 2013-05-17 10:02:00 -0700 | [diff] [blame] | 70 | -include proguard_basic_keeps.flags |
Yifei Zhang | e6d9964 | 2023-11-02 17:23:07 -0700 | [diff] [blame] | 71 | -include proguard/kotlin.flags |