Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”

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.
Copy the code

Problem Description: Android: Exported applications need to specify an explicit value for “Android: Exported” (Android :exported=”true”) when the component defines < intent-filter>.

Such as:

    <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>
Copy the code

Yes, you read that right. Main Activity also needs this. Let’s take a look at the official answer.

android:exported

This element sets whether an Activity can be started by a component of another application:

  • If it is “true”, any application can access the Activity and can be started with its exact class name.
  • If it is “false”, the Activity can only be started by a component of the same application, an application with the same user ID, or a privileged system component. This is the default value when there is no intent filter.

If an Activity in your application contains < intent-filter>, set this element to “true” to allow other applications to start it. For example, if the Activity is the application of the Main Activity and contain category: “android. Intent. The category. The LAUNCHER”.

If this element is set to “false” try to launch the activity and application, the system will throw a ActivityNotFoundException.

This property is not the only way to limit activity exposure to other applications. Permissions can also be used to restrict external entities that can invoke the Activity (see Permission properties).

Unconvinced, I decided to modify the code to try

        <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>
Copy the code

Indeed as expected avalanche, but ran out of the system is not ActivityNotFoundException.

The log is as follows:

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=[1124103][1393137] }
    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)
Copy the code

You see he is not ActivityNotFoundException ah.

Activity supporting ACTION_VIEW is not exported

When I try to change the following Activity property android: Exported with ACTION_VIEW to false, it looks like this:

.

However, you can understand that this comparison is to receive other pages and other apps jump, you do not allow interprocess communication how to play. Android: exported problem is solved, but about ActivityNotFoundException found to restock, etc.