Reputation: 506
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?
Upvotes: 12
Views: 6729
Reputation: 462
I have faced the same problem. I added the following line to the proguard-rules.pro -keep class com.dexterous.** { *; }
but nothing worked. Problem was that proguard-rules.pro file was located in the local notifications plugin library.
So I created a copy of this file in android/app
directory and finally it works. I have spent almost 2 days on this issue.
Do not forget to add the following code in res/raw/keep.xml
file to keep your icon resource for your notification file as shown here
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="@drawable/*,@raw/slow_spring_board" />
Upvotes: 4
Reputation: 51
If you export release apk format so after installed crash the app. You have to make these steps:
proguard-files.pro
file
Than you have to added bottom of the file this code## flutter_local_notification plugin rules
-keep class com.dexterous.** { *; }
buildTypes {
release {
signingConfig signingConfigs.release
// Enables code shrinking, obfuscation, and optimization for only
// your project's release build type.
minifyEnabled false
// Enables resource shrinking, which is performed by the
// Android Gradle plugin.
shrinkResources false
// Includes the default ProGuard rules files that are packaged with
// the Android Gradle plugin. To learn more, go to the section about
// R8 configuration files.
proguardFiles getDefaultProguardFile(
'proguard-android-optimize.txt'),
'proguard-rules.pro'
}
}
Upvotes: 5
Reputation: 53
Basically what you should do is:
-keep class com.dexterous.** { *; }
You can read more details about why to do this in the package documentation.
Upvotes: 1
Reputation: 41
i try to add:
-keep class com.dexterous.** { *; }
in proguard-rules.pro, but still got crash in APK version, and then i try to set false in
build.gradle
buildTypes {
release {
minifyEnabled false
shrinkResources false
}
}
and it works for me
Upvotes: 3
Reputation: 350
I had the same problem and these 2 changes works for me: (I'm building an appbundle)
1)
If you build an App Bundle Edit android/gradle.properties and add the flag:
android.bundle.enableUncompressedNativeLibs=false
If you build an APK Make sure android/app/src/AndroidManifest.xml doesn’t set android:extractNativeLibs=false
in the <application>
tag.
2)
flutter build appbundle --no-shrink
https://flutter.dev/docs/deployment/android#r8
Upvotes: 2
Reputation: 308
Setting minifyEnabled false
will disable your proguard!
you can add this rule -keepclassmembers enum * {*;}
to your /android/app/proguard-rules.pro to fix this problem.
Upvotes: 2
Reputation: 616
I had the same problem and it was driving me nuts. It only happens on a release build and appears to be related to AndroidInitializationSettings('app_icon')
The flutter_local_notifications docs section on Android Integration says to add
-keep class com.dexterous.** { *; }
to /android/app/proguard-rules.pro
Upvotes: 39
Reputation: 86
I have the exact same issue.
I used the following:
buildTypes {
release {
minifyEnabled false
}
}
Please note that this disables your proguard.
Upvotes: 3