AndroidDriver cant be initialized after mvn clean


As usually, before running mvn test i executed mvn clean, but this time a lot of things started downloading, once it finished i ran the code and got this error:

class org.openqa.selenium.Platform$22 cannot be cast to class java.lang.String (org.openqa.selenium.Platform$22 is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')

I actually didnt change anything, it just stop working (Last time I checked that this worked was 1 week ago)

This is the code that generates the error:

DesiredCapabilitiescap = new DesiredCapabilities();
URL url = new URL("");
cap.setCapability("platformName", "Android");
cap.setCapability("deviceName", "emulator-5554");
cap.setCapability("avd", "Pixel_4_API_30");
cap.setCapability("appPackage", "");
cap.setCapability("appActivity", "com.myapp.splash.SplashActivity");
cap.setCapability("automationName", "UiAutomator2");
cap.setCapability("noReset", "false");
AppiumDriver driver = new AndroidDriver(url, cap);


There could be version incompatibilities. When I got the same error, I made the following changes and it worked:

In the pom.xml upped the version of java-client to 8.1.0 and added additional dependency selenium-support with compatible version 4.2.0



Optionally, made changes to the way capabilities are set for platform. Replaced capabilities.setCapability("platformName", "android") with
capabilities.setCapability("appium:platformName", MobilePlatform.ANDROID)

import io.appium.java_client.remote.MobilePlatform;

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("appium:platformName", MobilePlatform.ANDROID);

Answered By – VanagaS

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published