Appium Mac OS 下调用命令行启动 appium 无法连接真机时不能初始化 ideviceinstaller

adfghzhang · August 17, 2015 · Last by 渐次消逝 replied at May 04, 2017 · 5149 hits

最近研究Mac OS下从命令行启动Appium的研究,连接模拟器都没有问题,但是连接真机却出现异常:“Could not initialize ideviceinstaller; make sure it is installed and works on your system”。
Appium GUI启动连接真机无问题,直接终端启动appium再去连接真机也没有问题。
环境信息如下:
Appium1.4.8.dmg
Xcode 6.3
idevice系列的组件都存在且appium下的idevice系列组件也是OK的。


java代码片段如下:

String processName = "/Applications/Appium.app/Contents/Resources/node/bin/node "
+ "/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/server/main.js"
+ " --address \"127.0.0.1\" --command-timeout \"15000\" --log-no-colors --debug-log-spacing"
+ " --platform-version \"8.1.3\" --platform-name \"iOS\""
+ " --app \"/Users/user/Documents/TestApp.app\" --log \"/Users/systest/Desktop/appium.log\""
+ " --udid \"f1c019a675bade1fe48837ecda0899d682x280ef\" --no-reset --device-name \"iPad Air 2\"";
String[] CMDS = new String[3];
CMDS[0] = "/bin/bash";
CMDS[1] = "-c";
CMDS[2] = processName;
Runtime rt = Runtime.getRuntime();
try {
rt.exec(CMDS);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

desiredCapabilities的内容如下。

capacitymap.put("platformName", "iOS");
capacitymap.put("platformVersion", "8.1.3");
capacitymap.put("newCommandTimeout", 72000);
capacitymap.put("automationName", "Appium");
capacitymap.put("deviceName", "iPad Air 2");
desiredcapmap.put("desiredCapabilities", capacitymap);

Appium GUI运行关键日志:

2015-08-17 02:59:12:070 - info: [debug] Creating instruments
2015-08-17 02:59:12:071 - info: [debug] Preparing uiauto bootstrap
2015-08-17 02:59:12:071 - info: [debug] Dynamic bootstrap dir: /Users/user/Library/Application Support/appium/bootstrap
2015-08-17 02:59:12:080 - info: [debug] Dynamic env: {"nodePath":"/Applications/Appium.app/Contents/Resources/node/bin/node","commandProxyClientPath":"/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js","instrumentsSock":"/tmp/instruments_sock","interKeyDelay":null,"justLoopInfinitely":false,"autoAcceptAlerts":false,"autoDismissAlerts":false,"sendKeyStrategy":"grouped"}
2015-08-17 02:59:12:105 - info: [debug] Dynamic bootstrap code: // This file is automatically generated. Do not manually modify!
2015-08-17 02:59:12:105 - info: [debug] Dynamic bootstrap path: /Users/user/Library/Application Support/appium/bootstrap/bootstrap-6745615c424bb0c0.js
2015-08-17 02:59:12:110 - info: [debug] Reusing dynamic bootstrap: /Users/user/Library/Application Support/appium/bootstrap/bootstrap-6745615c424bb0c0.js
2015-08-17 02:59:12:112 - info: [debug] Attempting iOS device log capture via libimobiledevice idevicesyslog
2015-08-17 02:59:12:221 - info: [debug] Creating iDevice object with udid f1c019a675bade1fe48837ecda0899d682c280ef
2015-08-17 02:59:13:830 - info: [debug] App is installed.

java调用命令行运行关键日志:

2015-08-17 03:00:17:190 - info: [debug] Creating instruments
2015-08-17 03:00:17:191 - info: [debug] Preparing uiauto bootstrap
2015-08-17 03:00:17:191 - info: [debug] Dynamic bootstrap dir: /Users/user/Li
brary/Application Support/appium/bootstrap
2015-08-17 03:00:17:191 - info: [debug] Dynamic env: {"nodePath":"/Applications/Appium.app/Contents/Resources/node/bin/node","commandProxyClientPath":"/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js","instrumentsSock":"/tmp/instruments_sock","interKeyDelay":null,"justLoopInfinitely":false,"autoAcceptAlerts":false,"autoDismissAlerts":false,"sendKeyStrategy":"grouped"}
2015-08-17 03:00:17:221 - info: [debug] Dynamic bootstrap code: // This file is automatically generated. Do not manually modify!
2015-08-17 03:00:17:221 - info: [debug] Dynamic bootstrap path: /Users/user/Library/Application Support/appium/bootstrap/bootstrap-6745615c424bb0c0.js
2015-08-17 03:00:17:233 - info: [debug] Reusing dynamic bootstrap: /Users/user/Library/Application Support/appium/bootstrap/bootstrap-6745615c424bb0c0.js
2015-08-17 03:00:17:234 - info: [debug] Attempting iOS device log capture via li
bimobiledevice idevicesyslog
2015-08-17 03:00:17:235 - warn: Could not capture device log using libimobiledevice idevicesyslog. Libimobiledevice probably isn't installed
2015-08-17 03:00:17:236 - info: [debug] Attempting iOS device log capture via deviceconsole
2015-08-17 03:00:18:387 - info: [debug] Creating iDevice object with udid f1c019a675bade1fe48837ecda0899d682c280ef
2015-08-17 03:00:18:388 - info: [debug] Couldn't find ideviceinstaller, trying built-in at /Applications/Appium.app/Contents/Resources/node_modules/appium/build/libimobiledevice-macosx/ideviceinstaller
2015-08-17 03:00:18:389 - error: Could not initialize ideviceinstaller; make sure it is installed and works on your system
2015-08-17 03:00:18:389 - info: [debug] Cleaning up appium session
2015-08-17 03:00:18:390 - error: Failed to start an Appium session, err was: Error: Could not initialize ideviceinstaller; make sure it is installed and works on your system
2015-08-17 03:00:18:394 - info: [debug] Error: Could not initialize ideviceinstaller; make sure it is installed and works on your system
at [object Object].IOS.getIDeviceObj (/Applications/Appium.app/Contents/Reso
urces/node_modules/appium/lib/devices/ios/ios.js:909:13)
at [object Object].IOS.installToRealDevice (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios/ios.js:856:32)
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/async/lib/async.js:607:21
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/async/lib/async.js:246:17
at iterate (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/async/lib/async.js:146:13)
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/async/lib/async.js:157:25
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/async/lib/async.js:248:21
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/async/lib/async.js:612:34
at [object Object].<anonymous> (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios/ios-crash-log.js:52:5)
at [object Object].<anonymous> (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios/ios-crash-log.js:27:5)
at f (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/node_modules/once/once.js:17:25)
at Glob.<anonymous> (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/glob.js:131:7)
at Glob.emit (events.js:107:17)
at Glob._finish (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/glob.js:168:8)
at done (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/glob.js:157:12)
at Glob._processReaddir2 (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/glob.js:351:12)
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/glob.js:288:17
at RES (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/node_modules/inflight/inflight.js:23:14)
at f (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/node_modules/once/once.js:17:25)
at Glob._readdirEntries (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/glob.js:480:10)
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/glob.js:457:12
at FSReqWrap.oncomplete (fs.js:95:15)
2015-08-17 03:00:18:394 - info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Could not initialize ideviceinstaller; make sure it is installed and works on your system)","origValue":"Could not initialize ideviceinstaller; make sure it is installed and works on your system"},"sessionId":null}
2015-08-17 03:00:18:400 - info: <-- POST /wd/hub/session 500 1227.408 ms - 300
2015-08-17 03:00:19:424 - info: --> GET /wd/hub/session/null/source {}
2015-08-17 03:00:19:428 - info: <-- GET /wd/hub/session/null/source 404 3.526 ms - 40
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 32 条回复 时间 点赞

