Skip to content

Commit 7c25fc1

Browse files
souvlakiasvaslabs
authored andcommitted
add proguard-common.txt
1 parent 2df8aeb commit 7c25fc1

File tree

4 files changed

+114
-11
lines changed

4 files changed

+114
-11
lines changed

example/thirdparty/android-compose-samples/build.mill

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ object JetLagged extends mill.api.Module {
2121

2222
def androidIsDebug = true
2323

24-
def androidR8ExtraRules = Seq(
25-
"-dontwarn androidx.window.extensions.**",
26-
"-dontwarn androidx.window.sidecar.**"
27-
)
28-
2924
override def androidDebugSettings: T[AndroidBuildTypeSettings] = Task {
3025
AndroidBuildTypeSettings(
3126
isMinifyEnabled = false,
@@ -149,10 +144,6 @@ object JetNews extends mill.api.Module {
149144

150145
def androidIsDebug = true
151146

152-
// FIXME: ideally R8 should compile without erroring, but the app seems to be working
153-
// without some reportedly missing classes.
154-
override def androidR8Args = Seq("--map-diagnostics", "error", "warning")
155-
156147
override def androidDebugSettings: T[AndroidBuildTypeSettings] = Task {
157148
AndroidBuildTypeSettings(
158149
isMinifyEnabled = false,
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# https://android.googlesource.com/platform/tools/base/+/refs/heads/studio-master-dev/build-system/gradle-core/src/main/resources/com/android/build/gradle/proguard-common.txt
2+
-dontusemixedcaseclassnames
3+
-dontskipnonpubliclibraryclasses
4+
-verbose
5+
6+
# Preserve some attributes that may be required for reflection.
7+
-keepattributes *Annotation*,Signature,InnerClasses,EnclosingMethod
8+
9+
-keep public class com.google.vending.licensing.ILicensingService
10+
-keep public class com.android.vending.licensing.ILicensingService
11+
-keep public class com.google.android.vending.licensing.ILicensingService
12+
-dontnote com.android.vending.licensing.ILicensingService
13+
-dontnote com.google.vending.licensing.ILicensingService
14+
-dontnote com.google.android.vending.licensing.ILicensingService
15+
16+
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
17+
-keepclasseswithmembernames,includedescriptorclasses class * {
18+
native <methods>;
19+
}
20+
21+
# Keep setters in Views so that animations can still work.
22+
-keepclassmembers public class * extends android.view.View {
23+
void set*(***);
24+
*** get*();
25+
}
26+
27+
# We want to keep methods in Activity that could be used in the XML attribute onClick.
28+
-keepclassmembers class * extends android.app.Activity {
29+
public void *(android.view.View);
30+
}
31+
32+
# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
33+
-keepclassmembers enum * {
34+
public static **[] values();
35+
public static ** valueOf(java.lang.String);
36+
}
37+
38+
-keepclassmembers class * implements android.os.Parcelable {
39+
public static final ** CREATOR;
40+
}
41+
42+
# Preserve annotated Javascript interface methods.
43+
-keepclassmembers class * {
44+
@android.webkit.JavascriptInterface <methods>;
45+
}
46+
47+
# The support libraries contains references to newer platform versions.
48+
# Don't warn about those in case this app is linking against an older
49+
# platform version. We know about them, and they are safe.
50+
-dontnote android.support.**
51+
-dontnote androidx.**
52+
-dontwarn android.support.**
53+
-dontwarn androidx.**
54+
55+
# This class is deprecated, but remains for backward compatibility.
56+
-dontwarn android.util.FloatMath
57+
58+
# Understand the @Keep support annotation.
59+
-keep class android.support.annotation.Keep
60+
-keep class androidx.annotation.Keep
61+
62+
-keep @android.support.annotation.Keep class * {*;}
63+
-keep @androidx.annotation.Keep class * {*;}
64+
65+
-keepclasseswithmembers class * {
66+
@android.support.annotation.Keep <methods>;
67+
}
68+
69+
-keepclasseswithmembers class * {
70+
@androidx.annotation.Keep <methods>;
71+
}
72+
73+
-keepclasseswithmembers class * {
74+
@android.support.annotation.Keep <fields>;
75+
}
76+
77+
-keepclasseswithmembers class * {
78+
@androidx.annotation.Keep <fields>;
79+
}
80+
81+
-keepclasseswithmembers class * {
82+
@android.support.annotation.Keep <init>(...);
83+
}
84+
85+
-keepclasseswithmembers class * {
86+
@androidx.annotation.Keep <init>(...);
87+
}
88+
89+
# These classes are duplicated between android.jar and org.apache.http.legacy.jar.
90+
-dontnote org.apache.http.**
91+
-dontnote android.net.http.**
92+
93+
# These classes are duplicated between android.jar and core-lambda-stubs.jar.
94+
-dontnote java.lang.invoke.**

libs/androidlib/src/mill/androidlib/AndroidModule.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@ trait AndroidModule extends JavaModule { outer =>
172172
rules
173173
}
174174

175+
// Common Proguard Rules used by AGP
176+
// Source: https://android.googlesource.com/platform/tools/base/+/refs/heads/studio-master-dev/build-system/gradle-core/src/main/resources/com/android/build/gradle/proguard-common.txt
177+
def commonProguardFile: T[PathRef] = Task {
178+
val resource = "proguard-common.txt"
179+
val resourceUrl = getClass.getResourceAsStream(s"/$resource")
180+
val dest = Task.dest / resource
181+
os.write(dest, resourceUrl)
182+
PathRef(dest)
183+
}
184+
175185
def androidProguard: T[PathRef] = Task {
176186
val globalProguardFile = Task.dest / "global-proguard.pro"
177187
os.write(globalProguardFile, "")

libs/androidlib/src/mill/androidlib/AndroidR8AppModule.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,17 @@ trait AndroidR8AppModule extends AndroidAppModule {
234234

235235
r8ArgsBuilder ++= libArgs
236236

237-
// ProGuard configuration files: add our extra rules file and all provided config files.
237+
// ProGuard configuration files: add our extra rules file,
238+
// all provided config files and the common rules.
238239
val pgArgs =
239-
Seq("--pg-conf", androidProguard().path.toString, "--pg-conf", extraRulesFile.toString)
240+
Seq(
241+
"--pg-conf",
242+
androidProguard().path.toString,
243+
"--pg-conf",
244+
extraRulesFile.toString,
245+
"--pg-conf",
246+
commonProguardFile().path.toString
247+
)
240248

241249
r8ArgsBuilder ++= pgArgs
242250

0 commit comments

Comments
 (0)