You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Appium创建AndroidDriver失败:NoClassDefFoundError问题求助

Fixing NoClassDefFoundError When Creating Appium AndroidDriver

Hey, let's work through this java.lang.NoClassDefFoundError: org/openqa/selenium/remote/ProtocolHandshake issue you're hitting while initializing your AndroidDriver.

What's Causing This?

This error comes down to a version mismatch or missing dependency between Appium Java Client and Selenium WebDriver. The Appium Java Client is built on top of Selenium, so specific client versions require matching Selenium versions. You're using Java Client 6.0.0, which needs a compatible Selenium version (typically around 3.11.0) — if your project has the wrong Selenium version or it's missing entirely, you'll get this class-not-found error.

Step-by-Step Solutions

1. Fix Your Maven Dependencies

First, open your pom.xml and ensure you have the correct Selenium version paired with Java Client 6.0.0. Here's the recommended setup:

<!-- Selenium WebDriver (matches Appium Java Client 6.0.0) -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.11.0</version>
</dependency>

<!-- Appium Java Client -->
<dependency>
    <groupId>io.appium</groupId>
    <artifactId>java-client</artifactId>
    <version>6.0.0</version>
</dependency>

If you had other Selenium versions in your pom before, remove them to avoid version conflicts.

2. Clean and Rebuild Your Maven Project

Old cached dependencies can cause odd issues, so run these commands to clear and re-download everything:

mvn clean install -U

The -U flag forces Maven to update dependencies, ensuring you get the exact versions you specified.

3. Double-Check Your DesiredCapabilities

While this error isn't directly from bad capabilities, incomplete configs can cause initialization failures too. Make sure you have all required capabilities set:

DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
dc.setCapability(MobileCapabilityType.DEVICE_NAME, "your-device-name"); // e.g., "emulator-5554" or your physical device's name
dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UIAUTOMATOR2");
dc.setCapability(MobileCapabilityType.APP, "/path/to/your/app.apk"); // Or use APP_PACKAGE + APP_ACTIVITY if the app is already installed

Missing key capabilities might lead to unexpected failures during driver setup, so it's worth verifying.

4. Verify Appium Server Compatibility

You tested Appium Server 1.7.2 and 1.8.1, which are compatible with Java Client 6.0.0, but if you still run into issues after fixing dependencies, try upgrading to Appium Server 1.9.x — it's a more stable match for Java Client 6.x.

Quick Additional Checks

  • Make sure your IDE (IntelliJ/Eclipse) has loaded all Maven dependencies correctly. Sometimes you need to right-click the project and select "Refresh Maven Dependencies" to fix missing jars.
  • Check your project's classpath to confirm the Selenium jar is included. If it's missing, Maven might have failed to download it — re-run the clean install command.

内容的提问来源于stack exchange,提问作者picstand

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:39:03