AndroidManifest错误: android:exported needs to be explicitly specified for <activity>

标签 android android-manifest android-api-31

当我更改目标并将 SDK 版本从 30 编译到 31 时,出现错误。类似this question的东西,但没有答案。

Error: android:exported needs to be explicitly specified for . 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.

但是所有具有 Intent 过滤器的 Activity 都已经有 andoird:exported属性。 我的 android list :


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.bsuir.testapp.presentation">

    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" tools:node="remove" />
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />

    <application
        android:name="com.bsuir.testapp.presentation.App"
        android:allowBackup="true"
        android:label="@string/app_name"
        android:theme="@style/Theme.ComposePagination"
        android:supportsRtl="true">

        <activity
            android:name=".screens.launchscreen.SplashScreen"
            android:theme="@style/SplashTheme"
            android:screenOrientation="portrait"
            android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".screens.history.view.HistoryActivity"
            android:label="@string/history_name"
            android:theme="@style/Theme.ComposePagination.NoActionBar"
            android:screenOrientation="portrait"/>
        <activity
            android:name=".screens.availabledevices.view.AvailableDevicesActivity"
            android:label="@string/devices_name"
            android:theme="@style/Theme.ComposePagination.NoActionBar"
            android:screenOrientation="portrait"/>
        <activity
            android:name=".screens.settings.view.SettingsActivity"
            android:label="@string/settings_name"
            android:theme="@style/Theme.ComposePagination.NoActionBar"
            android:screenOrientation="portrait"/>
        <activity
            android:name=".screens.dashboard.view.DashboardActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"/>

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_provider_paths" />
        </provider>
    </application>

</manifest>

什么可能导致错误?

最佳答案

   <?xml version="1.0" encoding="utf-8"?>
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.bsuir.testapp.presentation">

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" tools:node="remove" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />

<application
    android:name="com.bsuir.testapp.presentation.App"
    android:allowBackup="true"
    android:label="@string/app_name"
    android:theme="@style/Theme.ComposePagination"
    android:supportsRtl="true">

    <activity
        android:name=".screens.launchscreen.SplashScreen"
        android:theme="@style/SplashTheme"
        android:screenOrientation="portrait"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:exported="false"
        android:name=".screens.history.view.HistoryActivity"
        android:label="@string/history_name"android:exported="true"
        android:theme="@style/Theme.ComposePagination.NoActionBar"
        android:screenOrientation="portrait"/>
    <activity
        android:exported="false"
        android:name=".screens.availabledevices.view.AvailableDevicesActivity"
        android:label="@string/devices_name"
        android:theme="@style/Theme.ComposePagination.NoActionBar"
        android:screenOrientation="portrait"/>
    <activity
        android:exported="false"
        android:name=".screens.settings.view.SettingsActivity"
        android:label="@string/settings_name"
        android:theme="@style/Theme.ComposePagination.NoActionBar"
        android:screenOrientation="portrait"/>
    <activity
        android:exported="false"
        android:name=".screens.dashboard.view.DashboardActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"/>

    <provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="${applicationId}.provider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_provider_paths" />
    </provider>
</application>

仅针对启动器 Activity 和剩余 Activity 更新 android:exported="true"android:exported="false"

关于AndroidManifest错误: android:exported needs to be explicitly specified for <activity>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70666009/

相关文章:

android - Webview - 在显示网站之前更改页面源?

java - Kotlin 数据库错误 CursorIndexOutOfBoundsException

AndroidManifest.xml 中的 Android 兼容性设置

android - 'VIBRATOR_SERVICE : String' is deprecated for API 31

android - exception.class.missing._Unknown_ : Strongly consider using FLAG_IMMUTABLE without PendingIntent in source

android - 如何在 Android 12 中配置 Toast 图标?

java - Android SharedPreferences 重置为默认值。重新启动应用程序后

android - 有什么方法可以在 android 中实现 "checkbox group"(比如 RadioButton 组)?

Android 全局搜索应用程序替换

android - 如何获取 Android 应用程序的构建/版本号?