Flutter android alarm manager plus not working in release version - flutter

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>

Related

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.

How to enable Multidex inside flutter which is added to existing android project as module

I have and android project, which I added flutter on it as module,
In my original android app, multidex is enabled, but this do not help me, when running the app in debug it's working normally, but when creating a release apk or even debug apk the FlutterFragment is appearing as white, like the engine did not attach.
Things I notice, 'flutter run --release' will ask me to support multidex, and will not run, updating the minSdkVersion to 21 and enabling multidex in .android/app/build.gradle then again 'flutter run --release' works perfect, but this have no effect on the host app because it's under .android which automatically build, and ignored by the host app.
Also I tried to search for how to update minSdkVersion to 21 instead of 16, but references lead to change in the .android which have no effect.
Hey you can do two thing
Update your flutter SDK version by running command
flutter upgrade
The new version of flutter(2.10) multidex support automatically.
simply pass the --multidex flag to flutter build appbundle or flutter build apk and your app will support multidex.
2.In your app folder inside android [project_folder]/app/build.gradle and add following lines.
defaultConfig {
...
multiDexEnabled true
}
and
dependencies {
...
implementation 'com.android.support:multidex:1.0.3'
}
After a lot of investigation, the reason was related to something in the entry point, which needed to add project name, referring to this link

Flutter build release apk with no sound null safety?

Debug apk works fine, release apk not working..
Tried flutter build apk --no-sound-null-safety it builds release apk but does not works.
Issue Solved!!
Actually, the problem was with 'http' as SSL certificate was not included for the admin panel hence, app showed
Bad state: Insecure HTTP is not allowed by platform error in some devices while it was running in my Mi note4 mobile phone.
Added
android:usesCleartextTraffic="true" line in
AndroidManifest.xml file inside
<manifest <application android:usesCleartextTraffic="true""> </application> </manifest> tag
The ability to mix language versions frees package maintainers to migrate their code, with the knowledge that even legacy users can get new bug fixes and other improvements. However, mixed-version programs don’t get all the advantages that null safety can bring. Read here
Solution
Code for building APK:
flutter build apk --no-sound-null-safety

How to debug what's wrong if app crashes only in release mode

I upgraded Flutter to 2.0.0 recently and am stuck with this issue. flutter run and flutter run --profile work perfectly well, but flutter run --release makes app crash after startup. There is no stacktrace, there is no error or warning, there is no build issue or verbose warning, no hint really. I googled a lot, but similar questions were answered like "try to remove this line" or "try to add that line". I couldn't find any clear steps on how to debug what's wrong.
What steps should I take to debug this issue and find the root cause instead of trying meaningless changes on code hoping some of them will eventually fix the issue?
Use adb logcat
OR
Enable debugging in release build, by modifying your android/app/build.gradle
like this
buildTypes {
release {
debuggable true
shrinkResources false
minifyEnabled false
...
}
}
When the error is code related and not in flutter itself sentry should help.
Sentry's Flutter SDK enables automatic reporting of errors, messages,
and exceptions.
You can import it just as any other package
dependencies:
sentry_flutter: ^4.0.6
and configure it as early as possible in you app
import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
await SentryFlutter.init(
(options) => options.dsn = 'put_your_public_key_here',
appRunner: () => runApp(MyApp()),
);
}
To get your public key you just have to sign up on sentry.io and create a flutter project, no need to search for your key your it should be in the example code, it wont let you pass that point without initialiting it so you can't miss it.
The docs regarding flutter can be found here.
You can Use Firebase Analytics to see error logs from your released devices from firebase. Previously it was named as Fabric.
Or you can create your own log tracker, write the logs in a file and upload the log to your server.
You can give options to user to capture log and send to server within "Advanced Settings" or something like that.
try this flutter run --release --no-shrink
Check if you have given correct permission to the app in AndroidManifest.xml, in my case I simply fixed this issue by giving camera permission
<uses-permission android:name="android.permission.CAMERA" />
before the tag
In my case, after two day of confusion because app crashes only in release mode without any error on console, and errors shown in adb logcat not clear (unknown errors), after that I switching Flutter channel from stable to master, after run release on master channel errors started shown as clear messages, I solved these errors then crashes problem solved.
So my steps is:
1- Switching Flutter channel to master by run this command in terminal:
flutter channel master
2- Run upgrade command in terminal:
flutter upgrade
3- Run app as release:
flutter run --release
4- Watch console to see errors...

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