Appium test: working locally but failing in TestDroid cloud

Below code works with Appium client locally (version: but fails with TestDroid cloud:

private static AppiumDriver<MobileElement> driver;
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("testdroid_target", "Android");
capabilities.setCapability("deviceName", "Android Device");
capabilities.setCapability("testdroid_username", TESTDROID_USERNAME);
capabilities.setCapability("testdroid_password", TESTDROID_PASSWORD);
capabilities.setCapability("testdroid_project", "My Test Project");
capabilities.setCapability("testdroid_testrun", "AndroidDriver 1");
capabilities.setCapability("testdroid_device", "Nvidia Shield Tablet"); //Free  device
capabilities.setCapability("testdroid_app", fileUUID); 
driver = new AndroidDriver<MobileElement>(new URL(""), capabilities);

It fails to create the AppiumDriver instance above, with exception:

java.lang.NoClassDefFoundError: org/openqa/selenium/internal/HasIdentity

From Appium Log of other successful Appium TestDroid runs, I can see Apppium version is 1.4.3: “info: Welcome to Appium v1.4.3”. So, my above code should have worked.

The Sample code by Testdroid uses very old version of Appium and this runs successfully:

private static AppiumDriver wd;
wd = new AppiumDriver(new URL(TESTDROID_SERVER+"/wd/hub"), capabilities);

in( )

This uses very old version of Appium Java Client-1.7.0 while my code uses 3.1.0. I want to use this new version of Appium Java client for its new features. Since TestDroid Appium version is latest, my code should have worked.

Can some one please help me with this.

The answer is posted here: