Execution failed for task ':app:processDebugMainManifest'. > Manifest merger failed : 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.
问题描述: Manifest合并失败:当组件定义了 < intent-filter> 时,针对 Android 12 及更高版本的应用需要为 "android:exported" 指定显式值(android:exported="true")。
以前加上intent-filter的话,exported就默认是true。Android 12之后开始强制大家声明exported属性。
例如:
<application <activity android:name=".actvitiy.MainActivity" android:exported="true" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".actvitiy.SchemeActivity" android:exported="true" > <intent-filter> ... </intent-filter> </activity> </application>
是的你没看错 Main Activity也要加这个。接下来咱们看看官方给出答案。
android:exported
此元素设置Activity是否可以由其他应用程序的组件启动:
- 如果是"true",则任何应用都可以访问该Activity,并且可以通过其确切的类名启动。
- 如果为"false",则Activity只能由相同应用程序的组件、具有相同用户 ID 的应用程序或特权系统组件启动。这是没有意图过滤器时的默认值。
如果你应用中的 Activity 包含 < intent-filter>,请将此元素设置为 "true",以允许其他应用启动它。例如,如果Activity是应用程序的Main Activity并包含category:"android.intent.category.LAUNCHER"。
如果此元素设置为"false"并且应用程序尝试启动该活动,则系统会抛出一个 ActivityNotFoundException.
此属性不是限制活动暴露于其他应用程序的唯一方法。权限还可用于限制可以调用 Activity 的外部实体(请参阅 permission 属性)。
不信邪的我果断修改代码进行尝试
<activity android:name=".actvitiy.MainActivity" android:exported="false" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
果然崩了,但是系统跑出来的不是 ActivityNotFoundException。
日志如下:
2021-10-14 01:38:52.623 1219-1219/com.google.android.apps.nexuslauncher E/BaseDraggingActivity: Unable to launch. tag=AppInfo(id=-1 type=APP container=# com.android.launcher3.logger.LauncherAtom$ContainerInfo@1a1bf6a targetComponent=ComponentInfo{com.scc.demo/com.scc.demo.actvitiy.MainActivity} screen=-1 cell(-1,-1) span(1,1) minSpan(1,1) rank=0 user=UserHandle{0} title=ShuaiCiDemo componentName=ComponentInfo{com.scc.demo/com.scc.demo.actvitiy.MainActivity}) intent=Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.scc.demo/.actvitiy.MainActivity bnds=[1124,1039][1393,1376] } java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.scc.demo/.actvitiy.MainActivity bnds=[1124,1039][1393,1376] } from ProcessRecord{ae07060 1219:com.google.android.apps.nexuslauncher/u0a128} (pid=1219, uid=10128) not exported from uid 10146 at android.os.Parcel.createExceptionOrNull(Parcel.java:2425) at android.os.Parcel.createException(Parcel.java:2409) at android.os.Parcel.readException(Parcel.java:2392) at android.os.Parcel.readException(Parcel.java:2334) at android.app.IActivityTaskManager$Stub$Proxy.startActivity(IActivityTaskManager.java:2284) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1743) at android.app.Activity.startActivityForResult(Activity.java:5404) at com.android.launcher3.Launcher.startActivityForResult(SourceFile:2) at com.android.launcher3.BaseQuickstepLauncher.startActivityForResult(SourceFile:6) at android.app.Activity.startActivity(Activity.java:5744) at com.android.launcher3.BaseDraggingActivity.startActivitySafely(SourceFile:14) at com.android.launcher3.Launcher.startActivitySafely(SourceFile:6) at com.android.launcher3.uioverrides.QuickstepLauncher.startActivitySafely(SourceFile:2) at com.android.launcher3.touch.ItemClickHandler.startAppShortcutOrInfoActivity(SourceFile:14) at com.android.launcher3.touch.ItemClickHandler.onClick(SourceFile:11) at com.android.launcher3.touch.ItemClickHandler.b(Unknown Source:0) at O0.f.onClick(Unknown Source:0) at android.view.View.performClick(View.java:7441) at android.view.View.performClickInternal(View.java:7418) at android.view.View.access$3700(View.java:835) at android.view.View$PerformClick.run(View.java:28676) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7842) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) Caused by: android.os.RemoteException: Remote stack trace: at com.android.server.wm.ActivityTaskSupervisor.checkStartAnyActivityPermission(ActivityTaskSupervisor.java:1047) at com.android.server.wm.ActivityStarter.executeRequest(ActivityStarter.java:975) at com.android.server.wm.ActivityStarter.execute(ActivityStarter.java:665) at com.android.server.wm.ActivityTaskManagerService.startActivityAsUser(ActivityTaskManagerService.java:1201) at com.android.server.wm.ActivityTaskManagerService.startActivityAsUser(ActivityTaskManagerService.java:1173)
你看 他也不是 ActivityNotFoundException 呀。
Activity supporting ACTION_VIEW is not exported
当我尝试将下面带 ACTION_VIEW 的 Activity 的属性 android:exported 改为false时,如下图:
不过也能理解,你这个比较是要接收其他其他页面和其他app的跳转,你不允许进程间通信还怎么玩。 android:exported 的问题是解决了,但是关于 ActivityNotFoundException 等找到了再补充把。