Adds some keep rules for R8 use cases

ajesh/r8-usecases
Ajesh R 2 months ago
parent cb83bc0ee7
commit c170a8ffb1

@ -1,19 +1,34 @@
# In your library's consumer-proguard-rules.pro # In your library's consumer-proguard-rules.pro
-keep, allowoptimization class * implements com.example.mylibrary.MyWorker { -keep, allowoptimization class ** implements com.example.mylibrary.MyWorker {
<init>(); <init>();
<methods>;
} }
-whyareyoukeeping class com.example.mylibrary.MyWorker{
<methods>;
}
-keepattributes *Annotation* -keepattributes *Annotation*
-keep @interface com.example.mylibrary.OnEvent -keep @interface com.example.mylibrary.OnEvent
-keepclasseswithmembers class * { -keepclasseswithmembers class **{
<init>();
@com.example.mylibrary.OnEvent <methods>; @com.example.mylibrary.OnEvent <methods>;
} }
-keep class com.example.mylibrary.EventBus {
<methods>;
}
-whyareyoukeeping class com.example.mylibrary.EventBus {
<methods>;
}
-keep @interface com.example.mylibrary.ReflectiveExecutor -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. # Keep the public, no-argument constructor so that an instance of the class can be created.
# <init> is the internal name for a constructor. # <init> is the internal name for a constructor.
public <init>(); public <init>();

@ -19,3 +19,11 @@
# If you keep the line number information, uncomment this to # If you keep the line number information, uncomment this to
# hide the original source file name. # hide the original source file name.
#-renamesourcefileattribute SourceFile #-renamesourcefileattribute SourceFile
-keep class com.example.mylibrary.WorkerLoader {
<methods>;
}
-whyareyoukeeping class com.example.mylibrary.WorkerLoader {
<methods>;
}

@ -95,14 +95,14 @@ class MainActivity : ComponentActivity() {
WorkerLoader.loadAndRun(workerClassName) WorkerLoader.loadAndRun(workerClassName)
val eventBus = EventBus() val eventBus = EventBus()
val listener = CustomListener() // val listener = CustomListener()
eventBus.dispatch(listener) // 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 { class CrashTestWorker : MyWorker {
override fun doWork() { override fun doWork() {
// This log will never appear in a release build because the class won't be found // 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 @ReflectiveExecutor
class ImportantBackgroundTask { class ImportantBackgroundTask {
fun execute() { fun execute() {
Log.e("ImportantBackgroundTask", "Executing the important background task... ✅") Log.e("ImportantBackgroundTask", "Executing the important background task... ✅")
} }
} }

Loading…
Cancel
Save