Derffered component not splitting apk when signed with release configuration - flutter

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.

Related

Flutter bluetooth.It doesn't give me real devices

Hi everybody I'm trying to use flutter_blue in my app.For this ı use this github project.https://github.com/pauldemarco/flutter_blue/blob/master/example/lib/widgets.dart. However when ı run this in my emulator it gives me 2 devices which are gDevice-beacon it didn't give me real devices.How can ı solve this.
You must run your app in your real phone.How can you think your emulator can show real device when your turn on bluetooth :).
Try this in build.gradle file in app:
buildTypes {
release {
signingConfig signingConfigs.release
shrinkResources false // this line
minifyEnabled false // this line
}
}
You can also try building the apk by :
flutter build apk --no-shrink

how to generate .aab from project flutter

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

this Eror happen in Generated signed apk

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.

MissingPluginException in flutter in release mode android

Many plugins aren't working in flutter when you try to build a apk in release mode , but these plugins are working perfectly in debug mode
Some recomend changing the gradle version to 3.5 , but sometimes the plugins used may not be compatible with the same like file_picker_cross
Others recomend using --no-shrink option while building the apk i.e flutter build apk --release --no-shrink
None of that solutions worked for me , i found this solution burried in a github issue conversation
Check the solution below
Looks like the recent proguard rules in flutter is ejecting the plugins which arent registering properly
In your project's app/build.gradle
change
buildTypes {
release {
signingConfig signingConfigs.release
}
}
to
buildTypes {
release {
shrinkResources false
minifyEnabled false
signingConfig signingConfigs.release
}
}
The added extra 2 lines seems to skip the proguard rules part thereby saving your from the nightmare , this is just a temporary work around , there might be a fix soon from flutter
Ofcourse this skips the proguard optimization , but atleast the code works now ;)
I have been wasting my time for almost 6 hours without knowing the solution ,so I am posting it here for others

How to optimize the Flutter App size?

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