Appium 求助!使用 Appium2 inspector start session 时,java.lang.SecurityException: Permission Denial: starting Intent

LTL · 2024年04月28日 · 最后由 LTL 回复于 2024年05月14日 · 4366 次阅读

最近在学习使用 Appium2 实现安卓 UI 自动化,在用 Appium2 inspector start session 时报错,尝试了很多办法没有解决 !

这个 app 是需要测试的 app,还不能在商店下载,使用的是真机: Redimi K30 Ultra, MiUI 12.0.8;
但是该手机系统功能 app 和其他商店的下载的 App ,Appium 能 start session(区别可能在于 appActivity 以 com 开头 ? 我无法 start session 的 App 的 Activity 是以 io 开头的);

已经尝试过的办法:

  1. https://github.com/appium/appium/blob/1.x/docs/en/writing-running-appium/android/activity-startup.md
    已经检查过 packageName 和 ActivityName 是正确的

  2. 尝试手动将这个待测 App 在手机上所有的权限都打开,再点击 Start Session 但是奇怪的是一点击 Start Session 后,但是应用无法打开后,所有的权限对这个 App 又会变成拒绝

才刚开始接触 Appium, 求各位大佬指点迷津!

参数:
{
"platformName": "Android",
"appium:automationName": "uiautomator2",
"appium:deviceName": "Android",
"appium:appPackage": "uni.UNI6B40A8B",
"appium:appActivity": "io.dcloud.PandoraEntryActivity"
}

报错如下:

 Running 'C:\Users\Adroid SDK\commandlinetools-win-9123335_latest\platform-tools\adb.exe -P 5037 -s tw9tfqy5cmk7ro4h shell 'settings delete global hidden_api_policy_pre_p_apps;settings delete global hidden_api_policy_p_apps;settings delete global hidden_api_policy''
[Instrumentation] The process has exited with code 0
[AppiumDriver@8370] Event 'newSessionStarted' logged at 1714296866213 (17:34:26 GMT+0800 (China Standard Time))
[AppiumDriver@8370] Encountered internal error running command: Error: Cannot start the 'uni.UNI6B40A8B' application. Consider checking the driver's troubleshooting documentation. Original error: Error executing adbExec. Original error: 'Command ''C:\\Users\\a698642\\Adroid SDK\\commandlinetools-win-9123335_latest\\platform-tools\\adb.exe' -P 5037 -s tw9tfqy5cmk7ro4h shell am start -W -n uni.UNI6B40A8B/io.dcloud.PandoraEntryActivity -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000' exited with code 255'; Command output: Security exception: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=uni.UNI6B40A8B/io.dcloud.PandoraEntryActivity } from null (pid=29183, uid=2000) not exported from uid 10335
[AppiumDriver@8370]
[AppiumDriver@8370] java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=uni.UNI6B40A8B/io.dcloud.PandoraEntryActivity } from null (pid=29183, uid=2000) not exported from uid 10335
[AppiumDriver@8370]     at com.android.server.wm.ActivityStackSupervisor.checkStartAnyActivityPermission(ActivityStackSupervisor.java:1065)
[AppiumDriver@8370]     at com.android.server.wm.ActivityStarter.startActivity(ActivityStarter.java:785)
[AppiumDriver@8370]     at com.android.server.wm.ActivityStarter.startActivity(ActivityStarter.java:584)
[AppiumDriver@8370]     at com.android.server.wm.ActivityStarter.startActivityMayWait(ActivityStarter.java:1387)
[AppiumDriver@8370]     at com.android.server.wm.ActivityStarter.execute(ActivityStarter.java:515)
[AppiumDriver@8370]     at com.android.server.wm.ActivityTaskManagerService.startActivityAndWait(ActivityTaskManagerService.java:1276)
[AppiumDriver@8370]     at com.android.server.am.ActivityManagerService.startActivityAndWait(ActivityManagerService.java:3628)
[AppiumDriver@8370]     at com.android.server.am.ActivityManagerShellCommand.runStartActivity(ActivityManagerShellCommand.java:525)
[AppiumDriver@8370]     at com.android.server.am.ActivityManagerShellCommand.onCommand(ActivityManagerShellCommand.java:172)
[AppiumDriver@8370]     at android.os.ShellCommand.exec(ShellCommand.java:104)
[AppiumDriver@8370]     at com.android.server.am.ActivityManagerService.onShellCommand(ActivityManagerService.java:10181)
[AppiumDriver@8370]     at android.os.Binder.shellCommand(Binder.java:881)
[AppiumDriver@8370]     at android.os.Binder.onTransact(Binder.java:765)
[AppiumDriver@8370]     at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:4699)
[AppiumDriver@8370]     at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2841)
[AppiumDriver@8370]     at android.os.Binder.execTransactInternal(Binder.java:1021)
[AppiumDriver@8370]     at android.os.Binder.execTransact(Binder.java:994)
[AppiumDriver@8370]
[AppiumDriver@8370]     at ADB.startApp (C:\Users\a698642\node_modules\appium-adb\lib\tools\apk-utils.js:194:11)
[AppiumDriver@8370]     at AndroidUiautomator2Driver.ensureAppStarts (C:\Users\node_modules\appium-uiautomator2-driver\lib\driver.ts:812:5)
[AppiumDriver@8370]     at AndroidUiautomator2Driver.performSessionPostExecSetup (C:\Users\node_modules\appium-uiautomator2-driver\lib\driver.ts:635:7)
[AppiumDriver@8370]     at AndroidUiautomator2Driver.startUiAutomator2Session (C:\Users\node_modules\appium-uiautomator2-driver\lib\driver.ts:683:5)
[AppiumDriver@8370]     at AndroidUiautomator2Driver.createSession (C:\Users\node_modules\appium-uiautomator2-driver\lib\driver.ts:405:22)
[AppiumDriver@8370]     at AppiumDriver.createSession (C:\Users\AppData\Roaming\npm\node_modules\appium\lib\appium.js:717:35)
[HTTP] <-- POST /session 500 6936 ms - 5592
共收到 1 条回复 时间 点赞
LTL #1 · 2024年05月14日 Author

已经解决: Appactivity name 不正确,获取启动时候正确的 activity name , 参考:https://blog.csdn.net/weixin_45625596/article/details/137611042

LTL 关闭了讨论 05月14日 17:25
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册