How to reduce Android APK size in react-native? - android

I am working on react native project , but whenever i am building an Apk file , it give me Apk of 47MB.
I tried every documentation which i found useful on google but nothing works for me, Is there any way to reduce my App size below 10MB as the app only contain three or four pages. Any help would be appreciated

You can try following steps
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.
Setting the last function creates two distinct apk in the build folder. You have to upload both of this apk to Play Store and Google would take care of distributing the app to the correct architectures.
Using this split generates version numbers for both apks in the order of 104856 and such. This is auto-generated by the build to avoid version conflicts, so don’t freak out (I did).
This split reduced the apk size from around 7MB to 3.5MB for arm and 5MB for x86 respectively.
You can find more information in this article https://medium.com/#aswinmohanme/how-i-reduced-the-size-of-my-react-native-app-by-86-27be72bba640

Seem like android app bundle can help you. But i will also answer the question how to reduce Android APK size in react-native
there are many ways to optimize app install size of a mobile app build with react-native.
a react-native app size depend on:
total Js code imported in your app (included in node_modules)
total Native code use in your app.
Total assets (images/ videos/ media ...)
variant of devices your app supported
To reduce / optimize your app size, you have to optimize 4 things above
First, js code
We write JS code, react components then update, replace by new others. By times, js code base growth. and become mess & smelling, useless but hard to remove from code base. It make your app size growth by still imported in your code base but never to be use.
-> Check, refactors your JS code after 1 / 2 phase of features development to make your code beauty & lean.
Second, Native code
Native side seem like a mystery cave with JS react-native developers and beginners. In native libraries have a ton of Java / Objective-C codes which hard to reach by developer. Some of their un-controlled or not necessary.
Abuse native libraries can soaring your app size and make some weird crashes
-> Don't use native libraries if you don't need it or you can do it by js code.
-> use Proguard to thin your app size by shrink code and remove unused codes. My apps reduced 15% - 20% app size after configured proguard.
Learn more about proguard here
Third, Assets
Assets like images, sounds or video are usually have high weight. To optimize assets you can use some tips below:
use webp format images
do not abuse png, gif format if jpg is enough
Optimize image files size using some tools like tinypng.com It's pretty good and fast
use vector icons. Like react-native-vector-icons
Do not included high weight assets in bundle, you can processing download and setup they when first times users open app.
Last, config variant of devices your app supported
If your app target some specify devices, os versions. You can limit it, remove unsupported architectures. It's can reduced 2% -> 10% base on what you removed.
Use Android app bundle, it's recommended by Google. if your app sold in Play Store. It will separate your bundle file into many installable apk files base on device types. So your app only included assets / code necessary for only this device type. Amazing, right?
Learn more about Android App Bundle here
one of my apps if build for type APK is 40MB.
When build type AAB is 40 MB. But install file from Goole play store only 13 -> 17 MB depend on device types.

Switch on these options
def enableProguardInReleaseBuilds = true
def enableSeparateBuildPerCPUArchitecture = true
Find alternatives for large-sized modules
Use cost-of-modules (npm package that will list the size of packages in your peoject) ... and try to find an alternative for costy-packages

Build .apk to .aab file and then deploy .aab file to google play console.
please read about app bundle concept in devloper site.
https://developer.android.com/guide/app-bundle

You can build .abb (Android App Bundle) file instead of .apk. This reduce your app size almost 3x time smaller.

You cannot do much about it . by using def enableProguardInReleaseBuilds = true can compress the app a bit . Use .aab bundle instead of apk format and uplaod it to Play store google play will compress the app further .If you are using play store and bundling your app in .aab format you need to do separate apk by enablingdef enableSeparateBuildPerCPUArchitecture = true
For more Info https://developer.android.com/studio/build/configure-apk-splits

Open up android/app/build.gradle and edit the following code as shown.
***lATEST method ***
def enableSeparateBuildPerCPUArchitecture = true
def enableProguardInReleaseBuilds = (findProperty('android.enableProguardInReleaseBuilds') ?: true).toBoolean()

