SVP*_*SVP 17 android android-manifest android-studio android-12
使用 Android Studio 4.2.1,在我的 build.gradle 文件中将 sdk 目标更改为 Android 12 后,出现Manifest merger failed with multiple errors, see logs错误。
Merged Manifest选项卡中显示的错误如下:
Merging Errors:
Error: 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. My_App.app main manifest (this file)
Error: 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. My_App.app main manifest (this file)
Error: 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. My_App.app main manifest (this file)
Run Code Online (Sandbox Code Playgroud)
但是,该android:exported标记已应用在我的 AndroidManifest.xml 文件中。我只有一项活动。没有服务或广播接收器。见下文:
Merging Errors:
Error: 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. My_App.app main manifest (this file)
Error: 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. My_App.app main manifest (this file)
Error: 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. My_App.app main manifest (this file)
Run Code Online (Sandbox Code Playgroud)
我的 build.gradle(:app) 文件:
android {
compileSdkVersion("android-S")
buildToolsVersion "30.0.3"
defaultConfig {
...
minSdkVersion 23
targetSdkVersion("S")
...
}
Run Code Online (Sandbox Code Playgroud)
知道我如何解决这个问题吗?
SVP*_*SVP 37
该问题是由 3 个活动android:exported在androidx.test:core库版本中缺少该属性引起的1.3.0。升级到版本1.4.0-beta01解决了这个问题。
如果您在面向 Android 12 后遇到错误,最简单的调试方法是:
AndroidManifest.xml.Merged Manifest选项卡<activity>包含<intent-filter>标签但缺少该android:exported属性的内容如果您想确保这些活动是问题所在,请将它们直接添加到您的项目AndroidManifest.xml文件中,并android:exported添加缺失的属性,然后尝试重建项目。
因此,如果<activity android:name="com.domain.ProblemActivity">缺少该android:exported属性,请将其添加到您的AndroidManifest.xml文件中,如下所示:
<activity
android:name="com.domain.ProblemActivity"
android:exported="true" >
Run Code Online (Sandbox Code Playgroud)
针对 Android 12 重新构建,如果它有效,那么您就找到了错误!
感谢@MikePenz为我指明了正确的方向。
如果您的应用以 Android 12 或更高版本为目标平台,并且包含使用 Intent 过滤器的活动、服务或广播接收器,则必须为这些应用组件显式声明 android:exported 属性。为了解决这个问题,我们需要执行以下步骤:
android>app>src>main>AndroidManifest.xml
我们必须android:exported=""在这些引号内添加并设置一个布尔值。现在您可能会问我什么时候需要添加android:exported="true"或android:exported="false"添加到使用意图过滤器的活动、服务或广播接收器。如果应用程序组件包含 LAUNCHER 类别,请将 android:exported 设置为 true。在大多数其他情况下,将 android:exported 设置为 false。
这是 AndroidManifest.xml 中的示例
<service android:name="com.example.app.backgroundService"
android:exported="false">
<intent-filter>
<action android:name="com.example.app.START_BACKGROUND" />
</intent-filter>
</service>Run Code Online (Sandbox Code Playgroud)
您可以通过以下链接查看有关此主题的更多信息:
小智 6
如果您将 Android Studio 升级到 Bumblebee 2021.1.1。需要进行以下更改: 步骤 1:您targetSdkVersion必须年满 30 岁或更高 步骤 2:将您的appcompat库更新为implementation 'androidx.appcompat:appcompat:1.4.1'
步骤 3:在 AndroidManifest 文件中添加android:exported = true到您的 Activity 启动器。
| 归档时间: |
|
| 查看次数: |
5839 次 |
| 最近记录: |