SlideShare a Scribd company logo
Fighting application size
with ProGuard and beyond
Eric Lafortune
Developer of ProGuard and DexGuard
Technical director at Saikoa
www.saikoa.com
Applications
Dalvik
bytecode
Resources Assets
Native
code
Renderscript
code
App
Dalvik
bytecode
Resources Assets
Native
code
Renderscript
code
Technical constraints
App
Google Play Store: max 50 MB
Froyo/Gingerbread: 5 MB LinearAlloc buffer
Dex format: max 65536 method IDs
Android build process
Android build process
Application
Java bytecode
Libraries
Java bytecode
Dex Dalvik bytecode
Javac
Application
Java source
Libraries
Java bytecode
XML resources
Assets Assets
Compiled
XML resourcesAapt
Compress media
●
Images: JPEG (lossy)
●
Images: PNG
●
Audio: AAC
●
Video: H264 AVC
aapt crunch -S input_dir -C output_diraapt crunch -S input_dir -C output_dir
Remove unused resources
●
Lint (Android SDK)
●
android-resource-remover (Philipp Berner)
●
android-unused-resources (S. Kennedy)
●
Gradle (Android SDK)
gradle lintgradle lint
android {
buildTypes {
release {
minifyEnabled true
shrinkResources true
}
}
}
android {
buildTypes {
release {
minifyEnabled true
shrinkResources true
}
}
}
Splitting apk files
Splitting apk files
Application
Java bytecode
Libraries
Java bytecode
Dex Dalvik bytecode
Javac
Application
Java source
Libraries
Java bytecode
XML resources
Assets
Assets
Compiled
XML resources
Aapt
Dalvik bytecode
Assets
Compiled
XML resources
Splitting apk files
●
Different variants in Gradle:
android {
...
productFlavors {
flavor1 {
ignoreAssetsPattern '!*_large.png'
assets.srcDirs = ['assets1']
res.srcDirs = ['res1']
}
flavor2 {
ignoreAssetsPattern '!*_small.png'
assets.srcDirs = ['assets2']
res.srcDirs = ['res2']
}
}
}
android {
...
productFlavors {
flavor1 {
ignoreAssetsPattern '!*_large.png'
assets.srcDirs = ['assets1']
res.srcDirs = ['res1']
}
flavor2 {
ignoreAssetsPattern '!*_small.png'
assets.srcDirs = ['assets2']
res.srcDirs = ['res2']
}
}
}
Splitting apk files
●
Splits in Gradle:
android {
...
splits {
density {
enable true
reset()
include 'mdpi', 'hdpi', 'xhdpi'
}
abi {
enable true
reset()
include 'armeabi-v7a', 'x86', 'mips'
}
}
}
android {
...
splits {
density {
enable true
reset()
include 'mdpi', 'hdpi', 'xhdpi'
}
abi {
enable true
reset()
include 'armeabi-v7a', 'x86', 'mips'
}
}
}
Code size
Code size
Application
Java bytecode
Libraries
Java bytecode
Dex Dalvik bytecode
Javac
Application
Java source
Libraries
Java bytecode
XML resources
Assets Assets
Compiled
XML resourcesAapt
java.lang.IllegalArgumentException:
method ID not in [0, 0xffff]: 65536
java.lang.IllegalArgumentException:
method ID not in [0, 0xffff]: 65536
Dex file
...
Strings
Types
Prototypes
Field IDs
Method IDs
Class definitions
Method IDs
#0: Accounts . <init>(.....)
#1: AccountManager . get(......)
#2: AccountManager . …..
#3: …..
#4: …..
...
...
...
...
...
...
...
...
...
...
...
...
...
...
#65535: …..
ProGuard
Shrink
Android
runtime
Optimize Obfuscate
Android
runtime
Libraries
Application
code
Processed
code
ProGuard
Application
Java bytecode
ProGuard
Libraries
Java bytecode
Processed
Java bytecode Dex
Javac
Application
Java source
Libraries
Java bytecode
XML resources
Assets Assets
Compiled
XML resourcesAapt
Dalvik bytecode
-keepclassmembers,allowobfuscation class * {
@dagger.** <fields>;
@dagger.** <methods>;
}
-keep class **$$ModuleAdapter
-keep class **$$InjectAdapter
-keep class **$$StaticInjection
-keep class com.example.DemoModule
-keep class com.example.AndroidModule
-keep class com.example.HomeActivity
-keepnames class dagger.Lazy
-keepclassmembers,allowobfuscation class * {
@dagger.** <fields>;
@dagger.** <methods>;
}
-keep class **$$ModuleAdapter
-keep class **$$InjectAdapter
-keep class **$$StaticInjection
-keep class com.example.DemoModule
-keep class com.example.AndroidModule
-keep class com.example.HomeActivity
-keepnames class dagger.Lazy
Example configuration: Dagger
Generated classes
Corresponding base classes
Libraries
Library Method IDs
Google Play Services 6.0 23,607
Guava 15.0 14,495
Yahoo Flurry Ads 4.1.0 8,511
ActionBarSherlock 4.4.0 4,300
RoboGuice 2.0 3,787
Facebook 3.5.2 3,166
Yahoo Flurry Analytics 4.1.0 1,148
Scala Core 2.11.2 50,786
ProGuard on libraries
ProGuard
Library
Java bytecode
Processed library
Java bytecode
Shrink Ads library
-injars google-play-services.jar
-outjars google-play-services-ads.jar
-libraryjars android-sdk/extras/android/support/v4/android-support-v4.jar
-libraryjars android-sdk/platforms/android-20/android.jar
-dontoptimize
-dontobfuscate
-dontwarn com.google.**.R
-dontwarn com.google.**.R$*
-dontnote
-keep public class com.google.android.gms.ads.** {
public protected *;
}
-keep class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
java.lang.String NULL;
}
-injars google-play-services.jar
-outjars google-play-services-ads.jar
-libraryjars android-sdk/extras/android/support/v4/android-support-v4.jar
-libraryjars android-sdk/platforms/android-20/android.jar
-dontoptimize
-dontobfuscate
-dontwarn com.google.**.R
-dontwarn com.google.**.R$*
-dontnote
-keep public class com.google.android.gms.ads.** {
public protected *;
}
-keep class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
java.lang.String NULL;
}
proguard @ configuration.txtproguard @ configuration.txt
Command line:
configuration.txt
Shrink Ads library
Before After Reduction
Size 3.3 M 578 K 83 %
Classes 3294 497 85 %
Method IDs 23607 3751 84 %
ProGuard
Google Play
Services
library
Ads library
Shrink Maps library
-injars google-play-services.jar
-outjars google-play-services-maps.jar
-libraryjars android-sdk/extras/android/support/v4/android-support-v4.jar
-libraryjars android-sdk/platforms/android-20/android.jar
-dontoptimize
-dontobfuscate
-dontwarn com.google.**.R
-dontwarn com.google.**.R$*
-dontnote
-keep public class com.google.android.gms.maps.**,
com.google.android.gms.common.**,
com.google.android.gms.location.** {
public protected *;
}
-keep class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
java.lang.String NULL;
}
-injars google-play-services.jar
-outjars google-play-services-maps.jar
-libraryjars android-sdk/extras/android/support/v4/android-support-v4.jar
-libraryjars android-sdk/platforms/android-20/android.jar
-dontoptimize
-dontobfuscate
-dontwarn com.google.**.R
-dontwarn com.google.**.R$*
-dontnote
-keep public class com.google.android.gms.maps.**,
com.google.android.gms.common.**,
com.google.android.gms.location.** {
public protected *;
}
-keep class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
java.lang.String NULL;
}
proguard @ configuration.txtproguard @ configuration.txt
Shrink Maps library
Before After Reduction
Size 3.3 M 583 K 82 %
Classes 3294 546 83 %
Method IDs 23607 4891 79 %
ProGuard
Google Play
Services
library
Maps library
Splitting dex files
Main dex file
Secondary
dex file
Build-time Run-time
Splitting dex files
Application
Java bytecode
Libraries
Java bytecode
Dex
Main
Dalvik bytecodeJavac
Application
Java source
Libraries
Java bytecode
XML resources
Assets Assets
Compiled
XML resourcesAapt
Secondary
Dalvik bytecode
Dex
Dex splitting: tools
●
secondary-dex-gradle (Mohit Kanwal)
●
Dex 65536 (Mmin18)
●
DexGuard (Saikoa)
●
multiDex (Android Gradle plugin 0.14)
Dex splitting: secondary-dex-gradle
●
ApplicationProject
LibraryProject
●
settings.gradle
●
AndroidManifest.xml
●
AppProject/src/com/example/App.java
AppProject/src/com/example/SecondaryDex.java
AppProject/src/com/example/FrameworkHack.java
include ':ApplicationProject', ':LibraryProject'include ':ApplicationProject', ':LibraryProject'
<application
android:name="com.example.App"
... >
<application
android:name="com.example.App"
... >
Dex splitting: secondary-dex-gradle
Advantages:
●
It works!
Disadvantages:
●
Split project
●
No references library application→
●
Dex classpath hack
Dex splitting: Dex 65536
●
libs/google-play-services.jar (for example)
●
custom_rules.xml
●
AndroidManifest.xml
●
src/com/example/App.java
...
<pathtool
libs="libs/google-play-services.jar"
... />
...
...
<pathtool
libs="libs/google-play-services.jar"
... />
...
<application
android:name="com.example.App"
... >
<application
android:name="com.example.App"
... >
new DexClassLoader(dexFile.getAbsolutePath(),
dexOpt.getAbsolutePath(),
nativeLibraryDir,
classLoader.getParent());
new DexClassLoader(dexFile.getAbsolutePath(),
dexOpt.getAbsolutePath(),
nativeLibraryDir,
classLoader.getParent());
Dex splitting: Dex 65536
Advantages:
●
It works!
Disadvantages:
●
Only for library jars
●
Dex classloader hack
Dex splitting: DexGuard
●
Gradle, Ant, Eclipse, Maven, Android Studio,...
●
dexguard-project.txt
-splitdexfile com.google.**
-splitdexfile !com.facebook.samples.**, com.facebook.**
-splitdexfile com.google.**
-splitdexfile !com.facebook.samples.**, com.facebook.**
Dex splitting: DexGuard
Advantages:
●
Transparent
●
Flexible
●
Lazy loading
Disadvantages:
●
Reflection
Dex splitting: multiDex
Android 5.0 loads classes2.dex, classes3.dex, etc.
●
build.gradle
●
AndroidManifest.xml (for legacy platforms)
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
android {
...
defaultConfig {
multiDexEnabled true
}
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
android {
...
defaultConfig {
multiDexEnabled true
}
}
<application
android:name="android.support.multidex.MultiDexApplication"
... >
<application
android:name="android.support.multidex.MultiDexApplication"
... >
Dex splitting: Android 5.0
Advantages:
●
Latest standard
Disadvantages:
●
Eager loading
Summary
Resources and assets:
– Compress
– Trim
– Split apk
Bytecode:
– Shrink libraries
– Shrink application
– Split dex file
Further reading
●
“Custom Class Loading in Dalvik”, Fred Chung, Google
http://android-developers.blogspot.com/2011/07/custom-class-loading-in-dalvik.html
●
“Play Services 5.0 Is A Monolith Abomination”, Jake Wharton
http://jakewharton.com/play-services-is-a-monolith/
●
“DEX Sky’s the limit? No, 65K methods is”, Sebastiano Gottardo
https://medium.com/@rotxed/dex-skys-the-limit-no-65k-methods-is-28e6cb40cf71
●
“Multi-dex support”, Xavier Ducrohet
https://plus.google.com/+XavierDucrohet/posts/1FnzwdcBnyC
●
“Under the Hood: Dalvik patch for Facebook for Android”, David Reiss
https://www.facebook.com/notes/facebook-engineering/under-the-hood-dalvik-patch-for-facebook-for-android/10151345597798920
●
“Remove unused resources”, Tor Norbye
https://plus.google.com/+TorNorbye/posts/eHsStybrrBf
●
“Tips for reducing APK file size”, David Karlsson, Sony
http://developer.sonymobile.com/2012/01/31/tips-for-reducing-apk-file-size/
Software tools
●
android-resource-remover, Philipp Berner, KeepSafe
https://github.com/KeepSafe/android-resource-remover
●
android-unused-resources, S. Kennedy
https://code.google.com/p/android-unused-resources/
●
secondary-dex-gradle, Mohit Kanwal
https://github.com/creativepsyco/secondary-dex-gradle
●
Dex 65536, Mmin18
https://github.com/mmin18/Dex65536
●
ProGuard
http://proguard.sourceforge.net/
●
DexGuard
http://www.saikoa.com/dexguard
Questions?
Open source
Java bytecode
ProGuard
Saikoa
DexGuard
Dalvik bytecode
Shrinking
Optimization

More Related Content

What's hot

Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDKEric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
GuardSquare
 
OWF12/PAUG Conf Days Pro guard optimizer and obfuscator for android, eric l...
OWF12/PAUG Conf Days Pro guard   optimizer and obfuscator for android, eric l...OWF12/PAUG Conf Days Pro guard   optimizer and obfuscator for android, eric l...
OWF12/PAUG Conf Days Pro guard optimizer and obfuscator for android, eric l...Paris Open Source Summit
 
IOS debugging
IOS debuggingIOS debugging
IOS debugging
Dawid Planeta
 
Fernando Arnaboldi - Exposing Hidden Exploitable Behaviors Using Extended Dif...
Fernando Arnaboldi - Exposing Hidden Exploitable Behaviors Using Extended Dif...Fernando Arnaboldi - Exposing Hidden Exploitable Behaviors Using Extended Dif...
Fernando Arnaboldi - Exposing Hidden Exploitable Behaviors Using Extended Dif...
Codemotion
 
The Ring programming language version 1.2 book - Part 80 of 84
The Ring programming language version 1.2 book - Part 80 of 84The Ring programming language version 1.2 book - Part 80 of 84
The Ring programming language version 1.2 book - Part 80 of 84
Mahmoud Samir Fayed
 
soscon2018 - Tracing for fun and profit
soscon2018 - Tracing for fun and profitsoscon2018 - Tracing for fun and profit
soscon2018 - Tracing for fun and profit
hanbeom Park
 
The Ring programming language version 1.2 book - Part 84 of 84
The Ring programming language version 1.2 book - Part 84 of 84The Ring programming language version 1.2 book - Part 84 of 84
The Ring programming language version 1.2 book - Part 84 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 83 of 84
The Ring programming language version 1.2 book - Part 83 of 84The Ring programming language version 1.2 book - Part 83 of 84
The Ring programming language version 1.2 book - Part 83 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 82 of 84
The Ring programming language version 1.2 book - Part 82 of 84The Ring programming language version 1.2 book - Part 82 of 84
The Ring programming language version 1.2 book - Part 82 of 84
Mahmoud Samir Fayed
 
Top 20 java programming interview questions for sdet
Top 20 java programming interview questions for sdetTop 20 java programming interview questions for sdet
Top 20 java programming interview questions for sdet
DevLabs Alliance
 
groovy & grails - lecture 7
groovy & grails - lecture 7groovy & grails - lecture 7
groovy & grails - lecture 7
Alexandre Masselot
 
Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"Victor_Cr
 
The Anatomy of an Exploit (NDC TechTown 2019)
The Anatomy of an Exploit (NDC TechTown 2019)The Anatomy of an Exploit (NDC TechTown 2019)
The Anatomy of an Exploit (NDC TechTown 2019)
Patricia Aas
 
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
kwatch
 
ZooKeeper Recipes and Solutions
ZooKeeper Recipes and SolutionsZooKeeper Recipes and Solutions
ZooKeeper Recipes and Solutions
Jeff Smith
 
The Ring programming language version 1.4 book - Part 3 of 30
The Ring programming language version 1.4 book - Part 3 of 30The Ring programming language version 1.4 book - Part 3 of 30
The Ring programming language version 1.4 book - Part 3 of 30
Mahmoud Samir Fayed
 
Tools and Techniques for Understanding Threading Behavior in Android
Tools and Techniques for Understanding Threading Behavior in AndroidTools and Techniques for Understanding Threading Behavior in Android
Tools and Techniques for Understanding Threading Behavior in Android
Intel® Software
 
2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertagMarcel Bruch
 
OWASP Poland Day 2018 - Pedro Fortuna - Are your Java Script based protection...
OWASP Poland Day 2018 - Pedro Fortuna - Are your Java Script based protection...OWASP Poland Day 2018 - Pedro Fortuna - Are your Java Script based protection...
OWASP Poland Day 2018 - Pedro Fortuna - Are your Java Script based protection...
OWASP
 

What's hot (19)

Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDKEric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
 
OWF12/PAUG Conf Days Pro guard optimizer and obfuscator for android, eric l...
OWF12/PAUG Conf Days Pro guard   optimizer and obfuscator for android, eric l...OWF12/PAUG Conf Days Pro guard   optimizer and obfuscator for android, eric l...
OWF12/PAUG Conf Days Pro guard optimizer and obfuscator for android, eric l...
 
IOS debugging
IOS debuggingIOS debugging
IOS debugging
 
Fernando Arnaboldi - Exposing Hidden Exploitable Behaviors Using Extended Dif...
Fernando Arnaboldi - Exposing Hidden Exploitable Behaviors Using Extended Dif...Fernando Arnaboldi - Exposing Hidden Exploitable Behaviors Using Extended Dif...
Fernando Arnaboldi - Exposing Hidden Exploitable Behaviors Using Extended Dif...
 
The Ring programming language version 1.2 book - Part 80 of 84
The Ring programming language version 1.2 book - Part 80 of 84The Ring programming language version 1.2 book - Part 80 of 84
The Ring programming language version 1.2 book - Part 80 of 84
 
soscon2018 - Tracing for fun and profit
soscon2018 - Tracing for fun and profitsoscon2018 - Tracing for fun and profit
soscon2018 - Tracing for fun and profit
 
The Ring programming language version 1.2 book - Part 84 of 84
The Ring programming language version 1.2 book - Part 84 of 84The Ring programming language version 1.2 book - Part 84 of 84
The Ring programming language version 1.2 book - Part 84 of 84
 
The Ring programming language version 1.2 book - Part 83 of 84
The Ring programming language version 1.2 book - Part 83 of 84The Ring programming language version 1.2 book - Part 83 of 84
The Ring programming language version 1.2 book - Part 83 of 84
 
The Ring programming language version 1.2 book - Part 82 of 84
The Ring programming language version 1.2 book - Part 82 of 84The Ring programming language version 1.2 book - Part 82 of 84
The Ring programming language version 1.2 book - Part 82 of 84
 
Top 20 java programming interview questions for sdet
Top 20 java programming interview questions for sdetTop 20 java programming interview questions for sdet
Top 20 java programming interview questions for sdet
 
groovy & grails - lecture 7
groovy & grails - lecture 7groovy & grails - lecture 7
groovy & grails - lecture 7
 
Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"
 
The Anatomy of an Exploit (NDC TechTown 2019)
The Anatomy of an Exploit (NDC TechTown 2019)The Anatomy of an Exploit (NDC TechTown 2019)
The Anatomy of an Exploit (NDC TechTown 2019)
 
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
 
ZooKeeper Recipes and Solutions
ZooKeeper Recipes and SolutionsZooKeeper Recipes and Solutions
ZooKeeper Recipes and Solutions
 
The Ring programming language version 1.4 book - Part 3 of 30
The Ring programming language version 1.4 book - Part 3 of 30The Ring programming language version 1.4 book - Part 3 of 30
The Ring programming language version 1.4 book - Part 3 of 30
 
Tools and Techniques for Understanding Threading Behavior in Android
Tools and Techniques for Understanding Threading Behavior in AndroidTools and Techniques for Understanding Threading Behavior in Android
Tools and Techniques for Understanding Threading Behavior in Android
 
2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag
 
OWASP Poland Day 2018 - Pedro Fortuna - Are your Java Script based protection...
OWASP Poland Day 2018 - Pedro Fortuna - Are your Java Script based protection...OWASP Poland Day 2018 - Pedro Fortuna - Are your Java Script based protection...
OWASP Poland Day 2018 - Pedro Fortuna - Are your Java Script based protection...
 

Similar to Eric Lafortune - Fighting application size with ProGuard and beyond

Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011
pundiramit
 
Kandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalKandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalNAVER D2
 
Android 101 - Introduction to Android Development
Android 101 - Introduction to Android DevelopmentAndroid 101 - Introduction to Android Development
Android 101 - Introduction to Android Development
Andy Scherzinger
 
Steelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android ApplicationsSteelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android Applications
Tom Keetch
 
Proguard android
Proguard androidProguard android
Proguard android
Bhavya Rattan
 
Null mumbai-Android-Insecure-Data-Storage-Exploitation
Null mumbai-Android-Insecure-Data-Storage-ExploitationNull mumbai-Android-Insecure-Data-Storage-Exploitation
Null mumbai-Android-Insecure-Data-Storage-Exploitation
Nitesh Malviya
 
Core Android
Core AndroidCore Android
Core Android
Dominik Helleberg
 
Getting Native with NDK
Getting Native with NDKGetting Native with NDK
Getting Native with NDK
ナム-Nam Nguyễn
 
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Patrick Chanezon
 
Android Logging System
Android Logging SystemAndroid Logging System
Android Logging System
William Lee
 
Writing Android Libraries
Writing Android LibrariesWriting Android Libraries
Writing Android Libraries
emanuelez
 
Groovy In the Cloud
Groovy In the CloudGroovy In the Cloud
Groovy In the Cloud
Jim Driscoll
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new Platforms
Linaro
 
Ese 2008 RTSC Draft1
Ese 2008 RTSC Draft1Ese 2008 RTSC Draft1
Ese 2008 RTSC Draft1
drusso
 
Porting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsPorting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsMarcelo Pinheiro
 
AndroidX Google Extended I/O BKK 2018
AndroidX Google Extended I/O BKK 2018 AndroidX Google Extended I/O BKK 2018
AndroidX Google Extended I/O BKK 2018
Theerasan Tonthongkam
 
Android Internals
Android InternalsAndroid Internals
Android Internals
Opersys inc.
 
Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014
Paris Android User Group
 
Reverse Engineering 안드로이드 학습
Reverse Engineering 안드로이드 학습Reverse Engineering 안드로이드 학습
Reverse Engineering 안드로이드 학습
Sungju Jin
 
Troubleshooting real production problems
Troubleshooting real production problemsTroubleshooting real production problems
Troubleshooting real production problems
Tier1 app
 

Similar to Eric Lafortune - Fighting application size with ProGuard and beyond (20)

Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011
 
Kandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalKandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_final
 
Android 101 - Introduction to Android Development
Android 101 - Introduction to Android DevelopmentAndroid 101 - Introduction to Android Development
Android 101 - Introduction to Android Development
 
Steelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android ApplicationsSteelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android Applications
 
Proguard android
Proguard androidProguard android
Proguard android
 
Null mumbai-Android-Insecure-Data-Storage-Exploitation
Null mumbai-Android-Insecure-Data-Storage-ExploitationNull mumbai-Android-Insecure-Data-Storage-Exploitation
Null mumbai-Android-Insecure-Data-Storage-Exploitation
 
Core Android
Core AndroidCore Android
Core Android
 
Getting Native with NDK
Getting Native with NDKGetting Native with NDK
Getting Native with NDK
 
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
 
Android Logging System
Android Logging SystemAndroid Logging System
Android Logging System
 
Writing Android Libraries
Writing Android LibrariesWriting Android Libraries
Writing Android Libraries
 
Groovy In the Cloud
Groovy In the CloudGroovy In the Cloud
Groovy In the Cloud
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new Platforms
 
Ese 2008 RTSC Draft1
Ese 2008 RTSC Draft1Ese 2008 RTSC Draft1
Ese 2008 RTSC Draft1
 
Porting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsPorting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability Systems
 
AndroidX Google Extended I/O BKK 2018
AndroidX Google Extended I/O BKK 2018 AndroidX Google Extended I/O BKK 2018
AndroidX Google Extended I/O BKK 2018
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014
 
Reverse Engineering 안드로이드 학습
Reverse Engineering 안드로이드 학습Reverse Engineering 안드로이드 학습
Reverse Engineering 안드로이드 학습
 
Troubleshooting real production problems
Troubleshooting real production problemsTroubleshooting real production problems
Troubleshooting real production problems
 

Recently uploaded

Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 

Recently uploaded (20)

Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 

Eric Lafortune - Fighting application size with ProGuard and beyond

  • 1. Fighting application size with ProGuard and beyond Eric Lafortune Developer of ProGuard and DexGuard Technical director at Saikoa www.saikoa.com
  • 3. Dalvik bytecode Resources Assets Native code Renderscript code Technical constraints App Google Play Store: max 50 MB Froyo/Gingerbread: 5 MB LinearAlloc buffer Dex format: max 65536 method IDs
  • 5. Android build process Application Java bytecode Libraries Java bytecode Dex Dalvik bytecode Javac Application Java source Libraries Java bytecode XML resources Assets Assets Compiled XML resourcesAapt
  • 6. Compress media ● Images: JPEG (lossy) ● Images: PNG ● Audio: AAC ● Video: H264 AVC aapt crunch -S input_dir -C output_diraapt crunch -S input_dir -C output_dir
  • 7. Remove unused resources ● Lint (Android SDK) ● android-resource-remover (Philipp Berner) ● android-unused-resources (S. Kennedy) ● Gradle (Android SDK) gradle lintgradle lint android { buildTypes { release { minifyEnabled true shrinkResources true } } } android { buildTypes { release { minifyEnabled true shrinkResources true } } }
  • 9. Splitting apk files Application Java bytecode Libraries Java bytecode Dex Dalvik bytecode Javac Application Java source Libraries Java bytecode XML resources Assets Assets Compiled XML resources Aapt Dalvik bytecode Assets Compiled XML resources
  • 10. Splitting apk files ● Different variants in Gradle: android { ... productFlavors { flavor1 { ignoreAssetsPattern '!*_large.png' assets.srcDirs = ['assets1'] res.srcDirs = ['res1'] } flavor2 { ignoreAssetsPattern '!*_small.png' assets.srcDirs = ['assets2'] res.srcDirs = ['res2'] } } } android { ... productFlavors { flavor1 { ignoreAssetsPattern '!*_large.png' assets.srcDirs = ['assets1'] res.srcDirs = ['res1'] } flavor2 { ignoreAssetsPattern '!*_small.png' assets.srcDirs = ['assets2'] res.srcDirs = ['res2'] } } }
  • 11. Splitting apk files ● Splits in Gradle: android { ... splits { density { enable true reset() include 'mdpi', 'hdpi', 'xhdpi' } abi { enable true reset() include 'armeabi-v7a', 'x86', 'mips' } } } android { ... splits { density { enable true reset() include 'mdpi', 'hdpi', 'xhdpi' } abi { enable true reset() include 'armeabi-v7a', 'x86', 'mips' } } }
  • 13. Code size Application Java bytecode Libraries Java bytecode Dex Dalvik bytecode Javac Application Java source Libraries Java bytecode XML resources Assets Assets Compiled XML resourcesAapt java.lang.IllegalArgumentException: method ID not in [0, 0xffff]: 65536 java.lang.IllegalArgumentException: method ID not in [0, 0xffff]: 65536
  • 14. Dex file ... Strings Types Prototypes Field IDs Method IDs Class definitions Method IDs #0: Accounts . <init>(.....) #1: AccountManager . get(......) #2: AccountManager . ….. #3: ….. #4: ….. ... ... ... ... ... ... ... ... ... ... ... ... ... ... #65535: …..
  • 16. ProGuard Application Java bytecode ProGuard Libraries Java bytecode Processed Java bytecode Dex Javac Application Java source Libraries Java bytecode XML resources Assets Assets Compiled XML resourcesAapt Dalvik bytecode
  • 17. -keepclassmembers,allowobfuscation class * { @dagger.** <fields>; @dagger.** <methods>; } -keep class **$$ModuleAdapter -keep class **$$InjectAdapter -keep class **$$StaticInjection -keep class com.example.DemoModule -keep class com.example.AndroidModule -keep class com.example.HomeActivity -keepnames class dagger.Lazy -keepclassmembers,allowobfuscation class * { @dagger.** <fields>; @dagger.** <methods>; } -keep class **$$ModuleAdapter -keep class **$$InjectAdapter -keep class **$$StaticInjection -keep class com.example.DemoModule -keep class com.example.AndroidModule -keep class com.example.HomeActivity -keepnames class dagger.Lazy Example configuration: Dagger Generated classes Corresponding base classes
  • 18. Libraries Library Method IDs Google Play Services 6.0 23,607 Guava 15.0 14,495 Yahoo Flurry Ads 4.1.0 8,511 ActionBarSherlock 4.4.0 4,300 RoboGuice 2.0 3,787 Facebook 3.5.2 3,166 Yahoo Flurry Analytics 4.1.0 1,148 Scala Core 2.11.2 50,786
  • 19. ProGuard on libraries ProGuard Library Java bytecode Processed library Java bytecode
  • 20. Shrink Ads library -injars google-play-services.jar -outjars google-play-services-ads.jar -libraryjars android-sdk/extras/android/support/v4/android-support-v4.jar -libraryjars android-sdk/platforms/android-20/android.jar -dontoptimize -dontobfuscate -dontwarn com.google.**.R -dontwarn com.google.**.R$* -dontnote -keep public class com.google.android.gms.ads.** { public protected *; } -keep class com.google.android.gms.common.internal.safeparcel.SafeParcelable { java.lang.String NULL; } -injars google-play-services.jar -outjars google-play-services-ads.jar -libraryjars android-sdk/extras/android/support/v4/android-support-v4.jar -libraryjars android-sdk/platforms/android-20/android.jar -dontoptimize -dontobfuscate -dontwarn com.google.**.R -dontwarn com.google.**.R$* -dontnote -keep public class com.google.android.gms.ads.** { public protected *; } -keep class com.google.android.gms.common.internal.safeparcel.SafeParcelable { java.lang.String NULL; } proguard @ configuration.txtproguard @ configuration.txt Command line: configuration.txt
  • 21. Shrink Ads library Before After Reduction Size 3.3 M 578 K 83 % Classes 3294 497 85 % Method IDs 23607 3751 84 % ProGuard Google Play Services library Ads library
  • 22. Shrink Maps library -injars google-play-services.jar -outjars google-play-services-maps.jar -libraryjars android-sdk/extras/android/support/v4/android-support-v4.jar -libraryjars android-sdk/platforms/android-20/android.jar -dontoptimize -dontobfuscate -dontwarn com.google.**.R -dontwarn com.google.**.R$* -dontnote -keep public class com.google.android.gms.maps.**, com.google.android.gms.common.**, com.google.android.gms.location.** { public protected *; } -keep class com.google.android.gms.common.internal.safeparcel.SafeParcelable { java.lang.String NULL; } -injars google-play-services.jar -outjars google-play-services-maps.jar -libraryjars android-sdk/extras/android/support/v4/android-support-v4.jar -libraryjars android-sdk/platforms/android-20/android.jar -dontoptimize -dontobfuscate -dontwarn com.google.**.R -dontwarn com.google.**.R$* -dontnote -keep public class com.google.android.gms.maps.**, com.google.android.gms.common.**, com.google.android.gms.location.** { public protected *; } -keep class com.google.android.gms.common.internal.safeparcel.SafeParcelable { java.lang.String NULL; } proguard @ configuration.txtproguard @ configuration.txt
  • 23. Shrink Maps library Before After Reduction Size 3.3 M 583 K 82 % Classes 3294 546 83 % Method IDs 23607 4891 79 % ProGuard Google Play Services library Maps library
  • 24. Splitting dex files Main dex file Secondary dex file Build-time Run-time
  • 25. Splitting dex files Application Java bytecode Libraries Java bytecode Dex Main Dalvik bytecodeJavac Application Java source Libraries Java bytecode XML resources Assets Assets Compiled XML resourcesAapt Secondary Dalvik bytecode Dex
  • 26. Dex splitting: tools ● secondary-dex-gradle (Mohit Kanwal) ● Dex 65536 (Mmin18) ● DexGuard (Saikoa) ● multiDex (Android Gradle plugin 0.14)
  • 27. Dex splitting: secondary-dex-gradle ● ApplicationProject LibraryProject ● settings.gradle ● AndroidManifest.xml ● AppProject/src/com/example/App.java AppProject/src/com/example/SecondaryDex.java AppProject/src/com/example/FrameworkHack.java include ':ApplicationProject', ':LibraryProject'include ':ApplicationProject', ':LibraryProject' <application android:name="com.example.App" ... > <application android:name="com.example.App" ... >
  • 28. Dex splitting: secondary-dex-gradle Advantages: ● It works! Disadvantages: ● Split project ● No references library application→ ● Dex classpath hack
  • 29. Dex splitting: Dex 65536 ● libs/google-play-services.jar (for example) ● custom_rules.xml ● AndroidManifest.xml ● src/com/example/App.java ... <pathtool libs="libs/google-play-services.jar" ... /> ... ... <pathtool libs="libs/google-play-services.jar" ... /> ... <application android:name="com.example.App" ... > <application android:name="com.example.App" ... > new DexClassLoader(dexFile.getAbsolutePath(), dexOpt.getAbsolutePath(), nativeLibraryDir, classLoader.getParent()); new DexClassLoader(dexFile.getAbsolutePath(), dexOpt.getAbsolutePath(), nativeLibraryDir, classLoader.getParent());
  • 30. Dex splitting: Dex 65536 Advantages: ● It works! Disadvantages: ● Only for library jars ● Dex classloader hack
  • 31. Dex splitting: DexGuard ● Gradle, Ant, Eclipse, Maven, Android Studio,... ● dexguard-project.txt -splitdexfile com.google.** -splitdexfile !com.facebook.samples.**, com.facebook.** -splitdexfile com.google.** -splitdexfile !com.facebook.samples.**, com.facebook.**
  • 33. Dex splitting: multiDex Android 5.0 loads classes2.dex, classes3.dex, etc. ● build.gradle ● AndroidManifest.xml (for legacy platforms) dependencies { compile 'com.android.support:multidex:1.0.0' } android { ... defaultConfig { multiDexEnabled true } } dependencies { compile 'com.android.support:multidex:1.0.0' } android { ... defaultConfig { multiDexEnabled true } } <application android:name="android.support.multidex.MultiDexApplication" ... > <application android:name="android.support.multidex.MultiDexApplication" ... >
  • 34. Dex splitting: Android 5.0 Advantages: ● Latest standard Disadvantages: ● Eager loading
  • 35. Summary Resources and assets: – Compress – Trim – Split apk Bytecode: – Shrink libraries – Shrink application – Split dex file
  • 36. Further reading ● “Custom Class Loading in Dalvik”, Fred Chung, Google http://android-developers.blogspot.com/2011/07/custom-class-loading-in-dalvik.html ● “Play Services 5.0 Is A Monolith Abomination”, Jake Wharton http://jakewharton.com/play-services-is-a-monolith/ ● “DEX Sky’s the limit? No, 65K methods is”, Sebastiano Gottardo https://medium.com/@rotxed/dex-skys-the-limit-no-65k-methods-is-28e6cb40cf71 ● “Multi-dex support”, Xavier Ducrohet https://plus.google.com/+XavierDucrohet/posts/1FnzwdcBnyC ● “Under the Hood: Dalvik patch for Facebook for Android”, David Reiss https://www.facebook.com/notes/facebook-engineering/under-the-hood-dalvik-patch-for-facebook-for-android/10151345597798920 ● “Remove unused resources”, Tor Norbye https://plus.google.com/+TorNorbye/posts/eHsStybrrBf ● “Tips for reducing APK file size”, David Karlsson, Sony http://developer.sonymobile.com/2012/01/31/tips-for-reducing-apk-file-size/
  • 37. Software tools ● android-resource-remover, Philipp Berner, KeepSafe https://github.com/KeepSafe/android-resource-remover ● android-unused-resources, S. Kennedy https://code.google.com/p/android-unused-resources/ ● secondary-dex-gradle, Mohit Kanwal https://github.com/creativepsyco/secondary-dex-gradle ● Dex 65536, Mmin18 https://github.com/mmin18/Dex65536 ● ProGuard http://proguard.sourceforge.net/ ● DexGuard http://www.saikoa.com/dexguard