SlideShare ist ein Scribd-Unternehmen logo
1 von 71
Kirill Rozov
Android Developer
Optimize APK size
GDG Minsk
medium.com/googleplaydev/shrinking-apks-growing-installs-5d3fcba23ce2
Average downloaded APK size
64 MB
What for?
DownloadAPKsize
0
5
10
15
20
25
Size from Google Play for Xiaomi Mi A1 Android 8.0
Why it’s problem?
• Support low-end devices

• Low space on device memory

• How long time it will take to download app

I need it right now!!!

• No Wi-Fi

• Cellular data costs
Effect
• Lower install conversion rate

• Google Play Featuring problems

• Google Play Security Checks problems

• Problems with Instant App (4Mb limits)
APK Structure
APK Structure
Size related to app
• APK size

• Initial download size

• On-device install size

• Update download size
Size related to app
• APK size

• Initial download size

• On-device install size

• Update download size
Graphic Optimizations
Image Optimizers
PNGQuant ImageMagick PNGGauntlet PNGOut
PNGCrush OptiPNG CryoPNG PNG Compressor
Yahoo Smush.it PNGOptimizer PunyPNG TinyPNG
PNGWolf Advpng DeflOpt Defluff
Huffmix TruePNG PNGng-s9 zopfliPNG
ImageOptim
Optimization results
9.0 MB
Optimization results
6.5 MB
Optimization results
228 Images

Save: 28%

Average: 36%

Max saving: 98.6%
6.5 MB
Android PNG Cruncher
android {
buildTypes {
release {
// Disable PNG optimisation
crunchPngs false
}
}
}
SVGO
github.com/svg/svgo
Use WebP
PNG vs WebP
PNG, 958 KB WebP 100%, 286 KB-70%
PNG vs WebP
PNG, 958 KB WebP 75%, 29 KB-97%
Vector graphics
Vector graphics
xxxhdpi
3.6 KB
xxhdpi
xhdpi
hdpi
mdpi
2.5 KB 1.6 KB 1.1 KB 0.7 KB
PNG, 100x100dp, 8 bit
Vector graphics
Size, bytes
Optimized PNG,
5 files
SVG VectorDrawable Android Shape
RAW 10,023 359 416 232
In APK 10,023 - 371 241
Glide + SVG
github.com/kirich1409/SvgGlidePlugins
POTrace
PNG SVG
potrace.sourceforge.net
Multiple APKs
Multiple APKs
android {
  splits {
    // Configures multiple APKs based on screen density
    density {
      enable true
      // Specifies a list of screen densities Gradle

// should not create multiple APKs for
      exclude "ldpi", "xxhdpi", "xxxhdpi"
      // Specifies a list of compatible screen size
// settings for the manifest
      compatibleScreens 'small', 'normal', 'large', 'xlarge'
    }
  }
}
Reuse graphics
Image tint
<ImageView
android:src="@drawable/ic_favorite_black_48dp"
android:tint=“@color/blue"
/>
Drawable.setTint(int)
Drawable.setTint(ColorStateList)
Optimize images
• Use image optimizer

• Use WebP

• Use vector graphics

• Use multiple APKs for different screen

• Reuse similar images

• Skip images for low densities
Resources

Optimizations
Fonts
Downloadable fonts
Unnecessary
resources
Resource shrinker
android {
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
        }
    }
}
Resource configurations
android {
    defaultConfig {
        resConfigs ’ru’, ‘en’, ‘es’, ‘fr’, ‘ge’
    }
}
Resource configurations
android {
    defaultConfig {
resConfig ’auto’// Only for localization languages
    }
}
Resource configurations
android {
    defaultConfig {
        resConfigs ’ru’, ‘en’, ‘es’, ‘fr’, ‘ge’
        resConfigs ’mdpi’, ‘hdpi’, ‘xhdpi’, ‘xxhdpi’
        resConfigs ’normal’, ‘large’, ‘xlarge’
    }
}
Resource Optimizations
• Downloadable fonts

• Remove unused resources

• Reuse resources

• Use recommended media formats

AAC for audio, H264 AVC for Video and etc.

• Update strings over-the-air
localise.so
Code Optimizations
D8 dex compiler
DX compilation timeTime(s)
0
5
10
15
20
DX D8
* Tested with benchmark project here
.dex file sizeFilesize,MB
0
10
20
30
40
50
DX D8
* Tested with benchmark project here
Code optimizations tools
Code optimizations tools
• Java bytecode

