Java io.appium 与 io.grpc 冲突

huangapple go评论77阅读模式
英文:

Java io.appium clashes with io.grpc

问题

我正在创建一些使用Java 11程序(使用Maven)进行Android测试,并使用gRPC与其他设备进行通信。

Appium依赖项

<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
   <groupId>io.appium</groupId>
   <artifactId>java-client</artifactId>
   <version>8.3.0</version>
</dependency>

gRPC依赖项

<dependency>
  <groupId>io.grpc</groupId>
  <artifactId>grpc-netty-shaded</artifactId>
  <version>1.53.0</version>
</dependency>
<dependency>
  <groupId>io.grpc</groupId>
  <artifactId>grpc-protobuf</artifactId>
  <version>1.53.0</version>
</dependency>
<dependency>
  <groupId>io.grpc</groupId>
  <artifactId>grpc-stub</artifactId>
  <version>1.53.0</version>
</dependency>

当我运行程序时,我遇到了错误。

警告:[org.testng.ITest]类[com.framework.DynamicTest]上的实现返回null。默认为方法名
java.lang.NoSuchMethodError: com.google.common.collect.ImmutableMap.toImmutableMap(Ljava/util/function/Function;Ljava/util/function/Function;)Ljava/util/stream/Collector;
	at io.appium.java_client.remote.AppiumNewSessionCommandPayload.makeW3CSafe(AppiumNewSessionCommandPayload.java:40)
	at io.appium.java_client.remote.AppiumNewSessionCommandPayload.<init>(AppiumNewSessionCommandPayload.java:54)
	at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:229)
	at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157)
	at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:80)
	at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:92)
	at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:117)

错误发生在我执行这一行时。

mobileDriver = new AndroidDriver(new URL(strURL), capabilities);

看起来AndroidDriver未被检测到。但是当我移除gRPC依赖时,它可以工作。

是否有可能解决使用io.appium与io.grpc的问题?

英文:

I'm create some java 11 program (use maven) which using Appium for android testing and gRPC to communicate with other device.

Appium Dependency

&lt;!-- https://mvnrepository.com/artifact/io.appium/java-client --&gt;
&lt;dependency&gt;
   &lt;groupId&gt;io.appium&lt;/groupId&gt;
   &lt;artifactId&gt;java-client&lt;/artifactId&gt;
   &lt;version&gt;8.3.0&lt;/version&gt;
&lt;/dependency&gt;

gRPC Dependency

&lt;dependency&gt;
  &lt;groupId&gt;io.grpc&lt;/groupId&gt;
  &lt;artifactId&gt;grpc-netty-shaded&lt;/artifactId&gt;
  &lt;version&gt;1.53.0&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
  &lt;groupId&gt;io.grpc&lt;/groupId&gt;
  &lt;artifactId&gt;grpc-protobuf&lt;/artifactId&gt;
  &lt;version&gt;1.53.0&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
  &lt;groupId&gt;io.grpc&lt;/groupId&gt;
  &lt;artifactId&gt;grpc-stub&lt;/artifactId&gt;
  &lt;version&gt;1.53.0&lt;/version&gt;
&lt;/dependency&gt;

When I run the program, I got error

Warning: [org.testng.ITest] implementation on class [com.framework.DynamicTest] returned null. Defaulting to method name
java.lang.NoSuchMethodError: com.google.common.collect.ImmutableMap.toImmutableMap(Ljava/util/function/Function;Ljava/util/function/Function;)Ljava/util/stream/Collector;
	at io.appium.java_client.remote.AppiumNewSessionCommandPayload.makeW3CSafe(AppiumNewSessionCommandPayload.java:40)
	at io.appium.java_client.remote.AppiumNewSessionCommandPayload.&lt;init&gt;(AppiumNewSessionCommandPayload.java:54)
	at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:229)
	at org.openqa.selenium.remote.RemoteWebDriver.&lt;init&gt;(RemoteWebDriver.java:157)
	at io.appium.java_client.AppiumDriver.&lt;init&gt;(AppiumDriver.java:80)
	at io.appium.java_client.AppiumDriver.&lt;init&gt;(AppiumDriver.java:92)
	at io.appium.java_client.android.AndroidDriver.&lt;init&gt;(AndroidDriver.java:117)

The error occurs when I hit this line

mobileDriver = new AndroidDriver(new URL(strURL), capabilities);

It's look like the AndroidDriver not detected. But when I remove gRPC dependency, it's work.

Is there a possible solution to using io.appium together with io.grpc?

答案1

得分: 1

在添加了guava依赖项(不是最新版本)之后,错误得到了解决。

<dependency>
   <groupId>com.google.guava</groupId>
   <artifactId>guava</artifactId>
   <version>31.1-jre</version>
</dependency>

感谢@San P提供的建议。

英文:

After add guava dependency (not the latest version), the error is resolved.

&lt;dependency&gt;
   &lt;groupId&gt;com.google.guava&lt;/groupId&gt;
   &lt;artifactId&gt;guava&lt;/artifactId&gt;
   &lt;version&gt;31.1-jre&lt;/version&gt;
&lt;/dependency&gt;

Thankyou to @San P for giving advice.

huangapple
  • 本文由 发表于 2023年7月13日 15:24:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76676879.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定