android:exported needs to be explicitly specified for <activity>
场景:
正在按《第一行代码——Android(第3版)》写Kotlin代码,写了一个 HelloWorld, 点击“运行”时报错
错误提示:
> Task :app:processDebugAndroidTestManifest FAILED E:\AndroidProject\app\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest1257258968881101446.xml Error: android:exported needs to be explicitly specified for <activity>. 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. E:\AndroidProject\app\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest1257258968881101446.xml Error: android:exported needs to be explicitly specified for <activity>. 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. E:\AndroidProject\app\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest1257258968881101446.xml Error: android:exported needs to be explicitly specified for <activity>. 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.
解决思路:
(1)通过以 --debug 选项运行,重新查看更加详细的错误信息 (点击下图 --debug option,将自动再以该选项运行)
(2)得到更加详细的错误提示:
2021-11-12T07:57:44.384+0800 [INFO] [org.gradle.api.Task] Merging library manifest C:\Users\BensonLaur\.gradle\caches\transforms-3\ee2f476fa0c3550d01ea1b26bf917f27\transformed\monitor-1.3.0\AndroidManifest.xml 2021-11-12T07:57:44.384+0800 [INFO] [org.gradle.api.Task] Merging manifest with lower [androidx.test:monitor:1.3.0] AndroidManifest.xml:17:1-24:12 2021-11-12T07:57:44.384+0800 [INFO] [org.gradle.api.Task] uses-sdk defined in both files... 2021-11-12T07:57:44.384+0800 [INFO] [org.gradle.api.Task] Merging uses-sdk with lower [androidx.test:monitor:1.3.0] AndroidManifest.xml:20:5-22:41 2021-11-12T07:57:44.384+0800 [INFO] [org.gradle.api.Task] Merging library manifest C:\Users\BensonLaur\.gradle\caches\transforms-3\eba7c60eedbe1207821675fbca04aee1\transformed\espresso-idling-resource-3.3.0\AndroidManifest.xml 2021-11-12T07:57:44.384+0800 [INFO] [org.gradle.api.Task] Merging manifest with lower [androidx.test.espresso:espresso-idling-resource:3.3.0] AndroidManifest.xml:17:1-24:12 2021-11-12T07:57:44.384+0800 [INFO] [org.gradle.api.Task] uses-sdk defined in both files... 2021-11-12T07:57:44.384+0800 [INFO] [org.gradle.api.Task] Merging uses-sdk with lower [androidx.test.espresso:espresso-idling-resource:3.3.0] AndroidManifest.xml:20:5-22:41 2021-11-12T07:57:44.385+0800 [ERROR] [org.gradle.api.Task] E:\AndroidProject\app\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest1866872685080210847.xml Error: android:exported needs to be explicitly specified for <activity>. 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. 2021-11-12T07:57:44.385+0800 [ERROR] [org.gradle.api.Task] E:\AndroidProject\app\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest1866872685080210847.xml Error: android:exported needs to be explicitly specified for <activity>. 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. 2021-11-12T07:57:44.385+0800 [ERROR] [org.gradle.api.Task] E:\AndroidProject\app\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest1866872685080210847.xml Error: android:exported needs to be explicitly specified for <activity>. 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. 2021-11-12T07:57:44.385+0800 [INFO] [org.gradle.api.Task] -- Merging decision tree log ---
(3)分析错误
错误直接来自一个临时文件:tempFile1ProcessTestManifest1866872685080210847.xml (该文件应该是前序步骤生成的,因为是中间文件,思路上不应该直接修改,因为修改了可能也没用)
点击上图错误前的第一个提示的 “AndroidManifest.xml” : espresso-idling-resource-3.3.0\AndroidManifest.xml
进入对应的文件中:
观察到,多个地方提到 使用的 sdk 的问题(uses-sdk),而且具体提示了:uses-sdk defined in both files...
注意到 espresso-idling-resource-3.3.0\AndroidManifest.xml 里面的 targetSdkVersion 是 28
而我自己项目里的 build.gradle 是指定了 targetSdk 31
(4)推测是 sdk 版本兼容问题,将项目 targetSdk 改为 28
问题解决:
解决思路参考:https://blog.csdn.net/Juice_Lover/article/details/120076991
版权声明 本博客所有的原创文章,作者皆保留版权。转载必须包含本声明,保持本文完整,并以超链接形式注明作者 BensonLaur 和本文原始地址: https://www.cnblogs.com/BensonLaur/p/15542792.html |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端