How to decrease flutter app size in android - 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.

Related

why flutter project files size is more then 500MB?

Is it normal the size of flutter start app "counter app" is 125MB on Android Device, also the project files size is 543MB, the build file only is 508MB, I have a problem if anyone can help?
Flutter team acknowledges it
https://github.com/flutter/flutter/issues/12456.
There's an explanation for this https://flutter.dev/docs/resources/faq#how-big-is-the-flutter-engine,
In August 2018, we measured the size of a minimal Flutter app (no Material Components, just a single Center widget, built with flutter build apk), bundled and compressed as a release APK, to be approximately 4.7MB.
For this simple app, the core engine is approximately 3.2MB (compressed), the framework + app code is approximately 840KB (compressed), the LICENSE file is 55KB (compressed), necessary Java code (classes.dex) is 57KB (compressed), and there is approximately 533KB of (compressed) ICU data.
Of course, YMMV, and we recommend that you measure your own app, by running flutter build apk and looking at build/app/outputs/apk/release/app-release.apk.
Also, the relative differences in apk size would likely be smaller with larger apps. Flutter's overhead size is fixed.
1)For reduce the size you can use.
flutter clean
2)flutter build appbundle --target-platform android-arm,android-arm64
3) you can use proguard to reduce the size
Here is Official Android documentation that made my apps go From ~20mb To ~9mb
Try the Proguard recommendation
Link: https://developer.android.com/topic/performance/reduce-apk-size

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
}
}

How to reduce Android APK size in react-native?

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

how to find the size of your app while its in development

I want to know whats the size of my application when I look at my android studio project under properties it is something like 100MB is that the size of my app? if it is how can I decrease it?
NOTE: I use pro guard already, I got rid of any extra libraries and I merged my adapters and model classes to decrease the amount of JAVA code.
Go to your project in Android Studio,
Step 1:
Go to Build -> Build APK(s)
Step 2:
Go to the folder --> PROJECT FOLDER -> app -> build -> outputs -> apk -> debug
Or,
Click on Event Logs -> locate apk
Check the size of your debug-apk
If you are using proguard for release build, build your release apk which will be in the release directory and you can check the size of your apk.
Build -> Analyze APK -> app-debug.apk then click OK
You can see here the summary of the file size
If it is not working try to Build APK first
to reduce your APK size you can follow this link
https://medium.com/exploring-code/how-you-can-decrease-application-size-by-60-in-only-5-minutes-47eff3e7874e
If you're interested in continuously keeping track of your APK size as you merge into your master branch, you can take a look at these two github actions. https://github.com/marketplace/actions/apk-metric-upload : This one maintains the latest master branch's size in your own repo artifact, while this action : https://github.com/marketplace/actions/apk-size-tracker compares your feature branch's size with master's size. It also provides the capability to set a threshold (per PR) on incoming PR's to not allow the apk size from increasing too much.

Categories

Resources