当我更改目标并将 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/