this Eror happen in Generated signed apk - flutter

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.

Related

Flutter android alarm manager plus not working in release version

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>

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

Flutter Gradle task assembleDebug failed with exit code 1 zip END header not found

Hello I am new to Flutter I have setup flutter with android studio 4.2.1, and every thing is fine. When I try to run it; it show me following error
I see too much questions but it is not helpfull for me
flutter doctor run no issue found
Hers is doctor result
Here is my enviroment variable
can any one guide me how can I run the flutter. I am lunching it in a chrome
exception in thread "main" java.util.zip.ZipException: zip END header not found at
java.base/java.util.zip.ZipFile$Source.zerror(ZipFile.java:1567) at
java.base/java.util.zip.ZipFile$Source.findEND(ZipFile.java:1462) at
java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1469) at
java.base/java.util.zip.ZipFile$Source.(ZipFile.java:1274) at
java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1237) at
java.base/java.util.zip.ZipFile$CleanableResource.(ZipFile.java:727)
at
java.base/java.util.zip.ZipFile$CleanableResource.get(ZipFile.java:844)
at java.base/java.util.zip.ZipFile.(ZipFile.java:247) at
java.base/java.util.zip.ZipFile.(ZipFile.java:177) at
java.base/java.util.zip.ZipFile.(ZipFile.java:191) at
org.gradle.wrapper.Install.unzip(Install.java:214) at
org.gradle.wrapper.Install.access$600(Install.java:27) at
org.gradle.wrapper.Install$1.call(Install.java:74) at
org.gradle.wrapper.Install$1.call(Install.java:48) at
org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
at org.gradle.wrapper.Install.createDist(Install.java:48) at
org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
at
org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
Exception: Gradle task assembleDebug failed with exit code 1
I recently Solved this problem.
This Problem came from gradle file is corrupted in my system.
I'm using Linux so this steps almost same in windows also. This answer is for any gradle version.
Open File Manager:
enable Show hidden folder from top menu bar.
You may find this location : .gradle>wrapper>dists.
In Linux: Home > .gradle > wrapper > dists.
In Windows: C:>Users>{PC Name}>.gradle>wrapper>dists
Method 1
Go inside gradle-6.5-all > dists > 2oz4ud9k3tuxjg84bbf55q0tn. '2oz4ud9k3tuxjg84bbf55q0tn' may be different in your PC.
Delete all files in that folder and download required file manually: https://downloads.gradle-dn.com/distributions/gradle-6.5-all.zip
after download paste freshly downloaded zip file in that folder.
Run your project flutter run -v
Method 2
Try this if you have fast & stable internet connection.
Delete that gradle-6.5-all folder.
Open project in VS code or Android Studio and open terminal.
Run this command flutter run -v
Method 3
Flutter Doctor will give right result.
Open Android Studio
Create new flutter project
Click on Tools > flutter >Flutter for editing in android studio
and wait, flutter doctor takes time to identify problem.
Use this link for download gradle file.
Replace 6.5 with your gradle version.
https://downloads.gradle-dn.com/distributions/gradle-6.5-all.zip
I hope this answer helpful for you.
Please use the below command
1.Mac User :
rm -rf ~/.gradle
2.Windows User :
remove the .gradle file
.gradle file location -> C:\Users\myUser
I solve this error by updating the gradle plugin/version. I have as part of my configuration:
Windows 10
Android Studio 4.2.1
Java 11: Android Studio 4.2.1 don't have support for JDK 16, so, I installed JDK 11, and configured the AS (how to change the jdk in AS) to use this older JDK
Gradle 7.0.1
By default, when you create a new Flutter project, the IDE created it with basic standard configurations, so you have to change this configs to fit your current config. For that, you need to update the gradle config in the flutter project, as follow:
in android/gradle/build.gradle file: update the gradle plugin to 4.2.0 in the dependencies section, like this:
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0'
//more dependencies
}
in android/gradle/wrapper/gradle-wrapper.properties file: update the gradle version, in this case I have the 7.0.1, feel free to use another one, like this
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.1-all.zip
//more attributes
After you change the gradle config, run this commands in your project:
flutter clean : clean the project
flutter pub get : update your dependencies
flutter run : run the project. Now it must work, at least it work for me
I faced the same problem in VSCode when I wanted to run the Flutter app I got that error, so after lots of debugging and research, I found the solution. it's pretty easy, just follow these steps:
In windows 10:
1. Open flutter project in a Text-Editor like VSCode.
2. Open android -> gradle -> wrapper -> gradle-wrapper.properties
3. You will find "gradle-6.7.1.all.zip" inside gradle-wrapper folder
4. Go to this path: C:\Users\your-user
5. Then go to the wrapper->dists and find "gradle-6.7.1.all" folder
5. Delete this folder.
6. Then come to VSCode and open Terminal.
7. Please make sure that you have stable internet connection then type this command in terminal
8. flutter run
I hope this solution can help you!
I solve this error by deleting the .gradle folder.
This location is gradle folder
In Windows: C:> Users> {PC Name}>. Gradle
After deleting this folder, you only need to run the application again in Android Studio. At this point, Android Studio starts downloading the deleted folder automatically.
enter image description here
This error is caused by corrupted gradle files, this is either due to incomplete downloads due to network issues. To solve it easily download the gradle zipped file from https://downloads.gradle-dn.com/distributions/gradle-6.7-all.zip and paste on the .gradle directory as shown below if you are on linux
enter image description here
I try all method but it did not work for me so i decided to location the gradle-wrapper.properties in the andriod folder then i change the distribution gradle link to a more recent gradle link.
Welcome SO.
Java 16/latest version is not fully compatible with the Gradle 6 at this moment. Try to use java 11 or 8, it will resolve your issue.

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

