SlideShare a Scribd company logo
1 of 38
Download to read offline
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 SDKGuardSquare
 
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
 
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 84Mahmoud Samir Fayed
 
soscon2018 - Tracing for fun and profit
soscon2018 - Tracing for fun and profitsoscon2018 - Tracing for fun and profit
soscon2018 - Tracing for fun and profithanbeom 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 84Mahmoud 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 84Mahmoud 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 84Mahmoud 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 sdetDevLabs Alliance
 
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 SolutionsJeff 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 30Mahmoud 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 AndroidIntel® 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 Fighting app size with ProGuard, splitting APKs & dex files

Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011pundiramit
 
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 DevelopmentAndy 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 ApplicationsTom Keetch
 
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-ExploitationNitesh Malviya
 
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 SystemWilliam Lee
 
Writing Android Libraries
Writing Android LibrariesWriting Android Libraries
Writing Android Librariesemanuelez
 
Groovy In the Cloud
Groovy In the CloudGroovy In the Cloud
Groovy In the CloudJim 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 PlatformsLinaro
 
Ese 2008 RTSC Draft1
Ese 2008 RTSC Draft1Ese 2008 RTSC Draft1
Ese 2008 RTSC Draft1drusso
 
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
 
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 2014Paris 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 problemsTier1 app
 

Similar to Fighting app size with ProGuard, splitting APKs & dex files (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

Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 

Recently uploaded (20)

Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 

Fighting app size with ProGuard, splitting APKs & dex files

  • 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