0
votes

Original error: The JAVA_HOME environment variable must be set for Android Tools to work properly

My code:

    DesiredCapabilities capabilities = new DesiredCapabilities();
    
    capabilities.setCapability("BROWSER_NAME", "Android");
    capabilities.setCapability("VERSION", "9.0");

    // ZY224HFLPG is device name
    capabilities.setCapability("deviceName","ZY224HFLPG");
    capabilities.setCapability("platformName","Android"); 

    capabilities.setCapability("appPackage", "com.android.calculator2");
    capabilities.setCapability("appActivity","com.android.calculator2.Calculator"); 

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

Output:

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Cannot verify the signature of 'C:\Users\karakris\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v4.15.0.apk'.

Original error: The JAVA_HOME environment variable must be set for Android Tools to work properly

Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53' System info: host: 'LIN19003760', ip: '192.168.0.106', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '15.0.1' Driver info: driver.version: RemoteWebDriver remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Cannot verify the signature of 'C:\Users\karakris\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v4.15.0.apk'. Original error: The JAVA_HOME environment variable must be set for Android Tools to work properly at getResponseForW3CError (C:\Users\karakris\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:804:9) at asyncHandler (C:\Users\karakris\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:384:37) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) . . .

WHAT SHOULD HAVE TO DO?

2

2 Answers

0
votes

Below is the process to set environment variables in eclipse:

  1. Right click on java file which is to be executed/run.
  2. Select Run As--> Run Configurations
  3. Select Environment Tab
  4. Click on New Button and provide Env variable name and value
  5. Click on OK
  6. Click on Apply button.
  7. Close the window Done

Eclipse screen shot

0
votes

Do the following:

1. Set JAVA_HOME in Environment variables.

Steps:

  1. Right Click on My computer/This PC
  2. Select Properties>>Advanced system settings
  3. Select Environment variables
  4. In System Variables select New
  5. In Variable Name enter JAVA_HOME
  6. In Variable Value enter your java installation directory path e.g. C:\Program Files\Java\jdk-15.0.1

2. Set ANDROID_HOME in similar way. For example

Variable Name: ANDROID_HOME

Variable Value: Your android sdk path e.g. C:\Users\USERNAME\AppData\Local\Android\Sdk

3. Set desired capabilities for Android device by writing the following java code

    public class descap {

    public static AndroidDriver<AndroidElement> desiredCapabilities() throws 
    MalformedURLException{  
    
    DesiredCapabilities dcap=new DesiredCapabilities();
    
    dcap.setCapability(MobileCapabilityType.AUTOMATION_NAME,"uiautomator2");
    dcap.setCapability(MobileCapabilityType.PLATFORM_VERSION,"your version");
    // e.g. 9.0 is a device version
        
    dcap.setCapability(MobileCapabilityType.DEVICE_NAME,"your device name");
    // e.g. ZY224HFLPG is a device name
    dcap.setCapability(MobileCapabilityType.APP_PACKAGE,"com.android.calculator2");
    dcap.setCapability(MobileCapabilityType.APP_ACTIVITY,
    "com.android.calculator2.Calculator");
            
    AndroidDriver<AndroidElement> driver=new AndroidDriver<AndroidElement>(new 
    URL("http://127.0.0.1:4723/wd/hub"),dcap);
    return driver;
            
     }
    }

4. Check if your device or emulator is connected and working by executing following command in command prompt

    C:\Users\USERNAME>adb devices

5. Check if the Appium server is running and listening on port 4723. Else run appium server from the command prompt by executing following command

    C:\Users\USERNAME>appium

6. Execute your code.