1

当我将目标和编译 SDK 版本从 30 更改为 31 时,出现错误。类似于这个问题的东西,但它没有答案。

错误:需要明确指定 android:exported 为 . 面向 Android 12 及更高版本的应用需要为android:exported相应组件定义了 Intent 过滤器时指定显式值。有关详细信息,请参阅 https://developer.android.com/guide/topics/manifest/activity-element#exported。

但是所有带有意图过滤器的活动都已经有了andoird:exported属性。我的机器人清单:


<?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>

什么可能导致错误?

4

3 回答 3

0

android:exported="true"启动器活动和android:exported="false"所有其他活动设置

像下面

<activity
            android:name=".SecondActivity"
            android:exported="false" />
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
于 2022-01-11T11:33:23.550 回答
0
   <?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>

仅为启动器活动和剩余活动更新 android:exported="true" android:exported="false"

于 2022-01-11T11:34:13.150 回答
0

更改导出为真正的 Splashscreen Activity,如下所示

 <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>
于 2022-01-11T11:31:17.173 回答