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

Appium连接Android模拟器时出现java.lang.IllegalAccessError错误求助

Appium连接Android模拟器时IllegalAccessError问题解决

环境信息

  • Eclipse
  • Appium-Server-GUI-windows-1.22.3-4
  • Android模拟器
  • 依赖:java-client-8.2.1.jar

测试代码

@Test
public void test() throws MalformedURLException{
    //fail("Not yet implemented");
    URL link = new URL("http://127.0.0.1:4723/wd/hub");
    //AndroidDriver driver;
    DesiredCapabilities capacidades = new DesiredCapabilities(); 
    capacidades.setCapability("platformName", "Android");
    capacidades.setCapability("appium:platformVersion", "13");
    capacidades.setCapability("appium:appActivity", "com.BancaxcxcxActivity");
    capacidades.setCapability("appium:appPackage", "com.banxxxv40");
    capacidades.setCapability("appium:deviceName", "sdk_gphone64_x86_64");
    
    // Inicio driver
    AndroidDriver driver = new AndroidDriver(link ,capacidades);
}

报错信息

java.lang.IllegalAccessError: tried to access method org.openqa.selenium.remote.http.ClientConfig.<init>(Ljava/net/URI;Ljava/time/Duration;Ljava/time/Duration;Lorg/openqa/selenium/remote/http/Filter;Ljava/net/Proxy;Lorg/openqa/selenium/Credentials;)V from class io.appium.java_client.AppiumClientConfig

    at io.appium.java_client.AppiumClientConfig.<init>(AppiumClientConfig.java:62)
    at io.appium.java_client.AppiumClientConfig.defaultConfig(AppiumClientConfig.java:79)
    at io.appium.java_client.remote.AppiumCommandExecutor.<init>(AppiumCommandExecutor.java:109)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:92)
    at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:117)
    at consolePruebasTest.TestMovil.test(TestMovil.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

问题原因

这个错误是Appium Java Client与Selenium版本不兼容导致的。java-client 8.2.1依赖特定版本的Selenium库,若项目中Selenium版本不匹配,AppiumClientConfig无法访问Selenium内部的ClientConfig构造方法(该方法为包级访问权限,版本不对会触发非法访问错误)。

解决步骤

  1. 匹配Selenium版本:java-client 8.2.1对应的兼容Selenium版本为4.5.0。如果是手动导入jar包,需替换项目中所有Selenium相关jar为4.5.0版本;如果用Maven/Gradle,直接在依赖中指定该版本,或让java-client自动引入兼容依赖。
  2. 替换过时API:DesiredCapabilities已被标记为过时,推荐使用AppiumOptions替代,修改后的代码如下:
@Test
public void test() throws MalformedURLException{
    URL link = new URL("http://127.0.0.1:4723/wd/hub");
    AppiumOptions options = new AppiumOptions();
    options.setPlatformName("Android");
    options.setPlatformVersion("13");
    options.setCapability("appium:appActivity", "com.BancaxcxcxActivity");
    options.setCapability("appium:appPackage", "com.banxxxv40");
    options.setCapability("appium:deviceName", "sdk_gphone64_x86_64");
    
    AndroidDriver driver = new AndroidDriver(link, options);
}
  1. 清理依赖冲突:在Eclipse中使用Maven Dependency Analyzer检查是否存在重复或冲突的Selenium依赖,移除旧的不兼容版本,确保项目中只有一套匹配的Selenium库。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 21:10:20