1

When I changed the target and compile SDK version from 30 to 31 I get an error. Something similar to this question, but it has no answers.

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.

But all activities with intent-filter already have andoird:exported attribute. My android-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="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>

What could be causing the error?

RaBaKa 78
  • 1,115
  • 7
  • 11
Sunbey13
  • 339
  • 4
  • 12

3 Answers3

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

Update android:exported="true" only for Launcher activity and remaining Activities android:exported="false"

Tota Madhu
  • 26
  • 4
0

change exported to true Splashscreen Activity like below

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

set android:exported="true" for launcher activity and android:exported="false" for all other's activity

like below

<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>
Pratik Fagadiya
  • 1,195
  • 7
  • 21