From c170a8ffb17d9c45e46887ffbc629ee749f17d76 Mon Sep 17 00:00:00 2001 From: Ajesh R Date: Mon, 4 Aug 2025 09:55:53 +0530 Subject: [PATCH] Adds some keep rules for R8 use cases --- app/mylibrary/consumer-rules.pro | 21 ++++++++++++++++--- app/mylibrary/proguard-rules.pro | 8 +++++++ .../samples/apps/nowinandroid/MainActivity.kt | 16 +++++++------- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/app/mylibrary/consumer-rules.pro b/app/mylibrary/consumer-rules.pro index 2f441f1a0..14f5d6b67 100644 --- a/app/mylibrary/consumer-rules.pro +++ b/app/mylibrary/consumer-rules.pro @@ -1,19 +1,34 @@ # In your library's consumer-proguard-rules.pro --keep, allowoptimization class * implements com.example.mylibrary.MyWorker { +-keep, allowoptimization class ** implements com.example.mylibrary.MyWorker { (); + ; } +-whyareyoukeeping class com.example.mylibrary.MyWorker{ + ; +} + -keepattributes *Annotation* -keep @interface com.example.mylibrary.OnEvent --keepclasseswithmembers class * { +-keepclasseswithmembers class **{ + (); @com.example.mylibrary.OnEvent ; } +-keep class com.example.mylibrary.EventBus { + ; +} + +-whyareyoukeeping class com.example.mylibrary.EventBus { + ; +} + + -keep @interface com.example.mylibrary.ReflectiveExecutor --keep @com.example.mylibrary.ReflectiveExecutor class *{ +-keep @com.example.mylibrary.ReflectiveExecutor class **{ # Keep the public, no-argument constructor so that an instance of the class can be created. # is the internal name for a constructor. public (); diff --git a/app/mylibrary/proguard-rules.pro b/app/mylibrary/proguard-rules.pro index f1b424510..04ac39769 100644 --- a/app/mylibrary/proguard-rules.pro +++ b/app/mylibrary/proguard-rules.pro @@ -19,3 +19,11 @@ # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile + +-keep class com.example.mylibrary.WorkerLoader { + ; +} + +-whyareyoukeeping class com.example.mylibrary.WorkerLoader { + ; +} diff --git a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivity.kt b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivity.kt index 02e767f0a..e166d3559 100644 --- a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivity.kt +++ b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivity.kt @@ -95,14 +95,14 @@ class MainActivity : ComponentActivity() { WorkerLoader.loadAndRun(workerClassName) val eventBus = EventBus() - val listener = CustomListener() - eventBus.dispatch(listener) +// val listener = CustomListener() +// eventBus.dispatch(listener) +// +// val runner = TaskRunner() +// val task1 = ImportantBackgroundTask() - val runner = TaskRunner() - val task1 = ImportantBackgroundTask() - - runner.process(task1) // This will be executed. +// runner.process(task1) // This will be executed. @@ -219,7 +219,7 @@ data class ThemeSettings( class CrashTestWorker : MyWorker { override fun doWork() { // This log will never appear in a release build because the class won't be found - Log.d("CrashTestWorker", "Important work is being done!") + Log.e("CrashTestWorker", "✅ Important work is being done!") } } @@ -234,6 +234,6 @@ class CustomListener { @ReflectiveExecutor class ImportantBackgroundTask { fun execute() { - Log.e("ImportantBackgroundTask", "Executing the important background task... ✅") + Log.e("ImportantBackgroundTask", "✅ Executing the important background task... ✅") } }