How to reduce size of apk file? - android

I am working on an application which is containing .apk file of 13.56MB. It is containing 70 .png images. And there is image transparency so it have to be in .png format.
And i have to add more images. so do you have any solution to reduce the memory of an application.

Please used 9-patch images.
Nine patch images are especially useful when designing buttons. Custom drawn buttons can look distorted and pixelated when their borders are stretched in addition to the rest of the image.
Official Documentation and other resource for further help.

Use Following things
use tiny png to reduce size of images without loosing quality https://tinypng.com
Use tool AndroidUnusedResources to remove unneccessary resources
https://code.google.com/p/android-unused-resources/
Repackge jars or libraries using JarJar.jar tool. If you are using GooglePlayServices.jar then its too large

Batter way to reduce size of apk. Split apk and minifyEnabled=true.
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
}
splits {
abi {
enable true
reset()
include 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86'
universalApk false
}
}

Related

react-native size doesn't shrink

Trying to make a smaller APK, currently the size is 21 MB. Hoping to reduce it to 10MB.
I do this inside android/app/build.gradle, but it doesn't reduce, I just want ARM support for now:
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "arm64-v8a"
}
}
Try this, I hope this will helps you.
Open up android/app/build.gradle
Set def enableProguardInReleaseBuilds = true this would enable Progaurd to compress the Java Bytecode. This reduces the app size by a tad bit
Set def enableSeparateBuildPerCPUArchitecture = true . Android devices support two major device artitectures armebi and x86. By default RN builds the native librariers for both these artitectures into the same apk.
more information to https://medium.com/#aswinmohanme/how-i-reduced-the-size-of-my-react-native-app-by-86-27be72bba640

Compressing the size of React Native apps

Can someone please specify me the procedures for compressing the app size built on react native.
I referred to many pages on google, hackernoon, and medium but they were too good for me to understand.
Please if someone knows basic and fewer glitch ideas on how to compress react native apps for both Android and iOS with procedures and where to keep the screen files and assets folder.
I tried by following the steps on medium, detached the iOS and android folders but it was an unsuccessful attempt.
Please if someone can help me in compressing the app size.
Yes you can easily reduce app size . Just go to app/build.gradle and pasted these lines or check these lines
def enableSeparateBuildPerCPUArchitecture = true
def enableProguardInReleaseBuilds = true
enjoy
you can reduce your react-native app size by this steps:
1- shrink your app icons and images size as possible as you can
2- go to android/app/build.gradle and make this changes:
project.ext.react = [
entryFile: "index.js",
enableHermes: true, // change false to true
]
...
def enableHermes = project.ext.react.get("enableHermes", true);
its for using hermes engine in bundling js server.
3-
def enableSeparateBuildPerCPUArchitecture = false // change false to true
the above line causes building seprate apks instead of universal apk. however you can have both seprates and universal by doing following changes :
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk true // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64" // seprate apks
}
}

barteksc/AndroidPdfViewer massive APK Size

We included this AndroidPdfViewer library to support viewing of PDF reports in the app. It lead to massive increase in APK size from 4.7Mb to 20.1Mb .
Is there a way to reduce this size. Let me know where and what to tinker around to help or solve this.
I am familiar with proguard and have it configure for my app with reasonable success.
Why resulting apk is so big?
As stated in the documentation by barteksc/AndroidPdfViewer
Android PdfViewer depends on PdfiumAndroid, which is set of native
libraries (almost 16 MB) for many architectures. Apk must contain all
this libraries to run on every device available on market.
Fortunately, Google Play allows us to upload multiple apks, e.g. one
per every architecture. There is good article on automatically
splitting your application into multiple apks, available here.
Most important section is Improving multiple APKs creation and
versionCode handling with APK Splits, but whole article is worth
reading. You only need to do this in your application, no need for
forking PdfiumAndroid or so.
API: https://github.com/barteksc/AndroidPdfViewer
You have to generate Multiple APKs for different devices, by doing this you can reduce the size of apk up to 10 MB less than previous. Add below code to build.gradle (Module:App)
android{
.....
splits {
abi {
enable true
reset()
include 'x86_64', 'x86', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips'
universalApk false
}
}
.....
}
ext.versionCodes = ['armeabi': 1, 'armeabi-v7a': 2, 'arm64-v8a': 3, mips: 4, 'x86': 5, 'x86_64': 6]
import com.android.build.OutputFile
// For each APK output variant, override versionCode with a combination of
// ABI APK value * 1000 + defaultConfig.versionCode
android.applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
output.versionCodeOverride =
project.ext.versionCodes.get(output.getFilter(OutputFile.ABI)) * 1000 + android.defaultConfig.versionCode
}
}
Whatch video here https://youtu.be/bP05Vpp49hs for detail explanation on how to do it.
If anyone is looking for a lightweight pdf viewer for your app, then try this one
Use this library
It helped me to reduce the app size from 27MB to 10MB because of the barteksc-androidpdfviewer requires more space
I also faced the same problem, but this is very easy as of now to reduce the apk sizes by using android app bundles.
Firstly in build.gradle(Module: app) add these lines inside android { } brackets.
bundle {
abi {
enableSplit = true
}
}
This will handle apk splits on the basis of architecture.
Now, also remember to add this line in proguard-rules.pro
-keep class com.shockwave.**
If you will not add this line in proguard-rules.pro then your app will crash in release version.
Now, after this go to Build and then select, Generate Signed Bundle/apk. From here, generate a signed bundle. Bundles are generated in very same way, as the apk's are generated.
Then, upload your bundle(.aab file) on Google Play Console and you will see that every device gets different apks depending upon their architecture.
This is the most easiest way to reduce the app size.Multiple apk concept is more complicated.
So,I suggest you to use this way.

