i want to generate an .aab file from flutter project using this command
flutter build appbundle
💪 Building with sound null safety 💪
Removed unused resources: Binary resource data reduced from 1224KB to 1154KB: Removed 5%
Running Gradle task 'bundleRelease'... 47.8s
✓ Built build/app/outputs/bundle/release/app-release.aab (21.7MB).
to put it in play.google.com but i get this problem
You uploaded an APK or Android App Bundle that was signed in debug
mode. You need to sign your APK or Android App Bundle in release mode
so in the file android/app/build.gradle i did some modification
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.release
}
}
but i get the same problem the .aab is in debug mode and not in release mode how to do it to upload the application in play store ?
You need to sign the app and use the release version, not the debug.
Their web page explains how: https://docs.flutter.dev/deployment/android#signing-the-app
Related
I am fetching notifications from api in background using android alarm manager plus & is working fine in debug mode but not in release version.
I am using redmi note 7.
According to flutter doctor all is fine.
I ran into a same problem recently, couldn't really find help anywhere. I tried fixing it with help from this similar issue, but it didn't work for me (could've been doing something wrong). However, I found a temporary fix.
Running from cli (temporary fix)
If you are running the app from cli, use --profile flag instead.
flutter run --profile
Building an apk (temporary fix)
If you are building an apk, change the config to build the apk in profile mode and then sign the apk as if it was in release mode.
In android/app/build.gradle:
Inside buildTypes duplicate the "release" block and rename it to "profile". It should look something like this:
buildTypes {
release {
signingConfig signingConfigs.release
}
profile {
signingConfig signingConfigs.release
}
}
Then, build the apk in the profile mode:
flutter build apk --profile
Note that the desired apk is now called app-profile.apk.
Explanation
Flutter somehow changed the way build modes work. From what I understand, the android_alarm_manager libraries/plugin is not included in the release apk. You probably have to fix that using proguard, but I'm not sure how. Please note that building the apk in profile mode is not correct, but works as a temporary fix. I hope that someone more experienced can help us find the correct solution.
Hope this helps!
Regards, Honza
Do you have Internet permission to fetch data from the api? Check the AndroidManifest. Internet permission is set in debug mode, but removed in release. You have to set it manually.
<manifest xmlns:android...>
...
<uses-permission android:name="android.permission.INTERNET" />
<application ...
</manifest>
I was creating APK for my flutter project so I followed the below steps to generate a signed APK
Tools -> Flutter -> Open for editing in android studio
Then opened the model in a new window
I got the Gradle sync failed error, After my further investigation I run the command gradlew --warning-mode all in the terminal & I got the below message from gradle
The AbstractArchiveTask.destinationDir property has been deprecated. This is scheduled to be removed in Gradle 7.0. Please use the destinationDirectory property instead.
I also tried org.grdle.wranning=(all,summary,fail,none)
In order to generate a signed APK you don't necessarily have to open your Android project as you described in your issue.
The steps you have to follow are :
1- Create your keystore.
2- Plug this keystore with the android/app/build.gradle file
3- Enable the signing in your release buildType in the android/app/build.gradle file
buildTypes {
release {
signingConfig signingConfigs.release
}
}
This is just an overview of the steps you have to follow.
The full procedure with examples in available on the official docs.flutter.dev website
Don't worry too much about the warning. It only means that you some of the methods used in your build.gradle will be deprecated soon.
I have apk of Flutter having size around 700MB (app has local videos, assets). I have uploaded testflight easily as Apple allows 4GB IPA file. Now to handle this issue on Google play console flutter recommend Deferred components
I followed the official documentation but on last step when I run flutter build appbundle
command with signing configuration
buildTypes {
release {
signingConfig signingConfigs.debug
}
}
differed components are separated from base apk , thats good.
but with
buildTypes {
release {
signingConfig signingConfigs.release
}
}
resulting in a deferred library being compiled as part of the base loading unit.
Any help would be appreciated.
i need upload my release apk generated by flutter to the Google play store. When i run "flutter build apk --release" the response is and apk but the size is 21MB(Based in the documentation is a FAT apk that includes all abi's apk).
javier.hospital#COBOADM-UD-P01 Flutter-APP-BODYTECH % flutter build apk --release
Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 20,5s
✓ Built build/app/outputs/flutter-apk/app-release.apk (21.9MB).
I found out othe command "flutter build apk --split-per-abi", this commands generate 3 apks with 8mb size. I think that is a good option beacause i need that the size of my application are small.
javier.hospital#COBOADM-UD-P01 Flutter-APP-BODYTECH % flutter build apk --split-per-abi
Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 12,7s
✓ Built build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk (8.4MB).
The problem is when i try sign any of this 3 apks, it's not possible to sign an the code error is "jarsigner: unable to sign jar: java.util.zip.ZipException: invalid entry compressed size (expected 5654 but got 5205 bytes)".
My question is that when i upload the first apk (21MB) to google play, the user download only 8mb apk?. or is neccesary upload 3 abi apks for the user to download only 8 mb?
In which case it is so, what way is there to sign an apk generated only for a specific abi?.
Thanks for your help!
Uploading the App bundle is the recommended method by Google.
I always use the App bundle to upload my Apps to the playstore.
My question is that when i upload the first apk (21MB) to google play,
the user download only 8mb apk?
Yes the user only has to download an 8MB file
Read More about App bundle here https://developer.android.com/platform/technology/app-bundle
I am a native Android developer and I started using flutter SDK. I developed a simple app by following official flutter doc. But I found that the debug app size is 46 MB which is too large for this simple app. Is there any way to optimize the app size? because Flutter app size is larger than the native Android App.
Flutter debug app is very big, to optimize the app you should build it as release version by using
flutter build apk (flutter build defaults to --release).
Preparing an Android App for Release
Preparing an iOS App for Release
There are many possibilities:
First , build your application in release mode by using :
In your terminal :
flutter build --release
or just specify the target :
For Android Apk : flutter build apk --release
For Android App Bundle: flutter build app bundle --release
For IOS : flutter build ios --release
By default, flutter run compiles to debug mode .This explains the
large size of the application . Debug mode (Hot reload , Dart Devtools etc ..) vs Release Mode (Simple Application)
By default flutter build build for release mode . So you can just do flutter build
Using --split-debug-info flag can dramatically reduce code size. For an example of using this flag, see Obfuscating Dart code.
Some of the other things you can do to make your app smaller are:
Remove unused resources
Minimize resource imported from libraries
Compress PNG and JPEG files
Your can learn more about flutter app size here
To Decrease/Optimise the App Size
Step 1: Compress assets all assets (Example: using tinypng or any other option)
Step 2: Delete unused resource
You can easily search for unused resources from Android Studio. Just press Ctrl + Alt +Shift + i and type "unused resources" (without quotes). That will execute lint. Super easy way to run lint commands (and other stuff from IDE).
OR
In Android Studio Menu > Refactor > Remove Unused Resources...
Select the resources you want to remove. You can exclude resources you want to keep by right-clicking on the resource item.
Use Do Refactor to remove all Resources at once.
Update: use ⌘ +Option +Shift + i for mac
Step 3: Put this code in app/build.gradle
Refer to this link to know more about android ABIS
(https://developer.android.com/ndk/guides/abis)
///Note: only working build release app ( cause debug run issue so comment it while run in debug mode )
android {
defaultConfig {
minSdkVersion 19
.....
//comment this code while app is in debug mode
ndk {
abiFilters "armeabi", "armeabi-v7a","arm64-v8a"
}
}
}
Step 4: Remove unused plugins from pubspec.yaml
Step 5: Build Your App Bundle using the following command
flutter build appbundle
flutter build appbundle --target-platform android-arm,android-
arm64,android-x64
For More
You can Use Proguard Rules
buildTypes {
release {
minifyEnabled true // add this
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' // add this
signingConfig signingConfigs.release // this is default for release
}
}
in the android main directory, you are able to find proguard-rules.pro if not then new-> file -> proguard-rules.pro create this file
Put this code in that file and also appropriate rules of plugins you have added in your pubspec.yaml
Note: Add all proguards which is required by plugin otherwise android app will not work properly
## Flutter wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }
# -keep class com.google.firebase.** { *; } // uncomment this if you are
using firebase in the project
-dontwarn io.flutter.embedding.**
-ignorewarnings
Also go to your gradle.properties and add :
extra-gen-snapshot-options=--obfuscate
in your app/build.gradle
buildTypes {
release {
minifyEnabled true // added previously
shrinkResources true // add this
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro' // added previously
signingConfig signingConfigs.release // added previously
}
}
Another Command for build app
Old Apk with
flutter build apk --release
New Apk With
flutter build apk --split-per-abi
TO REDUCE APK SIZE:
If you are building android apk or bundle, then make sure you are considering
Minify
Proguard
Some common things to keep in mind
clean codes
remove unused plugins
remove unused assets
remove unused fonts etc.
Try this,
flutter build apk --split-per-abi
Follow the official doc - https://flutter.dev/docs/perf/app-size
Some of the obvious things you can do to make your app smaller are:
Remove unused resources
Minimize resource imported from libraries
Support a limited number of screen densities
Compress PNG and JPEG files
Android Studio includes an APK Analyzer that provides immediate insight into the composition of your APK or Android App Bundle after the build process completes. Using the APK Analyzer can reduce the time you spend debugging issues with DEX files and resources within your app, and help reduce your APK size. It's also available from the command line with apkanalyzer.
Open the project:
Drag an APK or app bundle into the Editor window of Android Studio.
Switch to the Project perspective in the Project window and then double-click the APK in the default build/output/apks/ directory.
Select Build > Analyze APK in the menu bar and then select your APK or app bundle
There's an explanation for this: https://developer.android.com/studio/command-line/apkanalyzer