new AndroidDriver报错java.lang.NoSuchMethodError: com.google.common.base.Throwables.throwIfUnchecked

xiaoxiao2021-02-28  129

创建new AndroidDriver初始化时候报错:报错java.lang.NoSuchMethodError: com.google.common.base.Throwables.throwIfUnchecked

在手机UI自动化项目开发中,使用appium框架进行开发,发生不少依赖冲突问题。项目使用spring cloud + appium手机UI自动化框架进行开发。appium版本4.1.2。

在appium初始开发中,发现driver = new AndroidDriver(new URL(appiumServerUrl), capabilities); 语句报错,appium对应的driver session已经正常创建,app应用已经启动,但出现此报错无法继续操作。 java.lang.NoSuchMethodError: com.google.common.base.Throwables.throwIfUnchecked(Ljava/lang/Throwable;)V

详细报错日志如下

java.lang.NoSuchMethodError: com.google.common.base.Throwables.throwIfUnchecked(Ljava/lang/Throwable;)V at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:176) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644) at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249) at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)

项目maven配置依赖如下:

<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <!-- <version>2.0.0.M2</version> --> <version>1.4.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <!-- <version>5.0.0-BETA9</version> --> <version>4.1.2</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> </exclusion> <!-- <exclusion> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-remote-driver</artifactId> </exclusion> --> </exclusions> </dependency> </dependencies>

解决思路

应该是jar依赖的问题,可能发送冲突,或者引入版本不对。查看com.google.common.base.Throwables.throwIfUnchecked 经过错误位置检查发现此类和方法在guava-19.0.jar依赖中,后面经过源码查看,确实该com.google.common.base下的类Throwables无此方法,应该是appium的一个bug。 后面经过修改maven配置排除guava依赖,然后手动更新此jar包依赖到guava-22.0.jar后项目运行正常。

修改如下

<dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <!-- <version>5.0.0-BETA9</version> --> <version>4.1.2</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> </exclusion> <!-- <exclusion> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-remote-driver</artifactId> </exclusion> --> <exclusion> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>22.0</version> </dependency>

修改配置文件后,项目运行正常。

转载请注明原文地址: https://www.6miu.com/read-42464.html

最新回复(0)