javaandroidantappium-androidjava-client

Appium:java.lang.NoSuchMethodError: com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder;


I am getting the above error while trying to run an appium test. The jars I use are:

The jars in my lib folder:

The jars in my lib folder

My app is coming up after

driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), caps);

But in the next step,

driver.wait(5000);

it fails with the exception:

Exception I get

I am a beginner in appium, hence downloaded the jar files mentioned above looking at dependencies. I have tried multiple combinations of version numbers of jars, but it still gives the exception. Can you please let me know how to proceed? I use Ant to build the project.

I have also used java client 6.1.0, but using it doesn't even bring my app up. I have used the latest gson jar as well which is 2.8.5

My build.xml is as follows:

<?xml version="1.0" encoding="UTF-8"?>

<property name="build.dir" location="bin">
</property>
<property name="src.dir" location="src">
</property>
<property name="docs.dir" location="docs">
</property>
<property name="dist.dir" location="dist">
</property>
<property name="lib.dir" location="lib">
</property>
<property name="resources.dir" location="resources">
</property>
<path id="build.classpath">
    <fileset dir="${lib.dir}" includes = "gson-2.8.5.jar">
        <include name="*.jar"/>
    </fileset>
</path>
<pathconvert property="classpathProp" refid="build.classpath" />
<echo>Classpath is ${classpathProp}</echo>
<target name="init">
    <mkdir dir="bin"/>
    <mkdir dir="dist"/>
    <mkdir dir="docs"/>

</target>
<target name="clean">
    <delete dir="${build.dir}"/>
    <delete dir="${docs.dir}"/>
    <delete dir="${dist.dir}"/>
</target>
<target name="compile" depends="clean,init">
    <javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="build.classpath" includeantruntime="false">
    </javac>
</target>
<target name="main" depends="compile">
    <java classname="core.Trigger" classpath="${build.dir}" classpathref="build.classpath"></java>
</target>


Solution

  • For me, the issue was due to using the parent class Webdriver instead of Android driver. I was looking to make it work both for app and desktop. I have seen such a usage before, but for me it didnt work.