plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

[Question]: Alarm Manager Plus Not Working on Release App

Open bakteribaik opened this issue 1 year ago • 3 comments

What is your question?

so i made an app that uses alarm manager to play audio at a set time. but I just realized that my alarm manager can't run in the release version of the app, but in debug mode the alarm manager runs fine. is there a solution for this problem?

I have followed the instructions from the documentation for the installation

Plugin version : android_alarm_manager_plus: ^2.0.6


flutter doctor -v

[√] Flutter (Channel stable, 3.3.0, on Microsoft Windows [Version 10.0.19042.1889], locale en-ID) • Flutter version 3.3.0 on channel stable at C:\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision ffccd96b62 (3 weeks ago), 2022-08-29 17:28:57 -0700 • Engine revision 5e9e0e0aa8 • Dart version 2.18.0 • DevTools version 2.15.0

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0) • Android SDK at D:\ProgramFiles\AndroidSDK • Platform android-33, build-tools 33.0.0 • Java binary at: D:\ProgramFiles\AndoridStrudio\jre\bin\java • Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822) • All Android licenses accepted.

[√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[!] Visual Studio - develop for Windows (Visual Studio Build Tools 2017 15.9.50) • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools • Visual Studio Build Tools 2017 version 15.9.28307.2094 • Windows 10 SDK version 10.0.17763.0 X Visual Studio 2019 or later is required. Download at https://visualstudio.microsoft.com/downloads/. Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2021.1) • Android Studio at D:\ProgramFiles\AndoridStrudio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)

[√] VS Code (version 1.71.2) • VS Code at C:\Users\root\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.48.0

[√] Connected device (4 available) • Redmi Note 5 (mobile) • 8c21d01 • android-arm64 • Android 9 (API 28) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19042.1889] • Chrome (web) • chrome • web-javascript • Google Chrome 105.0.5195.102 • Edge (web) • edge • web-javascript • Microsoft Edge 105.0.1343.33

[√] HTTP Host Availability • All required HTTP hosts are available

! Doctor found issues in 1 category.

bakteribaik avatar Sep 17 '22 14:09 bakteribaik

2.0.7 was released days ago with a patch for that. Can you try it and report back?

miquelbeltran avatar Sep 17 '22 19:09 miquelbeltran

2.0.7 was released days ago with a patch for that. Can you try it and report back?

yes, I've tried with the latest version. but the result is still the same, if the alarm manager is not running in the release build. I think this problem came after I updated flutter to 3.3.0, because in the previous version, the alarm manager worked fine in the release build. I haven't tried downgrading the flutter version yet, I'll try and report the results later

bakteribaik avatar Sep 18 '22 03:09 bakteribaik

ok, so this is my update, so i tried downgrading flutter to v.3.0.5 and alarm manager runs fine in the release build.

so alarm manager is not running on flutter v.3.3.0, and running on v3.0.5. but i still haven't tried on the latest flutter version yet. maybe someone else will try it later because I will stick with v.3.0.5 first

bakteribaik avatar Sep 18 '22 08:09 bakteribaik

I've got the same problem - no alarms are fired with Flutter 3.3.2 and android_alarm_manager_plus: 2.0.7 Debug builds are working on emulator (API level 30 and 33) and on Pixel 4a (Android 13)

However the release build of the same source code does not run oneShot callback as it should despite true value is returned.

I downgraded Flutter version to 3.0.5 and alarm manager package 2.0.6. The alarm manager notifications are working now.

oleksabor avatar Sep 25 '22 18:09 oleksabor

I have the same issue on 2.0.7+1. Flutter 3.3.4.

Doing --profile builds as a stop-gap.

chrisfraser avatar Oct 12 '22 10:10 chrisfraser

After doing some research found out that users of the plugin also need to add @pragma('vm:entry-point') annotation to the callback function in the app which uses the plugin.

Check #1229 for more info on related issues.

vbuberen avatar Oct 13 '22 09:10 vbuberen

Flutter has no help all documentation is a crap

hassan-hasy avatar Dec 16 '22 19:12 hassan-hasy

I was also facing the same issues on Flutter 3.3.4, as my app was running fine in Debug mode on my physical device: Oneplus Nord but not working in release mode. So I tried this code:

@pragma('vm:entry-point')
void printHello() {
  final DateTime now = DateTime.now();
  final int isolateId = Isolate.current.hashCode;
  print("[$now] Hello, world! isolate=${isolateId} function='$printHello'");
  Vibration.vibrate();
}

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await AndroidAlarmManager.initialize();
  runApp(const MyApp());
  const int helloAlarmID = 0;
  await AndroidAlarmManager.periodic(
      const Duration(minutes: 1), helloAlarmID, printHello);
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Alarm Manager',
      home: Scaffold(body: Text('Hey There!')),
      theme: ThemeData(
        useMaterial3: true,
      ),
    );
  }
}

and this worked just fine in release/build mode.

rajesh6161 avatar Feb 06 '23 05:02 rajesh6161

don't forget to add:

 @pragma('vm:entry-point')

rajesh6161 avatar Feb 06 '23 05:02 rajesh6161

After doing some research found out that users of the plugin also need to add @pragma('vm:entry-point') annotation to the callback function in the app which uses the plugin.

Check #1229 for more info on related issues.

your hint solve my problem. i stuck in problem last 3 days.

saeed45065 avatar Mar 18 '23 20:03 saeed45065