uni-app 本地打包的app进行activity组件暴露检测存在导出,加上android:exported="false"后app无法启动,点击无效
uni-app 本地打包的app进行activity组件暴露检测存在导出,加上android:exported="false"后app无法启动,点击无效
开发环境 | 版本号 | 项目创建方式 |
---|---|---|
Windows | win10 | HBuilderX |
产品分类:uniapp/App
PC开发环境操作系统:Windows
PC开发环境操作系统版本号:win10
HBuilderX类型:正式
HBuilderX版本号:3.99
手机系统:Android
手机系统版本号:Android 14
手机厂商:华为
手机机型:华为p40
页面类型:vue
vue版本:vue2
打包方式:云端
项目创建方式:HBuilderX
示例代码:
修改前:
<!-- 应用入口 -->
<activity
android:name="io.dcloud.PandoraEntry"
android:configChanges="orientation|keyboardHidden|screenSize|mcc|mnc|fontScale"
android:hardwareAccelerated="true"
android:taskAffinity=""
android:theme="[@style](/user/style)/TranslucentTheme"
android:windowSoftInputMode="adjustResize"
<!-- android:permission="ai.permission.SMARTRESOURCE"-->
<intent-filter>
<data android:scheme="ai.smartresource" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<intent-filter>
<data android:mimeType="image/*" />
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
修改后代码:
<!-- 应用入口 -->
<activity
android:name="io.dcloud.PandoraEntry"
android:configChanges="orientation|keyboardHidden|screenSize|mcc|mnc|fontScale"
android:hardwareAccelerated="true"
android:taskAffinity=""
android:theme="[@style](/user/style)/TranslucentTheme"
android:windowSoftInputMode="adjustResize"
android:exported="false"
tools:ignore="AppLinkUrlError">
<!-- android:permission="ai.permission.SMARTRESOURCE"-->
<intent-filter>
<data android:scheme="ai.smartresource" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<intent-filter>
<data android:mimeType="image/*" />
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
1 回复
在 Uni-app 中,如果你在本地打包的 Android 应用时,遇到某个 Activity
组件暴露检测的问题,并且你在 AndroidManifest.xml 中将其设置为 android:exported="false"
后,应用无法启动或点击无效,可能是以下原因导致的:
1. android:exported
的作用
android:exported
属性用于控制一个 Activity
是否可以被其他应用调用:
true
:允许其他应用调用。false
:不允许其他应用调用。
如果你将某个关键 Activity
设置为 android:exported="false"
,可能会导致应用无法正常启动,尤其是主 Activity
(通常是 MainActivity
)。
2. 检查主 Activity
的设置
- 主
Activity
必须设置为android:exported="true"
,因为它是应用的入口点,需要被系统启动。 - 如果你将主
Activity
设置为android:exported="false"
,系统将无法启动它,导致应用无法运行。
在 AndroidManifest.xml
中找到主 Activity
的声明,确保其 android:exported="true"
:
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
3. 检查其他 Activity
的设置
对于非主 Activity
,你可以根据需求设置 android:exported
:
- 如果某个
Activity
不需要被其他应用调用,可以设置为false
。 - 如果某个
Activity
需要被其他应用调用,或者通过隐式Intent
启动,必须设置为true
。
例如:
<activity
android:name=".OtherActivity"
android:exported="false" />