android - 面向 Android 12 及更高版本的应用需要为 `android:exported` 指定显式值

问题描述 投票:0回答:3

我已将 SDK 版本更新为 31,之后出现此错误。这是我的 Gradle :

    android {
    compileSdkVersion 31

    defaultConfig {
        applicationId "com.persiandesigners.alldentshops"
        minSdkVersion 16
        targetSdkVersion 31
        vectorDrawables.useSupportLibrary = true
        versionCode 1
        versionName "1"
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha01'
    implementation 'androidx.cardview:cardview:1.0.0-alpha01'
    implementation 'com.google.android.material:material:1.2.0-alpha01'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'

我收到此错误: 清单合并失败:需要显式指定 android:exported 。当相应组件定义了意图过滤器时,面向 Android 12 及更高版本的应用需要为

android:exported
指定显式值。有关详细信息,请参阅 https://developer.android.com/guide/topics/manifest/activity-element#exported。

我按照它说的做了,这是我的清单代码:

<activity
        android:name="mypackage.MainActivity"
        android:exported="true"
        tools:node="merge"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/SplashScreenTheme"
        android:windowSoftInputMode="stateAlwaysHidden">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

这是启动器活动,我添加了 android:exported 标签,我尝试清理并重建,但它不起作用。我在清单合并中仍然遇到合并错误:

Merging Errors: Error: 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. forushgah_alldentalshop.app main manifest (this file)

它指向MainActivity活动

android android-manifest android-sdk-tools android-12
3个回答
3
投票

如果您正在使用

flutter
,可能是您的应用程序中某些已弃用的库导致了此问题。 就我而言:升级
flutter_local_notifications
到最新版本(现在是 9.3.2)解决了这个错误..


2
投票

如果您的应用程序面向 Android 12 或更高版本,并包含使用 Intent 过滤器的活动、服务或广播接收器,则必须为这些应用程序组件显式声明 android:exported 属性。

请注意,这适用于使用意图过滤器的所有活动、服务、广播接收器。

做出改变。保存。使缓存无效并重新启动 android studio 并检查。


0
投票

在清单中,在默认启动活动属性中添加 android:exported="true" 或 android:exported="false "。

在启动器活动中

<activity
    android:name=".MainActivity"
    android:exported="true"
    android:theme="@style/Theme.MyApplication.NoActionBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

在接收器中

<receiver android:name=".Musicreceiver"
          android:exported="true">

</receiver>

在服务中

    <service
        android:name=".service.PlayerService"
        android:exported="true"
        android:enabled="true" />
© www.soinside.com 2019 - 2024. All rights reserved.