Why the size of flutter build apk --release is larger than the size of flutter run --release which reduces the size by half. I need to get the leaner app size.
We should know that flutter run --release compiles only for a target ABI (because you run the generated APK directly to your device). while, flutter build apk --release results in a fat APK (Universal apk) that contains your code compiled for all the target ABIs, as a result, you could install this apk on any device.
Flutter app can be compiled for
Armeabi-v7a (ARM 32-bit)
Arm64-v8a (ARM 64-bit)
x86-64 (x86 64-bit)
In Flutter, a build refers to the process of taking your source code and turning it into a deployable app. There are two types of builds in Flutter: debug builds and release builds.
Debug builds are used for development and testing. They are built with debugging symbols enabled, which makes it easier to debug your code. Debug builds also include a debugger that allows you to pause the execution of your code and inspect variables and the call stack.
Release builds are used for deploying your app to app stores or distributing it to users. They are built with debugging symbols stripped, which makes the app smaller and faster. Release builds also have optimizations enabled, which makes the app even faster.
To create a release build in Flutter, you can use the flutter build command with the --release flag. For example:
flutter build apk --release
This will create a release build of your app in the build/app/outputs/apk directory.
Related
I just finished an application with flutter and while I run it in debug mode everything is fine, but when I switch to --profile or --release mode it changes all the icons that I use and puts others, even the navigation arrows of the application.
I've had this error before while locally testing on a device with an .apk file directly generated from flutter build.
It fixed itself once I tested from the play store.
I found that when directly testing flutter build .apk files, there are issues as there are different processor types armeabi-v7a (ARM 32-bit), arm64-v8a (ARM 64-bit), and x86-64 (x86 64-bit).
If you are testing locally I would recommend:
Building an app bundle using flutter build appbundle in
terminal.
Using the bundletool from the GitHub repository.
Generate a set of APKs from your app bundle.
Deploy the APKs to connected devices.
Source
I recently started working with flutter. I have been making several test applications. They all work well on emulators.
But now I want to be able to use them on my cell phone.
I took the APK that is generated when I run the application in the emulator, indicated in this route:
But it always fails to install
So far, my applications are simple, Hello world, Add numbers, etc.
Any ideas?
How should I do it correctly?
First: Open your Terminal/Shell/Command Line and open the directory of the Flutter App in there (cd PATH_TO_YOUR_FILE)
You probably want to create a profile-mode apk for testing. This build still helps debugging while having the speed of the --release version:
This creates a single APK which works on all devices (x64, arm64 and arm), it's probably pretty big:
flutter build apk --profile
If the people who install your App know which devices they have, you can use the split-per-abi command which creates three different APKs for all architectures (x64, arm64 and arm)
flutter build apk --profile --split-per-abi
If you want to have a release build, you can use what #Niteesh commented:
flutter build apk --release --split-per-abi
Release-builds can be uploaded to Google-Play (also the internal testing)
Read more: https://flutter.dev/docs/testing/build-modes
the apk that is generated when you run the app is the debug-apk, it contains lots of overheads which helps in flutter hot reload and hot restart. The size of debug apk version is also a lot.
use this command to generate release version of apk
flutter build apk --split-per-abi
After execution of the command, you get the path of the apk, something like this
√ Built build\app\outputs\flutter-apk\app-armeabi-v7a-release.apk (7.0MB).
Then you can install that apk on your phone
I'm attempting to create apk for my flutter app. It works when running flutter run on both emulator and device.
When running:
flutter build apk
Get success and apk. When copying apk to device it installs but then cannot be opened. (After install button to open is grayed out and finding app in app draw opens up the app info page). Have tired apk on multiple devices.
flutter run --release works
I've followed the steps to migrate to Androidx and have checked all packages build.gradle to ensure all are compileSdkVersion 28.
I've tried running on stable, master and beta flutter branch.
Running:
flutter build apk --release gives (on flutter beta branch)
You are building a fat APK that includes binaries for android-arm, android-arm64, android-x64.
If you are deploying the app to the Play Store, it's recommended to use app bundles or split the APK to reduce the APK size.
To generate an app bundle, run:
flutter build appbundle --target-platform android-arm,android-arm64,android-x64
Learn more on: https://developer.android.com/guide/app-bundle
To split the APKs per ABI, run:
flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi
Learn more on: https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split
Running Gradle task 'assembleRelease'... 2.8s
✓ Built build/app/outputs/flutter-apk/app-release.apk (21.2MB).
EDIT:
The plot thickens xD. I can launch the app from deeplinks, but using the app icon always launches into settings.
Add below code to
android\app\build.gradle
Inside android {
}
buildTypes {
release {
signingConfig signingConfigs.release
ndk {
abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
}
}
}
Turns out I had the package app availability installed which was using the compileSdkVersion of 27. Changing this to 28 in that package's build.gradle seemed to fix it.
The easiest solution was just to swap that package out.
I need to understand the Android device architecture and, Why there is three different types of APKs are generated when I use:
flutter build apk --split-per-abi.
And when I use
flutter build apk
I get a large APK file called fat APK contains the 3 versions of the app.
The command flutter build apk --split-per-abi typically generates two APK files.
arm64 or x86_64 is the apk file for devices having 64-bit processors.
x86 is the apk file for 32-bit processors.
You can upload both of them on the PlayStore and based on the user's device architecture the corresponding apk will be installed.
The fat apk that you are getting while using the flutter build apk contains the necessary compiled code to target all the Application Binary Interfaces or ABIs. Once a user downloads this fat apk, then only the code applicable to the device will be used.
flutter build apk gives you large apk because,
flutter build apk results in a fat APK that contains your code compiled for all the target ABIs. Such APKs are larger in size than their split counterparts, causing the user to download native binaries that are not applicable to their device’s architecture.
--split-per-abi results in two APK files:
(The flutter build command defaults to --release.)
<app dir>/build/app/outputs/apk/release/app-armeabi-v7a-release.apk
<app dir>/build/app/outputs/apk/release/app-arm64-v8a-release.apk
Where armeabi-v7a for is 32-bit devices and arm64-v8a for 64-bit devices.
Read More on
https://flutter.dev/docs/deployment/android#build-an-apk
https://flutter.dev/docs/deployment/android#build-an-app-bundle
https://developer.android.com/studio/build/configure-apk-splits#configure-split
Run flutter build apk --split-per-abi
This command results in three APK files:
<app dir>/build/app/outputs/apk/release/app-armeabi-v7a-release.apk
<app dir>/build/app/outputs/apk/release/app-arm64-v8a-release.apk
<app dir>/build/app/outputs/apk/release/app-x86_64-release.apk
Removing the --split-per-abi flag results in a fat APK that contains your code compiled for all the target ABIs . Such APKs are larger in size than their split counterparts, causing the user to download native binaries that are not applicable to their device’s architecture.
ABI means : Application Binary Interface
APK means : Android Package
app dir is your application’s directory
NOTE : If you can build an app bundle instead of apk , do it .With this, the application will be signed more easily .
By default, the app bundle contains your Dart code and the Flutter runtime compiled for armeabi-v7a (ARM 32-bit), arm64-v8a (ARM 64-bit), and x86-64 (x86 64-bit).
Remember that creating an App Bundle (an .aab file) is preferred over creating a fat APK or multiple APKs per abi. To assemble an App Bundle, run flutter build appbundle. The bundle will be created at build/app/outputs/bundle/release/app.aab
I am running one app on my Nexus 6P. But While I am using the Android Studio, its showing "No debuggable process detected". Although I am getting log messages from logcat. Why am I getting this problem?
I have few shared libraries .so files. while starting the apk it's telling me to debug this apk, I need to add debug symbols with this .so files.
How to assign debug symbols with this .so files?
The android build system is not really straight forward in this manner and part of it is due to gradle not being forceful with build types. By default gradle does not have build types like debug and release, the android plugin is the one that adds this by default.
The cmake native build builds debug and release variants correctly and puts them into the corresponding build type of the end result APK or AAR.
By default Android Studio builds debug builds, you have to explicitly change this to not have debug builds, so it's likely that you already have debug symbols.
One important thing is that for some reason android project linkages are still not fixed so if you have a linkage of Application that uses an Android Library then in reality it will link the library in release, regardless of the build type of the Application, see here : https://stackoverflow.com/a/20617949/2880011 this way it is possible to not have debug symbols for native code that is coming from the Android Library.
For prebuilts you have to make sure in the native build system that you link against the proper library, so in cmake you have to detect and link it accordingly, but even then the APK packager may ignore this and bundle the same variant for both debug and release.
Android Studio also has some prerequisites for native debugging see here : https://developer.android.com/studio/debug/index.html