还请添加头像

#1楼 @monkey 已上传头像,还烦请看一下我的帖子,有没有什么好的办法去解决?

#2楼 @adfghzhang brew ideviceinstaller 安装就好来

#3楼 @hudiefeifei 重装ideviceinstaller还是一样的效果,怀疑不是这个的问题。通过Appium GUI和终端启动appium都能正常识别ideviceinstaller并启动真机上的app

python 里面没找到这个 exec的方法,只有execute_script,不好好想只可以执行 js

#5楼 @among29 能说明白点么

出现这种问题一般是 exec 的运行环境和你平时命令行运行的运行环境不一样。

建议检查一下 exec 下环境变量、使用的用户这些是否一致?

另外,注意一下 shell 的登录式和非登录式的区别,看是否有些配置信息没有加载?

遇到同样的问题了,

好把,我承认我也遇到这个问题了。后来我换了1.3.7的版本。_^

这个问题我在7月底的时候折腾过,后来没找到办法。。。
关注中。。。

我的错误信息和你一样,如下:
info: [debug] Couldn't find ideviceinstaller, trying built-in at /Volumes/Appium/Appium.app/Contents/Resources/node_modules/appium/build/libimobiledevice-macosx/ideviceinstaller
error: Could not initialize ideviceinstaller; make sure it is installed and works on your system

