영상
What is R8 Shrinking?
- Optimizing code for size, in android the dex file.
- Tree Shaking, Optimization, Obfuscating, Reduce Debug Information
- thrid party library를 사용할 때 안쓰는 코드, 그 안에서의 최적화 가능
buildTypes {
release {
minifyEnabled false
}
}
How does the shrinking work?
class JavaHelloWorld {
private void unused() {
System.out.println("Unused");
}
private static void greeting() {
System.out.println("Hello, world!");
}
public static void main(String[] args) {
greeting();
}
}
- Well-known Entry Points : Activities, Services, Content Providers, Broadcast Receivers
- AATP Tool gathers informations from manifest file.
- the developer is responsible for reflection. (need to set custom rule)
- for example add
keep
rules for data classes when using GSON which uses reflection
Class Inlining
- Removes classes that are only used locally
- Builders, Lambdas..
- Escape Analysis (is it locally used?)
- Method Inlining
- Field Access Removal (unnecessary field assignment)
- Instance Removal (remove instance that are not used as result)
Example
private const val databaseName = "hello-db"
fun buildDatabase(context: Context): RoomDatabase {
return Room.databaseBuilder(context, databaseName)
.fallbackToDestructiveMigration()
.build()
}
fun buildDatabase(context: Context): RoomDatabase {
return Room.databaseBuilder(context, "hello-db")
.fallbackToDestructiveMigration()
.build()
}
fun buildDatabase(context: Context): RoomDatabase {
val db = Room.getGeneratedImplementation(...)
db.init(DatabaseConfiguration(context, "hello-db", true, ...))
return db
}