blob: f6b34b8217c23feca3b635e86699a957995f0c8d [file] [log] [blame]
Ying Wang38cdd442013-05-30 10:45:46 -07001# 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 Dukedd1fd792022-10-13 16:30:47 -07005# Preserve line number information for debugging stack traces.
6-keepattributes SourceFile,LineNumberTable
7
Jared Duke3837a942022-07-25 16:49:39 -07008# 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 Duke3f274122023-08-14 21:09:50 +000013# 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 Wang57453512013-05-17 10:02:00 -070019# 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 Dukedf60c0b2022-02-07 10:29:28 -080026-keepclasseswithmembernames,includedescriptorclasses class * {
Ying Wang57453512013-05-17 10:02:00 -070027 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 Wang57453512013-05-17 10:02:00 -070037# 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 Dukecc28b022023-03-28 14:09:31 -070050# Keep all Javascript API methods
51-keepclassmembers class * {
52 @android.webkit.JavascriptInterface <methods>;
53}
54
Ying Wang480a9bb2015-05-11 14:56:20 -070055# Keep Throwable's constructor that takes a String argument.
56-keepclassmembers class * extends java.lang.Throwable {
57 <init>(java.lang.String);
58}
59
Ying Wang57453512013-05-17 10:02:00 -070060# 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 Kennedy62eb51a2014-04-07 11:25:47 -070069# Parcelable CREATORs must be kept for Parcelable functionality
Jared Duke9d27a922022-09-19 16:23:16 -070070-keepclassmembers class * implements android.os.Parcelable {
Scott Kennedy62eb51a2014-04-07 11:25:47 -070071 public static final ** CREATOR;
72}
Ying Wang57453512013-05-17 10:02:00 -070073
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 Wang4f5d0e62015-05-04 19:21:48 -070078#
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 Wangf864d502014-06-17 11:53:31 -070084
Colin Crosse75840f2019-04-11 14:09:37 -070085# 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 Duke3ca564b2022-08-10 15:14:06 -070092# 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 Delmerico4731ab72023-01-31 20:14:18 +000097# TODO(b/242088131): Remove these exemptions after resolving transitive libs
98# dependencies that are provided to R8.
Jared Duke3ca564b2022-08-10 15:14:06 -070099-dontwarn **android**.annotation*.**
Sam Delmerico4731ab72023-01-31 20:14:18 +0000100-dontwarn **com.google.errorprone.annotations.**
101-dontwarn javax.annotation.**
102-dontwarn org.checkerframework.**
103-dontwarn org.jetbrains.annotations.**
Jared Duke3ca564b2022-08-10 15:14:06 -0700104
Ying Wangf864d502014-06-17 11:53:31 -0700105# Less spammy.
106-dontnote
Colin Cross7a9acce2019-08-26 14:22:02 -0700107
108# The lite proto runtime uses reflection to access fields based on the names in
zhidou12fdb342022-07-12 21:20:03 +0000109# 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>; }