Remove unwanted Codes and unused Packages.
inside the app/build.gradle
Set values into true
def enableProguardInReleaseBuilds = true
def enableSeparateBuildPerCPUArchitecture = true
And
buildTypes {
release {
debuggable false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
use this command to build
gradlew bundleRelease

Related

How to decrease flutter app size in android

I make my app using flutter and my app size is more than 100 mb and app has 15 screens.
It's android size is more than 100 mb and iOS app size is 40 mb I have to make it small
and I want proper solution for this


I try to compress my image files but it just decrease 8 mb
I want proper solution for compress flutter app size.
Check this below steps it may help you to reduce app size (only Android), i have reduced my 48mb build to 14mb
Step 1: android/gradle.properties
android.enableR8=true
Step 2: android/app/build.gradle
inside -> buildTypes -> release
minifyEnabled true
shrinkResources true
useProguard true
Step 3:
Run
flutter build apk --target-platform=android-arm
or
flutter build apk --split-per-abi
Some other optimizing tips,
1. Image assets
Upload the images in permanent storage path like AWS or in your website server and use the link to that image in your code.
2. Icons
Its recommended to use from Material Icons or Cupertino Icons class. You can add --tree-shake-icons option to flutter build command, to remove all of the not used icons from the bundle. This will potentially save the size of your app. (use svg format icons)
3. Fonts
If we are using more fonts from local assets similar like images these fonts will also increase app size. The best solution is to use google_fonts plugin. This pluign will dynamically download font when it is used.
4. Dynamic App Delivery
We could build an app bundle if we are uploading to playstore or we could split the apk per abi which splits the apk to x64 and x86 bit code. By using appbundle Google Play’s new app serving model, called Dynamic Delivery, uses your app bundle to generate and serve optimized APKs for each user’s device configuration, so they download only the code and resources they need to run your app.
Refer below links for more understanding,
https://developer.android.com/studio/build/shrink-code
https://developer.android.com/guide/app-bundle
https://www.youtube.com/watch?v=9D63S4ZRBls
How many third-party packages are you using?
Did you use drag and drop to create the app or code everything manually?
Did you properly use const in objects that are repeated but are essentially the same? Like const EdgeInsets.all(8.0).
Do you have a lot of gradient images that you can convert to Container gradients?
Use webp images instead of PNG or JPEG
Add pro-guard files
Minify Enabled - true
Shrink- Resource -true
try running:
flutter clean
and then:
flutter build apk --split-per-abi
you could even further reduce the size of your code by doing:
flutter build apk --split-debug-info=/<project-name>/<directory>
and if you're willing to take the risk, you can obfuscate your code:
flutter build apk --obfuscate --split-debug-info=/<project-name>/<directory>
where
/<'project-name'>/<'directory'>
is the directory where Flutter can output your app debug files.

What symbols to upload to Play Store with Flutter and native obfuscation?

For an Android Flutter app, you can obfuscate the Dart code and the native Android code.
Obfuscate Dart code with the flags --obfuscate --split-debug-info=/path/to/place/symbols while building aab, apk, ipa or ios.
You can obfuscate the Android native app in the build.gradle at the app level
buildTypes {
release {
shrinkResources true
minifyEnabled true
}
Now, my doubt is what symbols do I have to upload to Google Play?
The Dart obfuscation generates the files:
app.android-x64.symbols
app.android-arm64.symbols
app.android-arm.symbols
but there is no info in how to use them besides symbolizing a crash report file you downloaded to your computer
According to skyllet's answer, you should compress the folders (each one consisting in a libapp.so and libflutter.so archive):
arm64-v8a
armeabi-v7a
x86_64
located at build\app\intermediates\merged_native_libs\release\out\lib into a *.zip and upload that zip to Google Play
You can also bundle the native symbols in the aab following Taras Svidnytskyy's answer by downloading the NDK and configuring the build.gradle (app)
android.*.ndkVersion = "23.1.7779620" | 'your ndk version'
android.*.ndk.debugSymbolLevel = 'FULL' | 'TABLE' // Table for reduced symbols
Now, using 3), the size of the compressed native-symbols bundled with the AAB, which unfortunately I cannot download to compare, is 5kB in Google Play console.
Using 2), the size of the compressed zip having the 3 folders is 12MB.
I didn't find how to upload the symbols from 1), but they weight about 1MB (compressed)
So my understanding is that 2 and 3 should upload the same symbols, but comparing the sizes of the archives, that does not seem the case.
What is the correct way to upload the symbols map?

Huge APK size with Mozilla Android Components

I'm building an APK (not app bundle) using Gradle via Android Studio.
Without adding any Mozilla dependencies in my app's build.gradle file the APK size is under 5MB but after adding these dependencies the APK size increases to over 100MB.
Most of the APK size is in the (new) lib directory, particularly the lib/libxul.so file, but also the assets/omni.ja file is around 9MB.
I am aware of how to reduce the APK size by using ABI filters and APK splitting to generate separate APKs for different architectures, but this can only do so much to reduce the download size for the user. Is there any way I can significantly reduce the size of my APK? Are there any command line options I can add or additional Gradle options to achieve this?
For reference, I am importing the following dependencies: https://github.com/mozilla-mobile/android-components
from here: https://maven.mozilla.org/maven2
The official recommendation is here: https://developer.android.com/studio/build/shrink-code.
And you can also use Play feature delivery to serve some features only when needed by users: https://developer.android.com/guide/app-bundle/play-feature-delivery

How to minimize the .apk size in android studio?

I am making a simple video call app by using Jitsi Android SDK after completion when i build my signed APK its size is too big i.e, 101 MB when i check that apk it shows the type .nox apk.
Another problem is when i tried to install that 101MB apk into Mobile it says App Not Installed
for this i checked mobile settings Unknown Sources after that it stick to the same message (App not installed).
this is my App's build.gradle(app) file
Here is my Proguard Rule also and target SDK
and this is the extention of APk file
here is my analyze apk result
How to build reduced Apk which run easily...Please Help me into this i don't know where i am going wrong ??
The main reason for your app to be that big is because of all the native libraries which you have in your project. I guess they are included by Jitsi Android SDK.
I guess you are not creating App Bundle but building directly an apk via Android Studio, that's why all versions of native libraries are included in the same apk.
By using App Bundle format to build your app you should lower a lot your app's size, because it will create apk files only for the specific configurations, so every architecture will have it's own apk with included native libraries for only that architecture.
Once you have the App Bundle file you can create your apk's in order to install to a device using bundletool. With a command like this:
bundletool build-apks --bundle=/PathToMyABB/app-bundle.aab --output=/PathToMyAPKS/my-apks.apks
You can retrieve apk as bundle and convert your images to webp format you are going to save %50 memory area.
First of All You Need to Tinify the Resource images Tinyfy, I suggest you to use this link to tinify your image assets.
The Second thing after the above Step, Convert all Image Assets to Webp Format, in order to convert to webp you need to right click on image asset and then at the Bottom of option there will be optionj convert to webp.
Remove Unnecessary classes and libraries to Reduce the Size.
Apply Proguard Rules to Reduce Size
In Order to remove delete x86_64 you just need to do is, just add this under Android Tag in app level gradle File
splits {
abi {
enable true
reset()
include 'armeabi-v7a'
universalApk false
}
}

Useless resources in APK file

I've got problem with very simple application. APK size is now 3 MB, but it contains a lot of useless for me files (I think that source of this files is Support Library). In my application I don't use any images, but all drawable directories contains a lot of icons, buttons, etc. Is it possible to delete this images by any rule in gradle or other method? I use Android Studio.
Already I added to build.gradle information about languages to include in APK. I had in Hello World 80 languages before it.
Screen of files:
The Gradle build system for Android supports "resource shrinking": the automatic removal of resources that are unused, at build time, in the packaged app. In addition to removing resources in your project that are not actually needed at runtime, this also removes resources from libraries you are depending on if they are not actually needed by your application.
To enable this add the line shrinkResources true in your gradle file.
android {
...
buildTypes {
release {
shrinkResources true
}
}
}
Check the official documentation here,
http://tools.android.com/tech-docs/new-build-system/resource-shrinking

Categories

Resources