Merge remote-tracking branch 'origin/ioc-workshop' into ioc-workshop

ioc-workshop
raystatic 2 days ago
commit c9bd32c4c0
No known key found for this signature in database

@ -0,0 +1,33 @@
# R8 Configuration Analyzer Guide
## Custom R8 Version Setup
To force the Android Gradle Plugin to use a custom version of R8 (like `9.3.+`), you need to update your `settings.gradle.kts` file.
Add the following `buildscript` block at the very top inside `pluginManagement`:
```kotlin
pluginManagement {
buildscript {
repositories {
mavenCentral()
maven {
url = uri("https://storage.googleapis.com/r8-releases/raw")
}
}
dependencies {
classpath("com.android.tools:r8:9.3.7-dev")
}
}
// ... rest of your pluginManagement block
}
```
## Generating the R8 Keep Rule Analyzer Report
To generate the R8 Keep Rule dump, you need to execute a minified build and pass the `dumpkeepradiushtmltodirectory` flag to the JVM arguments running the R8 compiler.
Run the following command in your terminal:
```bash
./gradlew clean assembleBenchmark --no-build-cache -Dcom.android.tools.r8.dumpkeepradiushtmltodirectory=/tmp/r8analysis
```
After the build succeeds, the HTML tree report will be available in the `/tmp/r8analysis` directory.

@ -46,6 +46,7 @@ android {
isMinifyEnabled = providers.gradleProperty("minifyWithR8")
.map(String::toBooleanStrict).getOrElse(true)
applicationIdSuffix = NiaBuildType.RELEASE.applicationIdSuffix
isShrinkResources = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro")

@ -33,7 +33,7 @@ import android.util.Log
class NiaStartupTask : StartupTask {
override fun run() {
Log.d("NiaStartupTask", "Running startup task from mylibrary")
Log.d("NiaStartupTask", "Running startup task from the app")
}
}
@ -54,7 +54,7 @@ class NiaApplication : Application(), ImageLoaderFactory, ComponentCallbacks2 {
// Initialize Sync; the system responsible for keeping data in the app up to date.
Sync.initialize(context = this)
profileVerifierLogger()
TaskRunner.execute(NiaStartupTask::class.java)
TaskRunner.execute("com.google.samples.apps.nowinandroid.NiaStartupTask")
}
override fun newImageLoader(): ImageLoader = imageLoader.get()

@ -82,8 +82,7 @@ internal object NetworkModule {
ImageLoader.Builder(application)
.callFactory { okHttpCallFactory.get() }
.memoryCache(null) // ❌ Bug 1: Memory cache disabled
.diskCache(null)
// ❌ Bug 2: Disk cache disabled
.diskCache(null) // ❌ Bug 2: Disk cache disabled
.allowHardware(false) // ❌ Bug 3: Forces bitmaps onto Java heap
.bitmapConfig(android.graphics.Bitmap.Config.ARGB_8888)
// Assume most content images are versioned urls

Binary file not shown.

Before

Width:  |  Height:  |  Size: 117 KiB

@ -10,12 +10,16 @@ android {
minSdk = 21
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}
buildTypes {
configureEach {
consumerProguardFiles("consumer-rules.pro")
}
release {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"

@ -1,12 +1,13 @@
# Declare that the default constructor is called reflectively.
-keep class * implements com.example.mylibrary.StartupTask { <init>(); }
-keep class * {
public *;
}
-dontwarn com.example.mylibrary.StartupTask
-dontwarn com.example.mylibrary.TaskRunner
-keep class * implements com.example.mylibrary.StartupTask {
<init>();
run();
}
-dontwarn com.example.mylibrary.StartupTask
-dontwarn com.example.mylibrary.TaskRunner
-keep class * {
*;
}

@ -18,4 +18,4 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile

@ -8,10 +8,10 @@ interface StartupTask {
// The library object that loads and executes the task.
object TaskRunner {
fun execute(taskClassFromApp: Class<out StartupTask>) {
// R8 will remove the class specified by this string.
val taskClassInstance =
taskClassFromApp.getDeclaredConstructor().newInstance() as StartupTask
taskClassInstance.run()
fun execute(className: String) {
// R8 won't retain classes specified by this string value at runtime
val taskClass = Class.forName(className)
val task = taskClass.getDeclaredConstructor().newInstance() as StartupTask
task.run()
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save