新手区 appium 连真机跑 python 脚本时,提示 Message: A new session could not be created. (Original error: Permission to start activity denied.)

WYH · 2016年09月06日 · 最后由 Unmurphy 回复于 2016年09月07日 · 1470 次阅读

情况是这样,测试的对象是我们项目自己开发的一个 app 程序,我直接拿 APK 安装在手机上。而在模拟器上,脚本是可以顺利执行。但是连真机测试时,却失败。
真机运行其他 app 程序都是 OK 的,我试过了安卓自带的计算器,还有新浪微博,都可以启动。
查找网上类似的解决方法,但是似乎都说让修改 AndroidManifest.xml 文件,可是我这是用 apk 安装的,哪来的这个文件呢?
我的 appium log 如下:


Killed Node Server.
Appium server process ended
Launching Appium server with command: C:\Appium\node.exe lib\server\main.js --address 127.0.0.1 --port 4723 --platform-name Android --platform-version 23 --automation-name Appium --log-no-color
info: Welcome to Appium v1.4.16 (REV ae6877eff263066b26328d457bd285c0cc62430d)
info: Appium REST http interface listener started on 127.0.0.1:4723
info: [debug] Non-default server args: {"address":"127.0.0.1","logNoColors":true,"platformName":"Android","platformVersion":"23","automationName":"Appium"}
info: Console LogLevel: debug
info: --> POST /wd/hub/session {"requiredCapabilities":{},"desiredCapabilities":{"platformVersion":"6.0.1","deviceName":"051605559b261e02","platformName":"Android","appActivity":"com.smartcity.activity.NewVersionMainActivity","appPackage":"com.smartcity"}}
info: Client User-Agent string: Python-urllib/2.7
info: [debug] Didn't get app but did get Android package, will attempt to launch it on the device
info: [debug] Creating new appium session 2933085c-e854-45f5-a352-e99976ea1e22
info: Starting android appium
info: [debug] Getting Java version
info: Java version is: 1.8.0_101
info: [debug] Checking whether adb is present
info: [debug] Using adb from E:\android\android-sdk-windows\platform-tools\adb.exe
warn: No app capability, can't parse package/activity
info: [debug] Using fast reset? true
info: [debug] Preparing device for session
info: [debug] Not checking whether app is present since we are assuming it's already on the device
info: Retrieving device
info: [debug] Trying to find a connected android device
info: [debug] Getting connected devices...
info: [debug] executing cmd: E:\android\android-sdk-windows\platform-tools\adb.exe devices
info: [debug] 1 device(s) connected
info: Found device 051605559b261e02
info: [debug] Setting device id to 051605559b261e02
info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
info: [debug] executing cmd: E:\android\android-sdk-windows\platform-tools\adb.exe -s 051605559b261e02 wait-for-device
info: [debug] executing cmd: E:\android\android-sdk-windows\platform-tools\adb.exe -s 051605559b261e02 shell "echo 'ready'"
info: [debug] Starting logcat capture
info: [debug] Getting device API level
info: [debug] executing cmd: E:\android\android-sdk-windows\platform-tools\adb.exe -s 051605559b261e02 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 23
info: Device API level is: 23
info: [debug] Extracting strings for language: default
info: [debug] Apk doesn't exist locally
info: [debug] Could not get strings, but it looks like we had an old strings file anyway, so ignoring
info: [debug] executing cmd: E:\android\android-sdk-windows\platform-tools\adb.exe -s 051605559b261e02 shell "rm -rf /data/local/tmp/strings.json"
info: [debug] Not uninstalling app since server not started with --full-reset
info: [debug] Skipping install since we launched with a package instead of an app path
info: [debug] Forwarding system:4724 to device:4724
info: [debug] executing cmd: E:\android\android-sdk-windows\platform-tools\adb.exe -s 051605559b261e02 forward tcp:4724 tcp:4724
info: [debug] Pushing appium bootstrap to device...
info: [debug] executing cmd: E:\android\android-sdk-windows\platform-tools\adb.exe -s 051605559b261e02 push "C:\Appium\node_modules\appium\build\android_bootstrap\AppiumBootstrap.jar" /data/local/tmp/
info: [debug] Pushing settings apk to device...
info: [debug] executing cmd: E:\android\android-sdk-windows\platform-tools\adb.exe -s 051605559b261e02 install "C:\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk"
info: [debug] Pushing unlock helper app to device...
info: [debug] executing cmd: E:\android\android-sdk-windows\platform-tools\adb.exe -s 051605559b261e02 install "C:\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
info: Starting App
info: [debug] Attempting to kill all 'uiautomator' processes
info: [debug] Getting all processes with 'uiautomator'
info: [debug] executing cmd: E:\android\android-sdk-windows\platform-tools\adb.exe -s 051605559b261e02 shell "ps 'uiautomator'"
info: [debug] No matching processes found
info: [debug] Running bootstrap
info: [debug] spawning: E:\android\android-sdk-windows\platform-tools\adb.exe -s 051605559b261e02 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.smartcity -e disableAndroidWatchers false
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
info: [debug] [BOOTSTRAP] [debug] Loading json...
info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
info: [debug] Waking up device if it's not alive
info: [debug] Pushing command to appium work queue: ["wake",{}]
info: [debug] [BOOTSTRAP] [debug] Client connected
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"wake","params":{}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: wake
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
info: [debug] executing cmd: E:\android\android-sdk-windows\platform-tools\adb.exe -s 051605559b261e02 shell "dumpsys window"
info: [debug] Screen already unlocked, continuing.
info: [debug] Pushing command to appium work queue: ["getDataDir",{}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"getDataDir","params":{}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: getDataDir
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"\/data\/local\/tmp"}
info: [debug] dataDir set to: /data/local/tmp
info: [debug] Pushing command to appium work queue: ["compressedLayoutHierarchy",{"compressLayout":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"compressedLayoutHierarchy","params":{"compressLayout":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: compressedLayoutHierarchy
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":false}
info: [debug] Getting device API level
info: [debug] executing cmd: E:\android\android-sdk-windows\platform-tools\adb.exe -s 051605559b261e02 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 23
info: [debug] executing cmd: E:\android\android-sdk-windows\platform-tools\adb.exe -s 051605559b261e02 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.smartcity/com.smartcity.activity.NewVersionMainActivity"
error: Permission to start activity denied.
info: [debug] Stopping logcat capture
info: [debug] Logcat terminated with code null, signal SIGTERM
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"}
info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"OK, shutting down"}
info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
info: [debug] [BOOTSTRAP] [debug] Closed client connection
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
info: [debug] [UIAUTOMATOR STDOUT] Time: 1.859
info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
info: [debug] UiAutomator shut down normally
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
error: Failed to start an Appium session, err was: Error: Permission to start activity denied.
info: [debug] Error: Permission to start activity denied.
at [object Object]. (C:\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:1151:19)
at [object Object]. (C:\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:180:9)
at ChildProcess.exithandler (child_process.js:742:7)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1016:16)
at Process.ChildProcess._handle.onexit (child_process.js:1088:5)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Permission to start activity denied.)","origValue":"Permission to start activity denied."},"sessionId":null}
info: <-- POST /wd/hub/session 500 6043.828 ms - 194


共收到 6 条回复 时间 点赞
info: [debug] executing cmd: E:\android\android-sdk-windows\platform-tools\adb.exe -s 051605559b261e02 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.smartcity/com.smartcity.activity.NewVersionMainActivity"
error: Permission to start activity denied.

应该是你的这个 activity 没有添加外部启动的权限。解决方法确实是修改 AndroidManifest.xml 文件。

不知道 AndroidManifest.xml 文件是什么,怎么修改的话建议自行百度或者 google 一下吧。这是安卓应用测试工程师的应该了解的知识。

PS:记得先确认下你的这个 activity 是不是真的是启动时使用的 activity 哦。正常来说一个启动时使用的 activity 不应该会无法被外部启动的。

WYH #2 · 2016年09月07日 Author

#1 楼 @chenhengjie123 这个 activity 我用模拟器是可以启动了,主要是模拟器上面运行的太慢了,所以我想换到真机上做。
另外,我是通过
adb shell dumpsys window w | findstr \/ | findstr name=
来获取 activity 名 和 Package 名 的。
先谢过了 ! 我再去试试。

#2 楼 @owenfigo 用 aapt d badging xx.apk 获取 activity

我记得这种错,要么就是 APPIUM 服务器没启动起来,要么就是配置出错了,你查查看,通常是服务器没启动好或者包名问题

WYH #5 · 2016年09月07日 Author

#4 楼 @nigu 我确认 appium 服务启动了,因为跑别的 APK 程序都没问题。

如果启动 activity 没有错的话,,还有问题就看这个 activity 是不是没有外部访问的权限

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册