android - 对我来说,添加 android :exported ="true" does not solve the problem

标签 android android-studio kotlin gradle manifest

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 studio 配置:
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 list 中,如果您在主 list 中找到此标记,则必须添加 的值安卓:导出如果您在主 list 中找不到接收者标签,那么您应该在其他依赖项 list 中搜索,我将逐步向您展示
1- 在 Android Studio 上打开 list 文件
2- 在底部点击 合并 list
3- 按顺序打开所有依赖项 list 并查找不包含 的安卓:导出
4-我确定会找到这个标签,找到它后只需复制整个标签并将其添加到主 list 中,不要忘记添加的值安卓:导出对它
例子:
接收器依赖项 list 文件之一中的标记:
<receiver
        android:name="com.moduletop.push.UserPresentBroadcastReceiver"
        android:enabled="false" >
        <intent-filter>
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
</receiver>
在主 list 中添加此标记:
<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>

关于android - 对我来说,添加 android :exported ="true" does not solve the problem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68714057/

相关文章:

java - 为什么我的 Android 应用程序在启动新 Activity 时崩溃?

android - 暂停或停止 fragment 后未显示键盘

android - 如何使用kotlin在android应用程序中设置错误消息的时间延迟

java - 尝试调用虚拟方法。显示位置的应用程序

java - 谷歌库 play-services-location 和 play-services-analytics 出错

android - 在 Message.builder 中, builder() 显示未解析的引用?

java - Android PDF 查看器库或 muPDF 库教程

java - Android Studio 无法运行 AVD...超时

android - 为什么我的 API 不能低于 5.1?

generics - 语法 : multiple generic constraints and inheritance, 接口(interface)