Ying Wang | 38cdd44 | 2013-05-30 10:45:46 -0700 | [diff] [blame] | 1 | # Some classes in the libraries extend package private classes to chare common functionality |
| 2 | # that isn't explicitly part of the API |
| 3 | -dontskipnonpubliclibraryclasses -dontskipnonpubliclibraryclassmembers |
| 4 | |
Jared Duke | dd1fd79 | 2022-10-13 16:30:47 -0700 | [diff] [blame] | 5 | # Preserve line number information for debugging stack traces. |
| 6 | -keepattributes SourceFile,LineNumberTable |
| 7 | |
Jared Duke | 3837a94 | 2022-07-25 16:49:39 -0700 | [diff] [blame] | 8 | # Annotations are implemented as attributes, so we have to explicitly keep them. |
| 9 | # Keep all runtime-visible annotations like RuntimeVisibleParameterAnnotations |
| 10 | # and RuntimeVisibleTypeAnnotations, as well as associated defaults. |
| 11 | -keepattributes RuntimeVisible*Annotation*,AnnotationDefault |
| 12 | |
Jared Duke | 3f27412 | 2023-08-14 21:09:50 +0000 | [diff] [blame] | 13 | # With R8 full mode, certain attributes are only kept when matched with an |
| 14 | # explicit keep rule for that target, even with a global -keepattributes rule. |
| 15 | # As such, we can add the global keep rule here with minimal cost while |
| 16 | # simplifying incremental development. |
| 17 | -keepattributes Exceptions |
| 18 | |
Ying Wang | 5745351 | 2013-05-17 10:02:00 -0700 | [diff] [blame] | 19 | # For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations |
| 20 | -keepclassmembers enum * { |
| 21 | public static **[] values(); |
| 22 | public static ** valueOf(java.lang.String); |
| 23 | } |
| 24 | |
| 25 | # For native methods, see http://proguard.sourceforge.net/manual/examples.html#native |
Jared Duke | df60c0b | 2022-02-07 10:29:28 -0800 | [diff] [blame] | 26 | -keepclasseswithmembernames,includedescriptorclasses class * { |
Ying Wang | 5745351 | 2013-05-17 10:02:00 -0700 | [diff] [blame] | 27 | native <methods>; |
| 28 | } |
| 29 | |
| 30 | # class$ methods are inserted by some compilers to implement .class construct, |
| 31 | # see http://proguard.sourceforge.net/manual/examples.html#library |
| 32 | -keepclassmembernames class * { |
| 33 | java.lang.Class class$(java.lang.String); |
| 34 | java.lang.Class class$(java.lang.String, boolean); |
| 35 | } |
| 36 | |
Ying Wang | 5745351 | 2013-05-17 10:02:00 -0700 | [diff] [blame] | 37 | # Keep serializable classes and necessary members for serializable classes |
| 38 | # Copied from the ProGuard manual at http://proguard.sourceforge.net. |
| 39 | -keepnames class * implements java.io.Serializable |
| 40 | -keepclassmembers class * implements java.io.Serializable { |
| 41 | static final long serialVersionUID; |
| 42 | private static final java.io.ObjectStreamField[] serialPersistentFields; |
| 43 | !static !transient <fields>; |
| 44 | private void writeObject(java.io.ObjectOutputStream); |
| 45 | private void readObject(java.io.ObjectInputStream); |
| 46 | java.lang.Object writeReplace(); |
| 47 | java.lang.Object readResolve(); |
| 48 | } |
| 49 | |
Jared Duke | cc28b02 | 2023-03-28 14:09:31 -0700 | [diff] [blame] | 50 | # Keep all Javascript API methods |
| 51 | -keepclassmembers class * { |
| 52 | @android.webkit.JavascriptInterface <methods>; |
| 53 | } |
| 54 | |
Ying Wang | 480a9bb | 2015-05-11 14:56:20 -0700 | [diff] [blame] | 55 | # Keep Throwable's constructor that takes a String argument. |
| 56 | -keepclassmembers class * extends java.lang.Throwable { |
| 57 | <init>(java.lang.String); |
| 58 | } |
| 59 | |
Ying Wang | 5745351 | 2013-05-17 10:02:00 -0700 | [diff] [blame] | 60 | # Please specify classes to be kept explicitly in your package's configuration. |
| 61 | # -keep class * extends android.app.Activity |
| 62 | # -keep class * extends android.view.View |
| 63 | # -keep class * extends android.app.Service |
| 64 | # -keep class * extends android.content.BroadcastReceiver |
| 65 | # -keep class * extends android.content.ContentProvider |
| 66 | # -keep class * extends android.preference.Preference |
| 67 | # -keep class * extends android.app.BackupAgent |
| 68 | |
Scott Kennedy | 62eb51a | 2014-04-07 11:25:47 -0700 | [diff] [blame] | 69 | # Parcelable CREATORs must be kept for Parcelable functionality |
Jared Duke | 9d27a92 | 2022-09-19 16:23:16 -0700 | [diff] [blame] | 70 | -keepclassmembers class * implements android.os.Parcelable { |
Scott Kennedy | 62eb51a | 2014-04-07 11:25:47 -0700 | [diff] [blame] | 71 | public static final ** CREATOR; |
| 72 | } |
Ying Wang | 5745351 | 2013-05-17 10:02:00 -0700 | [diff] [blame] | 73 | |
| 74 | # The support library contains references to newer platform versions. |
| 75 | # Don't warn about those in case this app is linking against an older |
| 76 | # platform version. We know about them, and they are safe. |
| 77 | # See proguard-android.txt in the SDK package. |
Ying Wang | 4f5d0e6 | 2015-05-04 19:21:48 -0700 | [diff] [blame] | 78 | # |
| 79 | # DO NOT USE THIS: We figured it's dangerous to blindly ignore all support library warnings. |
| 80 | # ProGuard may strip members of subclass of unknown super classes, in case an app is linking against |
| 81 | # LOCAL_SDK_VERSION lower than the support library's LOCAL_SDK_VERSION. |
| 82 | # See bug/20658265. |
| 83 | # -dontwarn android.support.** |
Ying Wang | f864d50 | 2014-06-17 11:53:31 -0700 | [diff] [blame] | 84 | |
Colin Cross | e75840f | 2019-04-11 14:09:37 -0700 | [diff] [blame] | 85 | # From https://github.com/google/guava/wiki/UsingProGuardWithGuava |
| 86 | # Striped64, LittleEndianByteArray, UnsignedBytes, AbstractFuture |
| 87 | -dontwarn sun.misc.Unsafe |
| 88 | # Futures.getChecked (which often won't work with Proguard anyway) uses this. It |
| 89 | # has a fallback, but again, don't use Futures.getChecked on Android regardless. |
| 90 | -dontwarn java.lang.ClassValue |
| 91 | |
Jared Duke | 3ca564b | 2022-08-10 15:14:06 -0700 | [diff] [blame] | 92 | # Ignore missing annotation references for various support libraries. |
| 93 | # While this is not ideal, it should be relatively safe given that |
| 94 | # 1) runtime-visible annotations will still be kept, and 2) compile-time |
| 95 | # annotations are stripped by R8 anyway. |
| 96 | # Note: The ** prefix is used to accommodate jarjar repackaging. |
Sam Delmerico | 4731ab7 | 2023-01-31 20:14:18 +0000 | [diff] [blame] | 97 | # TODO(b/242088131): Remove these exemptions after resolving transitive libs |
| 98 | # dependencies that are provided to R8. |
Jared Duke | 3ca564b | 2022-08-10 15:14:06 -0700 | [diff] [blame] | 99 | -dontwarn **android**.annotation*.** |
Sam Delmerico | 4731ab7 | 2023-01-31 20:14:18 +0000 | [diff] [blame] | 100 | -dontwarn **com.google.errorprone.annotations.** |
| 101 | -dontwarn javax.annotation.** |
| 102 | -dontwarn org.checkerframework.** |
| 103 | -dontwarn org.jetbrains.annotations.** |
Jared Duke | 3ca564b | 2022-08-10 15:14:06 -0700 | [diff] [blame] | 104 | |
Ying Wang | f864d50 | 2014-06-17 11:53:31 -0700 | [diff] [blame] | 105 | # Less spammy. |
| 106 | -dontnote |
Colin Cross | 7a9acce | 2019-08-26 14:22:02 -0700 | [diff] [blame] | 107 | |
| 108 | # The lite proto runtime uses reflection to access fields based on the names in |
zhidou | 12fdb34 | 2022-07-12 21:20:03 +0000 | [diff] [blame] | 109 | # the schema, keep all the fields. Wildcard is used to apply the rule to classes |
| 110 | # that have been renamed with jarjar. |
| 111 | -keepclassmembers class * extends **.protobuf.MessageLite { <fields>; } |