Android 12 第一次运行就报错

简介: 问题描述: Manifest合并失败:当组件定义了 < intent-filter> 时,针对 Android 12 及更高版本的应用需要为 "android:exported" 指定显式值(android:exported="true")。 以前加上intent-filter的话,exported就默认是true。Android 12之后开始强制大家声明exported属性。
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时,如下图:

微信图片_20220524111717.png


不过也能理解,你这个比较是要接收其他其他页面和其他app的跳转,你不允许进程间通信还怎么玩。 android:exported 的问题是解决了,但是关于 ActivityNotFoundException 等找到了再补充把。

相关文章
|
5月前
|
Java API 调度
Android系统 自定义开机广播,禁止后台服务,运行手动安装应用接收开机广播
Android系统 自定义开机广播,禁止后台服务,运行手动安装应用接收开机广播
238 0
|
5月前
|
移动开发 监控 安全
mPaaS常见问题之Android集成dexPatch热修复运行时候无法正常进行热更新如何解决
mPaaS(移动平台即服务,Mobile Platform as a Service)是阿里巴巴集团提供的一套移动开发解决方案,它包含了一系列移动开发、测试、监控和运营的工具和服务。以下是mPaaS常见问题的汇总,旨在帮助开发者和企业用户解决在使用mPaaS产品过程中遇到的各种挑战
|
5月前
|
Android开发
Android JNI 报错(signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr )
Android JNI 报错(signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr )
649 1
|
4月前
|
Java API 开发工具
如何将python应用编译到android运行
【6月更文挑战第27天】本文介绍在Ubuntu 20上搭建Android开发环境,包括安装JRE/JDK,设置环境变量,添加i386架构,安装依赖和编译工具。并通过`p4a`命令行工具进行apk构建和清理。
66 6
如何将python应用编译到android运行
|
2月前
|
开发工具 Android开发
解决Android运行出现NDK at /Library/Android/sdk/ndk-bundle did not have a source.properties file
解决Android运行出现NDK at /Library/Android/sdk/ndk-bundle did not have a source.properties file
140 4
解决Android运行出现NDK at /Library/Android/sdk/ndk-bundle did not have a source.properties file
|
2月前
|
网络安全 图形学 Android开发
Unity与安卓丨AS报错:SSL peer shut down incorrectly
Unity与安卓丨AS报错:SSL peer shut down incorrectly
Unity与安卓丨AS报错:SSL peer shut down incorrectly
|
2月前
|
开发工具 图形学 Android开发
Unity与安卓丨unity报错:SDK Tools version 0.0 < 26.1.1
Unity与安卓丨unity报错:SDK Tools version 0.0 < 26.1.1
|
2月前
|
API Android开发 图形学
UNITY与安卓⭐三、安卓报错答疑合集
UNITY与安卓⭐三、安卓报错答疑合集
|
2月前
|
Java Android开发
解决Android编译报错:Unable to make field private final java.lang.String java.io.File.path accessible
解决Android编译报错:Unable to make field private final java.lang.String java.io.File.path accessible
152 1
|
2月前
|
Android开发
解決Android报错:Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
解決Android报错:Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
57 1
下一篇
无影云桌面