gpt4 book ai didi

android - Flutter 本地通知导致崩溃,仅在 APK 版本中

转载 作者:行者123 更新时间:2023-12-03 13:25:38 25 4
gpt4 key购买 nike

我在 1.9 更新之前让这个应用程序工作,然后必须通过将 gradle 版本从 3.2.1 切换到 3.3.1 来解决构建失败

从那以后,对本地通知插件的任何非配置调用都会遇到此堆栈跟踪:

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).

我没有对正在运行的版本中的代码进行任何更改。
用于配置插件的代码在 init 上运行如下

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

并且对插件的调用是这样的:

  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
}

现在,有趣的是,只有在安装 apk 后才会发生崩溃。在使用 flutter 运行或调试运行的开发构建中,不会发生崩溃。

我尝试过的事情:
- 检查图标,因为消息提到可绘制。如果找不到图标,配置甚至不会运行。
  • 在调用周围使用 try/catch 捕获异常:异常直接通过
  • 检查通知权限,一切都很好,正如我所提到的,代码在更新之前工作
  • 调用是用正确的时间(小时和分钟)进行的,即使它们不是取消调用,仍然会使应用程序崩溃
  • 检查取消对没有预定通知的 id 的调用是否会崩溃,它没有在更新之前工作的版本上
  • 添加重要性、优先级和更改 channel 名称和 ID,没有奏效,此时变得绝望

  • 我觉得我缺少一些资源,有没有办法更全面地了解崩溃?

    最佳答案

    我遇到了同样的问题,这让我发疯了。它只发生在发布版本上,并且似乎与 AndroidInitializationSettings('app_icon')

    flutter_local_notifications Android 集成的文档部分说要添加

    -keep class com.dexterous.** { *; }

    到/android/app/proguard-rules.pro

    关于android - Flutter 本地通知导致崩溃,仅在 APK 版本中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58134023/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com