简体   繁体   English

无法通过appium在android模拟器中启动计算器

[英]Failed to launch calculator in android emulator through appium

I just create a sample code as below which is used to launch the calculator apk file and perform some task 我只是创建以下示例代码,用于启动计算器apk文件并执行一些任务

@BeforeSuite
    public static void driverInitalize() throws Exception {
        try {

            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("deviceName", "Android Emulator");
            capabilities.setCapability("platformName", "Android");
            capabilities.setCapability("platformVersion", "4.2.2");
            // capabilities.setCapability("browserName", "Chrome");
            capabilities.setCapability("appPackage", "com.android.calculator2");
            capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");
            capabilities
                    .setCapability("app",
                            "C:\\Ecare\\Appium\\com.android.calculator2-5.1-1720659-22-minAPI22.apk");
            driver = new RemoteWebDriver(
                    new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    @Test
    public static void sampleTest1() throws Exception {
        try {

            // System.out.println(driver.getTitle());
            driver.findElement(By.xpath(".//*[contains(text(),'7')]")).click();
            driver.findElement(By.xpath(".//*[contains(text(),'+')]")).click();
            driver.findElement(By.xpath(".//*[contains(text(),'3')]")).click();
            driver.findElement(By.xpath(".//*[contains(text(),'=')]")).click();
            String value = driver.findElement(
                    By.className("android.widget.EditText")).getText();
            System.out.print(value);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    @AfterSuite
    public static void tearDown() throws Exception {
        try {

            driver.quit();

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

Whenever I executed the above code will return following exception in appium server as well as in eclipse IDE. 每当执行以上代码时,appium服务器以及Eclipse IDE中都会返回以下异常。 Can somebody tell me how can I overcome this issue. 有人可以告诉我如何克服这个问题。 It seems to be the session is progress but I'm not sure how to kill the progress session which is started earlier. 这似乎是会话正在进行中,但是我不确定如何终止较早开始的进度会话。 I tried to start up the appium server as appium --no-reset, and checked in the override existing session as well but no luck. 我试图以appium --no-reset的形式启动appium服务器,并检查了覆盖现有会话,但是没有运气。

 Failure [INSTALL_FAILED_OLDER_SDK]
>     at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:1358:17
>     at [object Object].<anonymous> (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:180:9)
>     at ChildProcess.exithandler (child_process.js:635:7)
>     at ChildProcess.EventEmitter.emit (events.js:98:17)
>     at maybeClose (child_process.js:743:16)
>     at Process.ChildProcess._handle.onexit (child_process.js:810:5)
> info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Remote install failed: pkg: /data/local/tmp/b23beec2f0794d869eb021f75e3791bd.apk\r\r\nFailure [INSTALL_FAILED_OLDER_SDK])","origValue":"Remote install failed: pkg: /data/local/tmp/b23beec2f0794d869eb021f75e3791bd.apk\r\r\nFailure [INSTALL_FAILED_OLDER_SDK]"},"sessionId":null}
> info: <-- POST /wd/hub/session 500 39088.716 ms - 362 

Please help me out. 请帮帮我。

The error you are getting [INSTALL_FAILED_OLDER_SDK] is caused due to the version of android of your avd/device is older than the version being used to compile the code of the app. 您收到[INSTALL_FAILED_OLDER_SDK]的错误是由于您的avd /设备的android版本比用于编译应用程序代码的版本旧。 Check the target sdk version and the minimum sdk version of the app. 检查应用程序的目标sdk版本和最低sdk版本。

if you have the access to the source code of the app these information will be in the manifest file in the android:minSdkVersion tag. 如果您有权访问该应用程序的源代码,则这些信息将位于android:minSdkVersion标签中的清单文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM