Slide 1

Slide 1 text

Mobile Wellbeing: Shrinking Android Apps Sneh Pandya

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Today.. keep rules!!

Slide 4

Slide 4 text

Configuration language for ProGuard to specify things you need to keep in your APK while shrinking

Slide 5

Slide 5 text

Luckily.. Same language is used to build R8 shrinker (replacement for ProGuard)

Slide 6

Slide 6 text

Android Developers here?!

Slide 7

Slide 7 text

Who of you uses ProGuard?!

Slide 8

Slide 8 text

Google statistics show that.. Only 25% of apps on Play Store actually use keep rules!

Slide 9

Slide 9 text

Why does it matter?! Next billion users & Entry level Android Devices

Slide 10

Slide 10 text

RAM Disk space Bandwidth :P Limited Resources

Slide 11

Slide 11 text

Download Install (compile) Startup Smaller is faster

Slide 12

Slide 12 text

“Hardware will fix this!” “Haha, devices are faster” “There’s more storage ;)” “Connectivity is better!” You say..

Slide 13

Slide 13 text

That’s not a solution!

Slide 14

Slide 14 text

32 MB 1 MB

Slide 15

Slide 15 text

Hardware is not going to fix this shit for us!

Slide 16

Slide 16 text

Let’s look at an example..

Slide 17

Slide 17 text

Just 30 minutes! Android Support + ConstraintLayout + Retrofit + Gson + Glide Static data & Dynamic view A simple app

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

APK Analyzer says.. 2 MB for APK & 5.74 MB when installed!

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

We flew to the Moon & back with just 60KB of code!

Slide 22

Slide 22 text

fly to the Moon vs render an app on Android!

Slide 23

Slide 23 text

Apollo mission had a dedicated team that hand crafted, meticulously reduced & put only code needed Limited Resources

Slide 24

Slide 24 text

Fast forward to today.. We use components!

Slide 25

Slide 25 text

Simply..

Slide 26

Slide 26 text

Uh-oh!!

Slide 27

Slide 27 text

StackOverflow says..

Slide 28

Slide 28 text

But, under the hood.. ProGuard shrinks the code and generates the smaller app It actually grows the tree & scans everything that will be executed at runtime

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

always live

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

MainActivity AppCompatActivity FragmentActivity SupportActivity Activity

Slide 34

Slide 34 text

MainActivity AppCompatActivity FragmentActivity SupportActivity Activity

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

Neither R8, nor ProGuard understand the Manifest files That’s done by AAPT: preprocess all resources & keep corresponding keep rules

Slide 37

Slide 37 text

When ProGuard removes too much.. ClassNotFoundException MethodNotFoundException and so on.. It is very important to test the release build with ProGuard enabled of your app thoroughly and deal with these errors

Slide 38

Slide 38 text

keep rules -keep  preserves all classes & methods -keepclassmembers members to be kept, only if their parent class is being preserved -keepclasseswithmembers keep class & its members, only if all members listed are present -keepnames, -keepclassmembernames, -keepclasseswithmembernames

Slide 39

Slide 39 text

shrinking rules -dontshrink  not to shrink the input class files -printusage list dead code of the input class files -whyareyoukeeping print details on why the given classes and class members are being kept in the shrinking step

Slide 40

Slide 40 text

1.1 MB (2 MB) for APK & 2.1 MB (5.74 MB) when installed! Now our APK Analyzer says..

Slide 41

Slide 41 text

Sneh Pandya about.me/SnehPandya18 stackoverflow.com/users/6248491 github.com/SnehPandya18 medium.com/@SnehPandya18 twitter.com/@SnehPandya18 fb.com/SnehPandya18

Slide 42

Slide 42 text

Thank You!