You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter适配Android 12时android:exported配置异常求助

解决Flutter适配Android 12(API 31+)的ADB安装失败问题

问题场景

开发Flutter应用适配Android 12(API 31+)时,已为MainActivity设置android:exported="true",清理缓存并重启Android Studio后,在Android 12模拟器安装应用仍报错。

报错信息

Error: ADB exited with exit code 1
Performing Streamed Install

adb: failed to install E:\mobileapp\build\app\outputs\flutter-apk\app.apk: Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/vmdl279592420.tmp/base.apk (at Binary XML file line #186): com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver: Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present]
Error launching application on sdk gphone64 x86 64.

问题原因

Android 12(API 31+)强制要求:所有包含intent filter的组件(Activity、Receiver、Service等)必须显式声明android:exported属性。本次报错中的ScheduledNotificationBootReceiver来自flutter_local_notifications插件,该插件旧版本未适配API 31+,其Manifest中未为该Receiver设置android:exported,导致合并到应用最终Manifest时触发校验失败。

解决方案

在项目的AndroidManifest.xml的<application>标签内,手动添加该Receiver并显式设置android:exported="true":

</activity>
<!-- 新增以下Receiver配置 -->
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver"
    android:exported="true">
</receiver>

修复后的完整Manifest示例

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

    <queries>
        <intent>
            <action android:name="android.intent.action.SENDTO" />
            <data android:scheme="mailto" />
        </intent>
    </queries>

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

    <application
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="MY LABEL">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:windowSoftInputMode="adjustResize">
            <meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme" />
            <meta-data
                android:name="io.flutter.embedding.android.SplashScreenDrawable"
                android:resource="@drawable/launch_background" />
            <meta-data
                android:name="com.google.firebase.messaging.default_notification_channel_id"
                android:value="my_high_importance_channel" />

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <!-- 新增的Receiver -->
        <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver"
            android:exported="true">
        </receiver>
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

内容的提问来源于stack exchange,提问作者stacktrace2234

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 17:18:08