You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复Appium Inspector连接安卓模拟器的权限拒绝错误

Appium Inspector连接Android模拟器时权限拒绝错误

问题详情

已在Stack Overflow及全网查找解决方案但均无效,使用Appium Inspector连接Android模拟器时,持续触发权限拒绝错误,错误日志如下:

Exception occurred while executing 'start':
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.MyApp.package/.MyApp.Activity } from null (pid=8343, uid=2000) not exported from uid 10162
    at com.android.server.wm.ActivityTaskSupervisor.checkStartAnyActivityPermission(ActivityTaskSupervisor.java:1110)
    at com.android.server.wm.ActivityStarter.executeRequest(ActivityStarter.java:1024)
    at com.android.server.wm.ActivityStarter.execute(ActivityStarter.java:713)
    at com.android.server.wm.ActivityTaskManagerService.startActivityAndWait(ActivityTaskManagerService.java:1562)
    at com.android.server.am.ActivityManagerService.startActivityAndWait(ActivityManagerService.java:3148)
    at com.android.server.am.ActivityManagerShellCommand.runStartActivity(ActivityManagerShellCommand.java:598)
    at com.android.server.am.ActivityManagerShellCommand.onCommand(ActivityManagerShellCommand.java:208)
    at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97)
    at android.os.ShellCommand.exec(ShellCommand.java:38)
    at com.android.server.am.ActivityManagerService.onShellCommand(ActivityManagerService.java:9197)
    at android.os.Binder.shellCommand(Binder.java:1049)
    at android.os.Binder.onTransact(Binder.java:877)
    at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:4731)
    at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2630)
    at android.os.Binder.execTransactInternal(Binder.java:1285)
    at android.os.Binder.execTransact(Binder.java:1244)

当前Appium配置

{
  "appium:deviceName": "Test",
  "appium:udid": "emulator-5554",
  "platformName": "Android",
  "appium:platformVersion": "9",
  "appium:automationName": "UiAutomator2",
  "appium:appPackage": "com.MyApp.package",
  "appium:appActivity": "com.MyApp.package.MyApp.Activity",
  "appium:noReset": "true"
}

补充信息

问题仅针对目标应用出现,通过拖拽.app文件将应用安装至模拟器;切换到Google Messenger等应用时,Appium Inspector可正常连接。


解决方案

1. 检查目标Activity的导出属性

错误核心是not exported,说明指定的com.MyApp.package.MyApp.Activity未在AndroidManifest.xml中设置android:exported="true"。只有导出的Activity才能被外部进程(如Appium)启动。

若有权限修改应用源码,需在对应Activity的Manifest节点中添加该属性:

<activity
    android:name="com.MyApp.package.MyApp.Activity"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

2. 确认正确的启动Activity

若无法修改应用,可能是指定的appActivity并非应用的主启动Activity。可通过以下ADB命令获取应用的主Activity:

adb shell dumpsys package com.MyApp.package | grep -E "launchable-activity"

将返回的Activity路径替换到Appium配置的appium:appActivity字段中。

3. 临时禁用noReset测试

暂时将appium:noReset改为false,重新安装应用后再尝试连接,排除应用缓存或状态导致的异常。

4. 添加appWaitActivity参数

若应用启动后需要等待特定Activity,可添加appium:appWaitActivity配置,允许匹配多个Activity(用逗号分隔):

"appium:appWaitActivity": "com.MyApp.package.*"

内容的提问来源于stack exchange,提问作者cdub

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 09:05:17