• ProGuard

• DexGuard

• R8

• dex

• Facebook ReDex
Input JARs
Optimised code
Optimize
Shrunk code
Shrink
Obfuscated code
Obfuscate
Output JARs
Preverify
ProGuard Result
Plaid App Results
No optimization Optimization
Optimization
+
obfuscation
.dex size 2.6 Mb 1.2 Mb 0.9 Mb
Classes number 4827 2747 2715
Method references 42664 22319 18922
medium.com/google-developers/practical-proguard-rules-examples-5640a3907dc9
External libraries usage
External libraries usage
• Remove unused Android Support Library parts

• Try to don’t add libraries for 1 class/method usage

• Reflection based libraries can’t be properly optimised and
shrinked

• Don’t add debug libraries to a release builds

• Facebook Stetho

• LeakCanary

• etc.
Native libraries
Remove unused ABIs
android {
  defaultConfig {
    ndk {
      abiFilters ‘armeabi-v7a’, ‘arm64-v8a’, ‘x86’
}
  }
}
Multiple APKs for ABIs
android {
  splits {
    // Configures multiple APKs based on ABI
    abi {
      enable true
      // Resets the list of ABIs
// that Gradle should create APKs for to none
      reset()
      // Specifies a list of ABIs
// that Gradle should create APKs for
      include ‘armeabi’, ‘armeabi-v7a’, ‘arm64-v8a’
    }
  }
}
Code Optimisations
• Use D8 compiler instead of DX

• Code optimizations & shrinker tools

• Be careful about using external libraries

• Remove support of unused ABIs

• Use multiple APKs for ABIs
Other Optimizations
APK Structure
Packaging options
android {
packagingOptions {
exclude "/okhttp3/**"
exclude "/com/google/api/**"
exclude "/kotlin/**"
exclude "/com/applovin/**.java"
exclude "/META-INF/*.version"
exclude "/META-INF/**.pro"
exclude "/META-INF/services/**"
exclude "**/*.kotlin_module"
exclude "**/*.properties"
exclude "**/*.xml"
}
}
Google Play
Features
• Special compression format

• File-by-File updates

• Multiple APKs
Google Play Multiple APKs
• OpenGL texture compression formats

• Screen sizes and densities

• Device feature sets

• Platform versions

• CPU architectures

• Special APK for Android Go Edition
Google Play App Signing
More about App Signing youtu.be/5tdGAP927dk
github.com/kirich1409/apk-size-optimization
APK size optimization guide
Thanks
kiryl.rozau@apalon.com
krlrozov
Kirill Rozov
Android Developer

Weitere ähnliche Inhalte

Ähnlich wie Optimize APK size

Froyo to kit kat two years developing & maintaining deliradio
Froyo to kit kat   two years developing & maintaining deliradioFroyo to kit kat   two years developing & maintaining deliradio
Froyo to kit kat two years developing & maintaining deliradio
Droidcon Berlin
 
Cross-Platform Development using Angulr JS in Visual Studio
Cross-Platform Development using Angulr JS in Visual StudioCross-Platform Development using Angulr JS in Visual Studio
Cross-Platform Development using Angulr JS in Visual Studio
Mizanur Sarker
 

Ähnlich wie Optimize APK size (20)

An Introduction To Android
An Introduction To AndroidAn Introduction To Android
An Introduction To Android
 
The Road To Single Dex (Gradle Summit 2017)
The Road To Single Dex (Gradle Summit 2017)The Road To Single Dex (Gradle Summit 2017)
The Road To Single Dex (Gradle Summit 2017)
 
The Road To Single Dex (GDG San Francisco Meetup)
The Road To Single Dex (GDG San Francisco Meetup)The Road To Single Dex (GDG San Francisco Meetup)
The Road To Single Dex (GDG San Francisco Meetup)
 
Android Applications Development: A Quick Start Guide
Android Applications Development: A Quick Start GuideAndroid Applications Development: A Quick Start Guide
Android Applications Development: A Quick Start Guide
 
Developing for Android-Types of Android Application
Developing for Android-Types of Android ApplicationDeveloping for Android-Types of Android Application
Developing for Android-Types of Android Application
 
Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018
Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018
Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018
 
What's new in android 2018 (dev fest)
What's new in android 2018 (dev fest)What's new in android 2018 (dev fest)
What's new in android 2018 (dev fest)
 
Froyo to kit kat two years developing & maintaining deliradio
Froyo to kit kat   two years developing & maintaining deliradioFroyo to kit kat   two years developing & maintaining deliradio
Froyo to kit kat two years developing & maintaining deliradio
 
Cross-Platform Development using Angulr JS in Visual Studio
Cross-Platform Development using Angulr JS in Visual StudioCross-Platform Development using Angulr JS in Visual Studio
Cross-Platform Development using Angulr JS in Visual Studio
 
Apache Cordova 4.x
Apache Cordova 4.xApache Cordova 4.x
Apache Cordova 4.x
 
App Engine On Air: Munich
App Engine On Air: MunichApp Engine On Air: Munich
App Engine On Air: Munich
 
Where should I run my code? Serverless, Containers, Virtual Machines and more
Where should I run my code? Serverless, Containers, Virtual Machines and moreWhere should I run my code? Serverless, Containers, Virtual Machines and more
Where should I run my code? Serverless, Containers, Virtual Machines and more
 
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
 
Google Cloud Developer Challenge - GDG Belgaum
Google Cloud Developer Challenge - GDG BelgaumGoogle Cloud Developer Challenge - GDG Belgaum
Google Cloud Developer Challenge - GDG Belgaum
 
Getting started with the NDK
Getting started with the NDKGetting started with the NDK
Getting started with the NDK
 
Cordova: APIs and instruments
Cordova: APIs and instrumentsCordova: APIs and instruments
Cordova: APIs and instruments
 
Goldark Presentation at Qualcomm QPrize 2014
Goldark Presentation at Qualcomm QPrize 2014Goldark Presentation at Qualcomm QPrize 2014
Goldark Presentation at Qualcomm QPrize 2014
 
A Tale of Two Pizzas: Accelerating Software Delivery with AWS Developer Tools
A Tale of Two Pizzas: Accelerating Software Delivery with AWS Developer ToolsA Tale of Two Pizzas: Accelerating Software Delivery with AWS Developer Tools
A Tale of Two Pizzas: Accelerating Software Delivery with AWS Developer Tools
 
Android Presentation
Android PresentationAndroid Presentation
Android Presentation
 
Android - Anroid Pproject
Android - Anroid PprojectAndroid - Anroid Pproject
Android - Anroid Pproject
 

Mehr von Kirill Rozov

Mehr von Kirill Rozov (20)

Kotlin Coroutines. Flow is coming
Kotlin Coroutines. Flow is comingKotlin Coroutines. Flow is coming
Kotlin Coroutines. Flow is coming
 
2 years without Java. Kotlin only
2 years without Java. Kotlin only2 years without Java. Kotlin only
2 years without Java. Kotlin only
 
Почему Kotlin?
Почему Kotlin?Почему Kotlin?
Почему Kotlin?
 
KOIN for dependency Injection
KOIN for dependency InjectionKOIN for dependency Injection
KOIN for dependency Injection
 
ConstraintLayout. Fell the Power of constraints
ConstraintLayout. Fell the Power of constraintsConstraintLayout. Fell the Power of constraints
ConstraintLayout. Fell the Power of constraints
 
Kotlin 1.2: Sharing code between platforms
Kotlin 1.2: Sharing code between platformsKotlin 1.2: Sharing code between platforms
Kotlin 1.2: Sharing code between platforms
 
Kotlin - следующий язык после Java
Kotlin - следующий язык после JavaKotlin - следующий язык после Java
Kotlin - следующий язык после Java
 
Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2
 
Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1
 
Тестирование на Android с Dagger 2
Тестирование на Android с Dagger 2Тестирование на Android с Dagger 2
Тестирование на Android с Dagger 2
 
Что нового в Android O (Grodno HTP)
Что нового в Android O (Grodno HTP)Что нового в Android O (Grodno HTP)
Что нового в Android O (Grodno HTP)
 
What's new in Android O
What's new in Android OWhat's new in Android O
What's new in Android O
 
Android service
Android serviceAndroid service
Android service
 
Effective Java
Effective JavaEffective Java
Effective Java
 
Dagger 2
Dagger 2Dagger 2
Dagger 2
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
REST
RESTREST
REST
 
Kotlin для Android
Kotlin для AndroidKotlin для Android
Kotlin для Android
 
What's new in Android M
What's new in Android MWhat's new in Android M
What's new in Android M
 

Kürzlich hochgeladen

Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 

Kürzlich hochgeladen (20)

Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 

Optimize APK size