Reducing the size of final APK before submitting to the play store

My android application file size is huge, I've used Proguard and ImageOptim to reduce the size of images and code which isn't being used.
This is the buildtypes in my gradle:
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
I will also delete the mockable-android-jar before submitting.
I have also seen that the intermediates folder is big in size, I also cleaned it by deleting the extra png images which were not being used by the application (i.e: g+ png's and so on.)
What can I do which may help me shrink down this apk.
Edit: Made the following edits, which resulted intermediates to become 12.5 MB
android {
defaultConfig {
...
resConfigs "en"
}
Removes resources which are not meant for the english language.
Extract your apk and check which folder is bigger in size.
Or you can use "Android Studio" Also to analyze your apk file :
Reduce your image files size and use vector drawables wherever possible.
Go through the following guides on apk size reduce :
https://medium.com/google-developers/smallerapk-part-1-anatomy-of-an-apk-da83c25e7003#.nlid8yvdb
https://medium.com/google-developers/smallerapk-part-2-minifying-code-554560d2ed40#.bayyfe7zd
https://medium.com/google-developers/smallerapk-part-3-removing-unused-resources-1511f9e3f761#.igywlhtem
https://medium.com/#wkalicinski/smallerapk-part-4-multi-apk-through-abi-and-density-splits-477083989006#.9fgm8mryi
https://medium.com/#wkalicinski/smallerapk-part-5-multi-apk-through-product-flavors-e069759f19cd#.ngg4dfe8i
https://medium.com/#wkalicinski/smallerapk-part-6-image-optimization-zopfli-webp-4c462955647d#.elxsq9tcc
https://medium.com/#wkalicinski/smallerapk-part-7-image-optimization-shape-and-vectordrawables-ed6be3dca3f#.m0p9rrl4t
https://medium.com/#wkalicinski/smallerapk-part-8-native-libraries-open-from-apk-fc22713861ff#.mcytfj9y3

Reduce apk size android

I am facing a problem with app size in android.
The scenario is,
I developed my android app in Android Studio 2.0 and the size of apk was 23 MB.
After that, I upgraded my IDE to android studio 2.2 and with little code modification the size of apk boosted to 51 MB.
I tried with prorogued and Lint but no advantage.
Can Someone help me to tackle the issue.
1) Replace all of Images,Icons with vector drawable
2) Turn on pro guard like following
goto build.gradleapp level
and put these lines
**shrinkResources true
minifyEnabled true**
3) Remove unused classes,drawable and methods and strings
and use LINT's private method analyser which reduces method count
JAVA's Hidden cost
4) In android studio 2.2 and above they have added apk analyser tool in Build menu. Use that to analyse APk
5) if app size goes beyond 100mb use feature called split apk.
there are two methods of spliting apk
ABI and Density Splits
Do this changes in your build.gradle(Module:app) file. It decreases the apk size almost (40-50)%.
android {
// Other settings
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
It reduces the size of classes.dex files and res folder.
It is recommended to that you should use webp file format instead of BMP, JPG, PNG for better compression.
For reference, you can use: https://developer.android.com/studio/write/convert-webp.html
For more details on apk compression you can refer:
https://developer.android.com/topic/performance/reduce-apk-size.html
https://medium.com/how-you-can-decrease-application-size
Points to reduce APK size:
Make sure to do it
1. Use vector drawable
2. Use xml drawable to create simple view
3. Rotate images using xml drawable to reuse (eg. in case of arrow buttons)
4. Create drawable through code
5. Use aaptOptions { cruncherEnabled = false } to compress images
6. Use webP format for large images
7. Avoid enumerations and use #IntDef annotation
8. Use shrinkResources true in gradle to remove unused resources
9. Use resConfig “en” in gradle to remove other localization
android {
// Other settings
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
shrinkResources true will not include the images from resources which your using in the final apk
hope this will help you!

Categories

Resources