错误:无法获取 Java 版本.安装Java了吗? [英] Error: Could not get the Java version. Is Java installed?
问题描述
我运行 Appium 服务器:
I run Appium server:
➜ ~ appium
info: Welcome to Appium v1.3.5 (REV a124a15677e26b33db16e81c4b3b34d9c6b8cac9)
info: Appium REST http interface listener started on 0.0.0.0:4723
info: Console LogLevel: debug
info: --> POST /wd/hub/session {"desiredCapabilities":{"appPackage":"com.grindrapp.android","appActivity":".activity.SplashActivity","platformVersion":"4.4.2","browserName":"","platformName":"Android","deviceName":"10.0.0.9:5555"}}
info: Client User-Agent string: Apache-HttpClient/4.3.4 (java 1.5)
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 090abe0c-36d9-4f9b-987a-f3b665045928
info: Starting android appium
info: [debug] Getting Java version
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
error: Failed to start an Appium session, err was: Error: Could not get the Java version. Is Java installed?
info: [debug] Error: Could not get the Java version. Is Java installed?
at /usr/local/lib/node_modules/appium/lib/devices/android/android-common.js:1040:17
at ChildProcess.exithandler (child_process.js:735:7)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1008:16)
at Socket.<anonymous> (child_process.js:1176:11)
at Socket.emit (events.js:107:17)
at Pipe.close (net.js:476:12)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Could not get the Java version. Is Java installed?)","origValue":"Could not get the Java version. Is Java installed?"},"sessionId":null}
info: <-- POST /wd/hub/session 500 316.738 ms - 222
^C
➜ ~ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_76.jdk/Contents/Home
我尝试运行此代码以发布到 Appium 服务器:
I try to run this code to post to Appium server:
public class AndroidTest {
private AppiumDriver driver;
@Before
public void setUp() throws Exception {
// File classpathRoot = new File(System.getProperty("user.dir"));
// File appDir = new File(classpathRoot, "../../../data/app/");
// File app = new File(appDir, "Facebook.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName","10.0.0.9:5555");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("platformName","Android");
//capabilities.setCapability("app", app.getCanonicalPath());
capabilities.setCapability("appPackage", "com.grindrapp.android");
capabilities.setCapability("appActivity", ".activity.SplashActivity");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
但是正如你所看到的,我收到了这个错误:
but as you can see I get this error:
info: [debug] Error: Could not get the Java version. Is Java installed?
我该如何解决这个问题?
how can I fix this?
我正在尝试自动打开我从 google play 下载的应用程序,但我没有它的 apk.
I'm trying to automatically open an app which i downloaded from the google play and I don't have its apk.
推荐答案
我认为这是您问题的最终解决方案.
I think this is the final solution for your problem.
与往常一样,在编辑之前制作文件的备份副本.
As always, make a backup copy of the file before editing.
编辑文件/usr/local/lib/node_modules/appium/lib/devices/android/android-common.js
Edit the file /usr/local/lib/node_modules/appium/lib/devices/android/android-common.js
在第 1034 行周围的 else if(stderr) 分支中:
In the else if(stderr) branch around line 1034:
else if (stderr) {
var firstLine = stderr.split("\n")[0];
if (new RegExp("java version").test(firstLine)) {
javaVersion = firstLine.split(" ")[2].replace(/"/g, '');
}
}
替换代码读取:
else if (stderr){
if(new RegExp("java version").test(stderr)){
var regex = "java version \"[0-9]+\.[0-9]+\.[0-9]+";
var stderrstring = '' + stderr + '';
var regmatch = stderrstring.match(regex);
javaVersion = '' + regmatch + '' //convert object to string
javaVersion.replace(/"/g,'');
}
}
该代码应与常规 Java 版本响应消息以及您收到的响应消息一起使用.
The code should work with a regular java version response message plus the one that you are receiving.
这篇关于错误:无法获取 Java 版本.安装Java了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!