【问题标题】:Android emulator Java shellAndroid 模拟器 Java shell
【发布时间】:2017-07-01 14:41:16
【问题描述】:

我正在开发测试生成工具,需要启动设备来执行测试用例。我有以下试用码

ProcessBuilder pb_d = new ProcessBuilder("emulator",  "-avd", "Nexus_5_API_19");
    try {
        System.out.println("Starting Device");
        Process process = pb_d.start();
        InputStream is = process.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);

        BufferedReader br = new BufferedReader(isr);
        String line;
        System.out.printf("Output of running \"emulator\",  \"-avd\", \"Nexus_5_API_19\"");

        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

但我收到以下错误:

java.io.IOException: Cannot run program "emulator": error=2, No such file or directory

我在运行时尝试过,但我得到了同样的错误。

【问题讨论】:

    标签: java android shell emulation


    【解决方案1】:

    尝试使用模拟器的完整路径或确保系统变量PATH已经配置了emulator.exe

    【讨论】:

    • 刚刚试过。没运气 :\ 。该命令在终端上运行良好。
    • 试试这个:new ProcessBuilder("cmd.exe","/C","start","emulator","-avd","Nexus_5_API_19");
    • 这是一个 mac 但我尝试了p = Runtime.getRuntime().exec("/usr/bin/open -a Terminal"); p.waitFor(); 并且它打开了终端但之后什么都没有:\ .
    • 没关系,我使用了模拟器的整个路径,它运行良好:)。不过感谢您的建议。我的环境变量中已经有了路径,但看起来我需要明确指定它。 :D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-07
    • 2017-07-28
    • 1970-01-01
    • 1970-01-01
    • 2016-04-04
    • 2017-07-17
    • 2019-02-18
    相关资源
    最近更新 更多