我的解决方法是安装ideviceinstaller,安装方法如下:
brew install --HEAD ideviceinstaller

希望对你有用。

#9楼 @among29 1.3。7版本如何

#12楼 @mads 能用,要替换一个js文件。

@adfghzhang, 请问楼主找到解决方法了吗?我用的是1.5.2版本,用brew install --HEAD ideviceinstaller显示已经安装了,仍旧报错,@stella_chmt ,我下载那包node-idevice文件,放在指定路径下也没有效果,是因为用.dmg安装的不能这样用吗?

#15楼 @yingruoyuan 如果你是要通过命令行启动appium的话,这个问题是系统环境变量的问题,10.10以及以前的版本有解决方法。
1.eclipse里面可以设置环境变量临时解决(把ideviceinstaller所在目录/usr/local/bin添加到eclipse的environment Run as configuration -environment-New)。
2.如果要做jenkins集成或者打成jar运行需要更改系统的环境变量,可以参考该贴http://stackoverflow.com/questions/25385934/setting-environment-variables-via-launchd-conf-no-longer-works-in-os-x-yosemite

@adfghzhang,多谢,解决了,的确是环境变量的问题,我重新试了下在命令行下直接跑,是可以pass的,在eclipse或jinkens下则需要设置下环境变量;

我的环境变量是这样的
export MAVEN_HOME=/Users/user/apache-maven-3.3.9
export M2=$MAVEN_HOME/bin
export PATH=$M2:$PATH
export ANDROID_HOME=/Users/user/Library/Android/sdk
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home
export APPIUM_HOME=/Applications/Appium.app/Contents/Resources/node_modules/.bin
export PATH=${PATH}:${APPIUM_HOME}:${JAVA_HOME}:/Users/user/Library/Android/sdk/platform-tools

