Flutter local notification causing crash, only in the APK version

Question

Asked by Lucas M on September 27, 2019 (source).

I had this app working before the 1.9 update, then a failure to build had to be worked around by switching the gradle version from 3.2.1 to 3.3.1

Ever since, any non-configuration calls to the local notification pluggin are met with this stacktrace:

E/flutter (22738): [ERROR:flutter/shell/platform/android/platform_view_android_jni.cc(39)] java.lang.AssertionError: java.lang.NoSuchFieldException: Drawable
E/flutter (22738):      at c.a.a.b.a.ja$a.<init>(:12)
E/flutter (22738):      at c.a.a.b.a.V.a(:5)
E/flutter (22738):      at c.a.a.p.a(:18)
E/flutter (22738):      at c.a.a.b.a.p.a(:21)
E/flutter (22738):      at c.a.a.b.a.p.a(:37)
E/flutter (22738):      at c.a.a.b.a.p.a(:17)
E/flutter (22738):      at c.a.a.p.a(:18)
E/flutter (22738):      at c.a.a.b.a.c.a(:5)
E/flutter (22738):      at c.a.a.p.a(:18)
E/flutter (22738):      at c.a.a.p.a(:96)
E/flutter (22738):      at c.a.a.p.a(:86)
E/flutter (22738):      at c.a.a.p.a(:84)
E/flutter (22738):      at com.dexterous.flutterlocalnotifications.d.e(:7)
E/flutter (22738):      at com.dexterous.flutterlocalnotifications.d.a(:49)
E/flutter (22738):      at com.dexterous.flutterlocalnotifications.d.a(:157)
E/flutter (22738):      at com.dexterous.flutterlocalnotifications.d.b(:40)
E/flutter (22738):      at com.dexterous.flutterlocalnotifications.d.a(:132)
E/flutter (22738):      at d.a.b.a.m$a.a(:2)
E/flutter (22738):      at io.flutter.embedding.engine.a.c.a(:14)
E/flutter (22738):      at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(:2)
E/flutter (22738):      at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter (22738):      at android.os.MessageQueue.next(MessageQueue.java:326)
E/flutter (22738):      at android.os.Looper.loop(Looper.java:160)
E/flutter (22738):      at android.app.ActivityThread.main(ActivityThread.java:6762)
E/flutter (22738):      at java.lang.reflect.Method.invoke(Native Method)
E/flutter (22738):      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/flutter (22738):      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/flutter (22738): Caused by: java.lang.NoSuchFieldException: Drawable
E/flutter (22738):      at java.lang.Class.getField(Class.java:1601)
E/flutter (22738):      at c.a.a.b.a.ja$a.<init>(:6)
E/flutter (22738):      ... 26 more
E/flutter (22738): 
F/flutter (22738): [FATAL:flutter/shell/platform/android/platform_view_android_jni.cc(76)] Check failed: CheckException(env). 

I made no changes to the code from the version that was working. The code used to configure the plugin is ran on init as follows

  void inicializarPluginNotificacoes() {
    flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
    var initializationSettingsAndroid = new AndroidInitializationSettings('@drawable/app_icon24');
    var initializationSettings = new InitializationSettings(initializationSettingsAndroid, null);
    flutterLocalNotificationsPlugin.initialize(initializationSettings, onSelectNotification: onSelectNotification);
  }

and the call to the plugin is made like this:

  Future marcarNotificacao(int id, int hora, int minuto, String texto, String titulo) async {
    var scheduledNotificationDateTime = new DateTime.now().add(new Duration(hours: hora, minutes: minuto));
    var androidPlatformChannelSpecifics = new AndroidNotificationDetails('ponto_unb', 'Ponto', 'Notificações para o ponto eletrônico');
    NotificationDetails platformChannelSpecifics = new NotificationDetails(androidPlatformChannelSpecifics, null);
    await flutterLocalNotificationsPlugin.cancel(id); // crashes
    await flutterLocalNotificationsPlugin.schedule(id, titulo, texto, scheduledNotificationDateTime, platformChannelSpecifics); // also crashes if the other one is not called first
  }

Now, the intresting thing is, the crash only takes place after installing the apk. On a development build with flutter run or a debug run the crash doesn't happen.

Things i've tried: - Checking the icon since the message mentions drawable. The configuration doesn't even run if the icon is not found.

  • Catching the exception with a try/catch around the call: the exception goes right through

  • Checking notification permissions, its all fine, as i mentioned, the code was working prior to the update

  • The calls are made with corect times ( hours and minutes ), and even if they weren't the cancel call still would crash the app

  • Check if the cancel call to an id without scheduled notifications would crash, it didn't on the version that worked prior to the update

  • adding importance, priority and changing the channel name and id, didn't work, was getting desperate at this point

I feel like there is some resource i'm missing, is there a way to obtain a more comprehensive look into the crash?

Answer

Question answered by José D (source).

I have the exact same issue.

I used the following:

buildTypes {
        release {
           minifyEnabled false
}
    }

Please note that this disables your proguard.

ANDROID FLUTTER
SHARE: