AndroidDriver giving ClassNotFoundException

I have been working through some of the tutorials on Appium, to try & find out how to use the thing. I have been working on this one: http://www.automationtestinghub.com/first-appium-test-script/

Here is my code:

AppiumDriver<MobileElement> driver = new AndroidDriver<MobileElement>(caps);

I have added java-client06.0.0-BETA2.jar to my build path.

When I try to run, I get this error: Exception in thread “main” java.lang.NoClassDefFoundError: com/google/common/base/Function
at tests.AppiumTest.main(AppiumTest.java:27)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)

What am I missing?

@stapes

I looked it up and it appears that there are some dependencies missing in the classpath. The link leads to github issue that pertains to Selenium, but since Appium is based on Selenium, I think it would be relevant in your case. Basically it says that “Selenium requires guava library to be in classpath.”.

To avoid dependency issues, I prefer to work with Gradle. I assume that you are working with Eclipse since the tutorial you linked to makes use of Eclipse.

In Eclipse → File → New → Project → Gradle Project. Name your project and click finish. Eclipse will initialize Gradle project for you.

Then open the file titled build.gradle and paste the following code into the file:

group ‘’
version ‘1.0-SNAPSHOT’

apply plugin: ‘java’

sourceCompatibility = 1.8

repositories {

mavenCentral()

}

dependencies {
testCompile group: ‘junit’, name: ‘junit’, version: ‘4.12’
testCompile group: ‘io.appium’, name: ‘java-client’, version: ‘6.0.0-BETA2’
}

Then right click on the project in the project explorer → Gradle → Refersh Gradle Project. That should fetch all the dependencies and allow you to execute your tests.

Let me know if it helped.

Thank you @Nivi_Mor. Your solution worked. I tried first the android version of Guava - that gave a completely different error, but when I added the regular version, everything worked & my app was launched on the device:

Using Maven:

<dependency>
  <groupId>com.google.guava</groupId>
  <artifactId>guava</artifactId>
  <version>23.6-jre</version>
  <!-- or, for Android: -->
  <version>23.6-android</version>
</dependency>
1 Like