首页 > 解决方案 > Flutter - 本地通知在发布模式下失败

问题描述

我添加了flutter_local_notifications插件来安排通知。在调试版本中,一切都适用于模拟器和真实设备

但是,当我构建应用程序时

flutter build apk --split-per-abi

并在设备上安装包并运行应用程序,当涉及标记通知的代码部分时(我想......),应用程序崩溃

我如何找出问题所在?

我按照插件开发人员的说明更改了清单文件:

                    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                        package="com.example.explika">

                        <uses-permission android:name="android.permission.INTERNET" />

                        <!-- Tudo relacionado com as notificações -->
                        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
                        <uses-permission android:name="android.permission.VIBRATE" />
                        <!-- Fim relacionado com notificações -->

                        <!-- io.flutter.app.FlutterApplication is an android.app.Application that
                            calls FlutterMain.startInitialization(this); in its onCreate method.
                            In most cases you can leave this as-is, but you if you want to provide
                            additional functionality it is fine to subclass or reimplement
                            FlutterApplication and put your custom class here. -->
                        <application
                            android:name="io.flutter.app.FlutterApplication"
                            android:label="Explika"
                            android:icon="@mipmap/ic_launcher">
                            <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
                            <activity
                                android:name=".MainActivity"
                                android:launchMode="singleTop"
                                android:theme="@style/LaunchTheme"
                                android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
                                android:hardwareAccelerated="true"
                                android:windowSoftInputMode="adjustResize">
                                <!-- This keeps the window background of the activity showing
                                    until Flutter renders its first frame. It can be removed if
                                    there is no splash screen (such as the default splash screen
                                    defined in @style/LaunchTheme). -->
                                <meta-data
                                    android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                                    android:value="true" />
                                <intent-filter>
                                    <action android:name="android.intent.action.MAIN"/>
                                    <category android:name="android.intent.category.LAUNCHER"/>
                                </intent-filter>
                            </activity>
                        </application>
                    </manifest>

标签: flutter

解决方案


我发现了导致应用程序崩溃的原因:

[错误:flutter / shell / platform / android / platform_view_android_jni.cc (39)] java.lang.AssertionError: java.lang.NoSuchFieldException: Drawable

但是,这只发生在发布版本中。该解决方案包括按照插件页面上的说明自定义 ProGuard 配置文件和 build.gradle 文件。我没有执行这些步骤,因为在那之前发布版本没有问题,而且我认为 ProGuard 配置文件只有在想在 Play Store 上发布时才需要。


推荐阅读