Flutter android alarm manager plus not working in release version

Viewed 55

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.

2 Answers

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 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:

  1. 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
  }
}
  1. 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

Related