簡體   English   中英

AndroidManifest 錯誤:android:exported 需要明確指定<activity></activity>

[英]AndroidManifest error: android:exported needs to be explicitly specified for <activity>

當我更改目標並將 sdk 版本從 30 編譯到 31 時出現錯誤。 我在這個問題中看到了類似的東西,但沒有答案。

錯誤:android:需要明確指定導出。 當相應組件定義了意圖過濾器時,需要針對 Android 12 及更高版本的應用程序為android:exported指定顯式值。 有關詳細信息,請參閱 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>

什么可能導致錯誤?

更改導出為真正的 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>

為啟動器活動設置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>
   <?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"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM