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

Flutter添加Intent Filter后android:exported报错排查求助

Android 12+下Flutter应用android:exported属性不生效问题排查

开发Flutter应用时,为AndroidManifest.xml的MainActivity添加新的intent-filter后,出现如下错误:

android:exported needs to be explicitly specified for element <activity#com.example.myApp.MainActivity>. Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined.

已尝试为包含intent-filter的MainActivity添加android:exported="true"属性,但问题仍未解决,完整的AndroidManifest.xml代码如下:

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

<application
    android:label="myApp"
    android:name="${applicationName}"
    android:icon="@mipmap/ic_launcher">

    <activity
        android:name=".MainActivity"
        android:label="@string/myApp">
        android:exported="true"
        android:launchMode="singleTop"
        android:taskAffinity=""
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize" tools:ignore="MissingClass">

        <meta-data
            android:name="io.flutter.embedding.android.NormalTheme"
            android:resource="@style/NormalTheme" />

        <!-- Intent Filter for launching the app -->
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <!-- Intent Filter for App Links -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="my-app.com"
                android:scheme="app" />
        </intent-filter>
    </activity>

    <meta-data
        android:name="flutterEmbedding"
        android:value="2" />
</application>

<!-- Required to query activities that can process text -->
<queries>
    <intent>
        <action android:name="android.intent.action.PROCESS_TEXT" />
        <data android:mimeType="text/plain" />
    </intent>
</queries>

问题原因

XML语法错误导致属性未被系统识别:你在定义<activity>标签时,第一行末尾错误使用了>闭合标签,导致后续的android:exported="true"变成了<activity>的子元素,而非标签本身的属性。Android系统无法读取这个位置的属性,因此仍判定android:exported未被显式指定。

修复方法

将<activity>标签第一行末尾的>改为,把android:exported="true"移到`的属性列表中,确保所有属性都属于标签本身,示例如下:

<activity
    android:name=".MainActivity"
    android:label="@string/myApp"
    android:exported="true"
    android:launchMode="singleTop"
    android:taskAffinity=""
    android:theme="@style/LaunchTheme"
    android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
    android:hardwareAccelerated="true"
    android:windowSoftInputMode="adjustResize" tools:ignore="MissingClass">

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 20:56:02