Ionic and Crosswalk Can’t Generate Signed APK

I am trying to add crosswalk to my ionic. My apps are launched and working fine. However after I added Crosswalk, I can't generate signed apks anymore. I tried to remove crosswalk and it works again. How did you guys manage to get it working?
Here's what I did:
cordova plugin add cordova-plugin-crosswalk-webview
cordova platform add android
ionic build android
it builds fine except:
BUILD SUCCESSFUL
Total time: 1 mins 34.909 secs
Built the following apk(s):
<--- this part is empty, usually it'll show the path of the apk generated
In Android Studio I get this error for the gradle sync.
NDK integration is deprecated in the current plugin.
When I try to generate signed apk, I get this error:
Missing Gradle Project Information. Please check if the IDE successfully synchronized its state with the Gradle Project Model.
I tried cordova platform add android#4.1, instead of using latest one. And I was able to build it with sdk 22.
However when I try to publish, I'm getting this problem.
It is forbidden to downgrade devices which previously used M permissions (target SDK 23 and above) to APKs which use old style permissions (target SDK 22 and below). This occurs in the change from version 103098 (target SDK 23) to version 104004 (target SDK 22).
The steps I followed to get signed apk is as-
open terminal and go to android file
$ cd projectDir/platforms/android
and run this command to generate digital signature
$ keytool -genkey -v -keystore exampleapp.keystore -alias example -keyalg RSA -keysize 2048 -validity 10000
# This will create a file in you "projectDir/platforms/android" directory with a name of exampleapp.keystore which will have digital signature.
# Now Create a file with name of release-signing.properties here in
projectDir/platforms/android directory.
# Provide details to this file about your signature.
*# signed apk details
storeFile=exampleapp.keystore
keyAlias=mindfull
storePassword=password
keyPassword=password*
Go to terminal and exit to main project directory by typing
$ cd ../..
Run this command to build signed apk.
$ cordova build android --release
this will run many task and show something like this-
Now you can upload this apk on play store and share with your friend.
Have a nice day !!!
For more you can see here
https://randvblog.wordpress.com/2016/07/04/generate-signed-apk-for-android-using-gradle-for-cordova-6-0-0-in-ionic/