1
votes

I am trying to run a simple script, which launches an app. This worked fine when I was using Android 6.0 but fails on android 7.0

This is the script -

                DesiredCapabilities capabilities= new DesiredCapabilities();

                capabilities.setCapability("deviceName","Moto G4 Plus");
                capabilities.setCapability("platformName","Android");
                capabilities.setCapability("platformVersion","7.0.");


                capabilities.setCapability("appPackage","com.bigbasket.mobileapp");
                capabilities.setCapability("appActivity","com.bigbasket.mobileapp.activity.HomeActivity");

                AndroidDriver driver= new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

                Thread.sleep(4000);

This is the error Log -

error: Failed to start an Appium session, err was: Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c "C:\Users\gadiisha\AppData\Local\Android\android-sdk\platform-tools\adb.exe -s ZY2237WRTC install "D:\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk"" Failed to install D:\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]

info: [debug] Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c "C:\Users\gadiisha\AppData\Local\Android\android-sdk\platform-tools\adb.exe -s ZY2237WRTC install "D:\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk"" Failed to install D:\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]

at ChildProcess.exithandler (child_process.js:751:12)
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: Command failed: C:\WINDOWS\system32\cmd.exe /s /c \"C:\Users\gadiisha\AppData\Local\Android\android-sdk\platform-tools\adb.exe -s ZY2237WRTC install \"D:\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk\"\"\nFailed to install D:\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]\r\n)","killed":false,"code":1,"signal":null,"cmd":"C:\WINDOWS\system32\cmd.exe /s /c \"C:\Users\gadiisha\AppData\Local\Android\android-sdk\platform-tools\adb.exe -s ZY2237WRTC install \"D:\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk\"\"","origValue":"Command failed: C:\WINDOWS\system32\cmd.exe /s /c \"C:\Users\gadiisha\AppData\Local\Android\android-sdk\platform-tools\adb.exe -s ZY2237WRTC install \"D:\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk\"\"\nFailed to install D:\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]\r\n"},"sessionId":null} info: <-- POST /wd/hub/session 500 10506.783 ms - 1306

Details - 1. Appium for windows 2. appium version 1.4.16.1 3. eclipse (luna)

Solutions I have tried so far -

  1. Upgraded to the latest version of Appium - 1.6.5 (it didnt work so I downgraded to Appium 1.4.16.1

  2. deleted appium settings and unlock folders from the mobile device.

  3. deleted the app and then restarted the appium server and ran the scripts again after that

I have seen similar question on the portal but all of them just have lengthy discussions without proper solutions. Please help me to close this issue. Thanks

3

3 Answers

2
votes

This is a known issue for devices with Android OS Version 7.0

  1. Appium installs two apps (settings and unlocker) on the device while initializing the driver (And it works without any issues for non 7.0 os version devices).

  2. When you try to initialize the appium driver again on the same device then appium fails to install those two apps and fails to initialize the driver.

Solution: For Android OS 7.0, Before you start your appium server, You need to uninstall unlocker app and settings app from the device. You might be running your script on devices with different OS version, so its better to put a condition for uninstalling both the unlocker and setting app.

Below are the steps, However you can need to modify as per your requirements.

1.First get the OS version of the device through the adb command and store it in string.

  1. Lets consider you have stored the output of the above command in the string variable and then you can compare the value as below and execute adb commands to uninstall both the apps and your appium driver should initialize without any issues.

Below is the combined code snippet for both the above steps:

    String cmd = "adb shell getprop ro.build.version.release";

String osVersion=executeCommand(cmd);

    if(osVersion.contains("7"))
    {
        //uninstall io.appium.settings
        cmd="adb uninstall  io.appium.settings";
        executeCommand(cmd);

        //uninstall io.appium.unlock
        cmd="adb uninstall  io.appium.unlock";
        executeCommand(cmd);

    }

public String executeCommand(String cmd)
{
    String commandresponse="";
    try
    {
        Runtime run = Runtime.getRuntime();
        Process proc=run.exec(cmd);
        BufferedReader stdInput = new BufferedReader(new 
                InputStreamReader(proc.getInputStream()));

        BufferedReader stdError = new BufferedReader(new 
                InputStreamReader(proc.getErrorStream()));

        String response=null;
        while ((response = stdInput.readLine()) != null) 
        {
            if(response.length()>0)
            {
                commandresponse=commandresponse+response;
            }
        }

        while ((response = stdError.readLine()) != null) 
        {
            commandresponse=commandresponse+response;

        }
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    //System.out.println(commandresponse);
    return commandresponse;
}

NOTE : Above code snippet is written considering there is only one device connected to the machine so that all the adb commands goes to that device only. If you have connected more than one device to the machine then you can either disconnect the device which is not in use or add the deviceSerialNumber parameter in the above adb commands in your code.

Hope this helps :)

1
votes

Run adb -s device_serial uninstall io.appium.settings and adb -s device_serial uninstall io.appium.unlock before running the script.

0
votes

After doing work around was able to fix the issue try uninstalling the app before you run your automation and execute following commands in terminal

adb uninstall io.appium.settings
adb uninstall io.appium.unlock