Skip to content

Commit c170a8f

Browse files
committed
Adds some keep rules for R8 use cases
1 parent cb83bc0 commit c170a8f

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

app/mylibrary/consumer-rules.pro

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
11
# In your library's consumer-proguard-rules.pro
2-
-keep, allowoptimization class * implements com.example.mylibrary.MyWorker {
2+
-keep, allowoptimization class ** implements com.example.mylibrary.MyWorker {
33
<init>();
4+
<methods>;
45
}
6+
-whyareyoukeeping class com.example.mylibrary.MyWorker{
7+
<methods>;
8+
}
9+
510

611
-keepattributes *Annotation*
712

813
-keep @interface com.example.mylibrary.OnEvent
914

10-
-keepclasseswithmembers class * {
15+
-keepclasseswithmembers class **{
16+
<init>();
1117
@com.example.mylibrary.OnEvent <methods>;
1218
}
1319

20+
-keep class com.example.mylibrary.EventBus {
21+
<methods>;
22+
}
23+
24+
-whyareyoukeeping class com.example.mylibrary.EventBus {
25+
<methods>;
26+
}
27+
28+
1429
-keep @interface com.example.mylibrary.ReflectiveExecutor
1530

16-
-keep @com.example.mylibrary.ReflectiveExecutor class *{
31+
-keep @com.example.mylibrary.ReflectiveExecutor class **{
1732
# Keep the public, no-argument constructor so that an instance of the class can be created.
1833
# <init> is the internal name for a constructor.
1934
public <init>();

app/mylibrary/proguard-rules.pro

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@
1919
# If you keep the line number information, uncomment this to
2020
# hide the original source file name.
2121
#-renamesourcefileattribute SourceFile
22+
23+
-keep class com.example.mylibrary.WorkerLoader {
24+
<methods>;
25+
}
26+
27+
-whyareyoukeeping class com.example.mylibrary.WorkerLoader {
28+
<methods>;
29+
}

app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivity.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ class MainActivity : ComponentActivity() {
9595
WorkerLoader.loadAndRun(workerClassName)
9696
val eventBus = EventBus()
9797

98-
val listener = CustomListener()
99-
eventBus.dispatch(listener)
98+
// val listener = CustomListener()
99+
// eventBus.dispatch(listener)
100+
//
101+
// val runner = TaskRunner()
102+
// val task1 = ImportantBackgroundTask()
100103

101-
val runner = TaskRunner()
102-
val task1 = ImportantBackgroundTask()
103104

104-
105-
runner.process(task1) // This will be executed.
105+
// runner.process(task1) // This will be executed.
106106

107107

108108

@@ -219,7 +219,7 @@ data class ThemeSettings(
219219
class CrashTestWorker : MyWorker {
220220
override fun doWork() {
221221
// This log will never appear in a release build because the class won't be found
222-
Log.d("CrashTestWorker", "Important work is being done!")
222+
Log.e("CrashTestWorker", "Important work is being done!")
223223
}
224224
}
225225

@@ -234,6 +234,6 @@ class CustomListener {
234234
@ReflectiveExecutor
235235
class ImportantBackgroundTask {
236236
fun execute() {
237-
Log.e("ImportantBackgroundTask", "Executing the important background task... ✅")
237+
Log.e("ImportantBackgroundTask", "Executing the important background task... ✅")
238238
}
239239
}

0 commit comments

Comments
 (0)