appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.18k stars 752 forks source link

bug: IllegalAccessError when starting AndroidDriver in Appium 9.1.0 #2124

Closed MasterfieldProject closed 4 months ago

MasterfieldProject commented 4 months ago

Do I have the most recent component updates?

Is the component officially supported by the Appium team?

Is there an existing issue for this?

Current Behavior

Using libs: io.appium:java-client:9.1.0 org.seleniumhq.selenium:selenium-java:4.17.0

When start the android driver it throws IllegalAccessError.

Stacktrace:
`java.lang.IllegalAccessError: class io.appium.java_client.remote.AppiumNewSessionCommandPayload tried to access method 'java.util.stream.Collector com.google.common.collect.ImmutableMap.toImmutableMap(java.util.function.Function, java.util.function.Function)' (io.appium.java_client.remote.AppiumNewSessionCommandPayload and com.google.common.collect.ImmutableMap are in unnamed module of loader 'app')

    at io.appium.java_client.remote.AppiumNewSessionCommandPayload.makeW3CSafe(AppiumNewSessionCommandPayload.java:40)
    at io.appium.java_client.remote.AppiumNewSessionCommandPayload.(AppiumNewSessionCommandPayload.java:54)
    at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:268)
    at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:162)
    at io.appium.java_client.AppiumDriver.(AppiumDriver.java:90)
    at io.appium.java_client.AppiumDriver.(AppiumDriver.java:102)
    at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:109)`

Expected Behavior

It should start the driver successfully.

Minimal Reproducible Example

UiAutomator2Options o = new UiAutomator2Options()
                .setPlatformName("Android")
                .setPlatformVersion("13")
                .setDeviceName("device")
                .setAutomationName("UiAutomator2");
driver = new AndroidDriver(new URL("http://localhost:4723"), o);

Environment

Link to Appium Logs

No response

Further Information

No response

mykola-mokhnach commented 4 months ago

You probably have some conflicting version of Google Guava lib in your dependency tree

MasterfieldProject commented 4 months ago

My project dependencies shows it is com.google.guava.guava:33.0.0.-jre lib. And that is the only one Guava lib in the dep. tree. Is this the compatible version?

MasterfieldProject commented 4 months ago

I found that however it is com.google.guava.guava:33.0.0-jre (which is compatible) set in the gradle build file, but at runtime the incompatible com.google.guava.guava:33.0.0-android version is set under the gradle cache.

MasterfieldProject commented 4 months ago

Here is the resolution. Force Gradle to use "-jre" version of Guava instead of "-android". dependencies.constraints { add("androidTestImplementation", "com.google.guava:guava") { attributes { attribute(TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE, objects.named(TargetJvmEnvironment.STANDARD_JVM)) } } }

Reference: https://github.com/google/guava/issues/6904 https://github.com/google/guava/issues/6801