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

Android 12适配报错:需显式指定android:exported属性求助

解决Android 12+ 要求显式指定 android:exported 属性的问题

问题情况

刚上手Android Studio搞Flutter,运行朋友给的示例应用一直报错,折腾3小时没搞定。

错误日志

android:exported needs to be explicitly specified for element <activity#com.dbestech.food_delivery.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. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed : android:exported needs to be explicitly specified for element <activity#com.dbestech.food_delivery.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. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 5s
Exception: Gradle task assembleDebug failed with exit code 1

当前使用的AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.dbestech.food_delivery">
    <!-- Flutter needs it to communicate with the running application
         to allow setting breakpoints, to provide hot reload, etc.
    -->
    <uses-permission android:name="android.permission.INTERNET"/>
</manifest>

解决步骤

  1. 找到Flutter项目中的完整主配置文件:app/src/main/AndroidManifest.xml——你当前提供的Manifest缺少核心的Activity声明,主配置文件才是关键。
  2. 在文件内的<application>标签下,找到<activity android:name=".MainActivity"...>节点,给它添加android:exported="true"属性(这是应用入口Activity,带启动相关的intent-filter,必须设为true)。
  3. 修改后的完整Manifest参考示例:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.dbestech.food_delivery">
    <!-- Flutter needs it to communicate with the running application
         to allow setting breakpoints, to provide hot reload, etc.
    -->
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:label="food_delivery"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            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"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>
  1. 保存文件后,重新执行flutter run命令即可。

关键说明

Android 12(API 31)及以上版本有硬性规则:所有带有intent-filter的组件(比如应用入口Activity),必须显式声明android:exported属性。入口Activity设为true,因为需要被系统启动;如果是仅内部使用的组件,可设为false。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 18:55:35