在mac 终端通过命令行可以正常启动
但是我用java命令行的方式
命令如下:
ations/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/.bin/appium -a 127.0.0.1 -p 4723 2>>/Users/user/log.txt
Process process =null;
List strList = new ArrayList();
//String cmd1 = "chmod 777" + "/Users/user/appium.sh";
String cmdNode = "/Applications/Appium.app/Contents/Resources/node/bin/node ";
String cmdMain = "/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/main.js ";
String cmd = cmdNode+APPIUMSERVERSTARTCMD;
System.out.println(cmd );
String[] cmds = {"/bin/sh","-c",cmd};
//Applications/Appium.app/Contents/Resources/node_modules/.bin
//String[] cmds = {"/bin/sh","-c","/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/main.js appium -a 127.0.0.1 -p 4723"};
process = Runtime.getRuntime().exec(cmds);
InputStreamReader reader = new InputStreamReader(process.getErrorStream());
BufferedReader input1 = new BufferedReader(reader);
String line1 = "";
while ((line1 = input1.readLine())!= null)
{
到这里就不往下执行了

lsof -i tcp:4723
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 16617 user 11u IPv4 0x242b52c3d89b3d3d 0t0 TCP localhost:4723 (LISTEN)
看是有4723端口的但是不能使用

我增加了文件environment.list
启动还是有错
/Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/.bin/appium -a 127.0.0.1 -p 4723 2>>/Users/user/log.txt
[Appium] Welcome to Appium v1.5.3
[Appium] Non-default server args:
[Appium] address: '127.0.0.1'
Error: listen EADDRINUSE 127.0.0.1:4723
at Object.exports.errnoException (util.js:890:11)
at exports._exceptionWithHostPort (util.js:913:20)
at Server.
_dirname.Server.Server._listen2 (net.js:1230:14)
at listen (net.js:1266:10)
at net.js:1375:9
at _combinedTickCallback (internal/process/next_tick.js:77:11)
at process._tickCallback (internal/process/next_tick.js:98:9)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">


Label
my.startup
ProgramArguments

sh
-c

launchctl setenv APPIUM_HOME /Applications/Appium.app/Contents/Resources/node_modules/.bin
lanchctl setenv ANDROID_HOME /Users/user/Library/Android/sdk


RunAtLoad



这是增加的文件内容,不知道是不是缺啥

#21楼 @sunyy 尝试在脚本启动appium的时候最前面加上ideviceinstaller所在位置的环境变量。如:"export PATH=\"/usr/local/bin\";

export PATH=${PATH}:${APPIUM_HOME}:${JAVA_HOME}:/Users/user/Library/Android/sdk/platform-tools:/usr/local/bin
我将环境变量加上之后还是会卡String[] cmds = {"/bin/sh","-c",cmd};
//Applications/Appium.app/Contents/Resources/node_modules/.bin
//String[] cmds = {"/bin/sh","-c","/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/main.js appium -a 127.0.0.1 -p 4723"};
process = Runtime.getRuntime().exec(cmds);
InputStreamReader reader = new InputStreamReader(process.getErrorStream());
BufferedReader input1 = new BufferedReader(reader);
String line1 = "";
while ((line1 = input1.readLine())!= null)
{

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">


Label
my.startup
ProgramArguments

sh
-c

launchctl setenv APPIUM_HOME /Applications/Appium.app/Contents/Resources/node_modules/.bin
lanchctl setenv ANDROID_HOME /Users/user/Library/Android/sdk
lanchctl setenv IDEVICEINSTALLER_HOME /usr/local/bin


RunAtLoad



加上也是这样

我把进程杀掉# lsof -i tcp:4723
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 740 user 11u IPv4 0xd766c650ff131c73 0t0 TCP localhost:4723 (LISTEN)
lijinhaideMacBook-Pro:LaunchAgents root# kill 740
之后才能打印出下面的信息
Appium] Welcome to Appium v1.5.3
[Appium] Non-default server args:
[Appium] address: '127.0.0.1'
[Appium] Appium REST http interface listener started on 127.0.0.1:4723

#23楼 @sunyy 卡在这里不动了?那就好好检查一下你的执行脚本处的代码吧。appium启动最好单独用一个线程,appium是阻塞式的命令,你这样会一直卡下去的

@adfghzhang 非常感谢我用了多线程之后命令是不会阻塞了

用java命令启动
Exception in thread "main" org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Could not find adb Please set the ANDROID_HOME environment variable with the Android SDK root directory path. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 323 milliseconds
运行的时候会报这个错误
我的bash如下:
export MAVEN_HOME=/Users/user/apache-maven-3.3.9
export M2=$MAVEN_HOME/bin
export PATH=$M2:$PATH
export ANDROID_HOME=/Users/user/Library/Android/sdk
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home
export APPIUM_HOME=/Applications/Appium.app/Contents/Resources/node_modules/.bin
export PATH=${PATH}:${APPIUM_HOME}:${JAVA_HOME}:/Users/user/Library/Android/sdk/platform-tools
我的 environment.plist 配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">


Label
my.startup
ProgramArguments

sh
-c

launchctl setenv APPIUM_HOME /Applications/Appium.app/Contents/Resources/node_modules/.bin
launchctl setenv ANDROID_HOME /Users/user/Library/Android/sdk
launchctl setenv PATH $PATH:/Users/user/Library/Android/sdk/platform-tools


RunAtLoad



~

我用gui是好的

System.out.println(System.getenv().get("ANDROID_HOME"));
我打印了下是null。
明明是配置了的

我在ide里配置了环境变量问题终于解决了

@sunyy 你好,我在10.11.6上遇到和同样的问题,我在eclipse里配置了环境还是运行失败,请问你知道怎么解决吗?

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up