当前位置:   article > 正文

解决Manifest merger failed : android:exported needs to be explicitly specified for <activity>

manifest merger failed : android:exported needs to be explicitly specified f

出错场景

运行一个老项目,编译时报以下错误

Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed : android:exported needs to be explicitly specified for <activity>. 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.
  • 1
  • 2
  • 3
  • 4
  • 5

解决方案

根据错误提示,targetSdkVersion大于等于SDK 31(也就是Android 12)时,如果有的Activity配置了Intent-filter,必须也同时配置exported属性,否则编译失败。

所以我们有2种解决方案

  1. 降低targetSdkVersion为30.
    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 21
        //targetSdkVersion 31
        targetSdkVersion 30
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  1. 将Manifest中有配置Intent-filter的Activity加上android:exported属性
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:launchMode="standard"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小惠珠哦/article/detail/824114
推荐阅读
相关标签
  

闽ICP备14008679号