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 等找到了再補充把,
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/333840.html
標籤:其他
