对我来说,添加 android:exported="true" 并不能解决问题

For me, adding android:exported="true" does not solve the problem

see this question Application is not installed error, when launched from home screen shortcut

AndroidManifest.xml :

<application
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/Theme.AppTheme">
        <activity
                android:name=".ui.activity.MainActivity"
                android:screenOrientation="fullSensor"
                android:label="@string/app_name"
                android:exported="true"
                android:configChanges="orientation|screenSize">
            <intent-filter
                    >
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <intent-filter
                    >
                <action android:name="android.intent.action.VIEW"/>
                <data android:scheme="app" android:host="appname"
                />
                <category android:name="android.intent.category.BROWSABLE"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
            <nav-graph android:value="@navigation/nav_graph_main"
                    />
        </activity>
</application>

Gradle [应用] :

defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 19
        targetSdkVersion 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

我收到这个错误:

> Task :app:processDebugMainManifest FAILED
/home/mhrohani/IdeaProjects/PrjName/app/src/main/AndroidManifest.xml Error:
    android:exported needs to be explicitly specified for <receiver>. 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.
/home/mhrohani/IdeaProjects/PrjName/app/src/main/AndroidManifest.xml Error:
    android:exported needs to be explicitly specified for <receiver>. 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.

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.


Execution failed for task ':app:processDebugMainManifest'.

项目和 android 工作室配置:

Gradle :                 ** 7.1.1 **  
Android Gradle Plugin :  ** 7.0.0 **  
Android Studio Version : ** Arctic fox 2020.3.1 **  
OS :                     ** Linux Ubuntu **

我正在尝试重建和同步项目,但不起作用。

请注意错误文本

android:exported needs to be explicitly specified for receiver

这意味着你必须在main/dependencies清单中寻找receiver,如果你在主清单上找到这个标签,你必须添加[=31的值=]android:exported 如果你在主清单中找不到接收者标签,那么你应该在其他依赖清单中搜索,我会逐步向你展示

1- 在 Android Studio

上打开清单文件

2- 在底部点击 Merged Manifest

3- 按顺序打开所有依赖项清单并查找不包含 android:exported

4-我确定这个标签会被找到,找到后只需复制整个标签并将其添加到主清单中,不要忘记添加 [=44= 的值]:导出给它

示例:

receiver 依赖项清单文件中的一个标签:

<receiver
        android:name="com.moduletop.push.UserPresentBroadcastReceiver"
        android:enabled="false" >
        <intent-filter>
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
</receiver>

在主清单中添加此标签:

<receiver
        tools:node="merge"
        android:exported="false"
        android:name="com.moduletop.push.UserPresentBroadcastReceiver"
        android:enabled="false" >
        <intent-filter>
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
</receiver>