Can't run appium file Java

I am a appium beginner and I am trying to start using appium to test android and ios apps. I have started with android “java” and i was wondering if anyone can help. I think it related to appium as i was unable to add package and activity as they are dropdowns and not textfileds so basically i can add package path.

This is my code:
public static void main(String[] args) throws Exception{

	WebDriver driver;
	
	  DesiredCapabilities caps = new DesiredCapabilities();
	    caps.setCapability("app-package", "com.app.shopper");
	    caps.setCapability("browserName", "");
	    caps.setCapability("platformName", "Android");
	    caps.setCapability("app-activity", "com.app.android.ui.LaunchActivity");
	    caps.setCapability("takesScreenshot", true);
	    caps.setCapability("version", "4.4.2");
	    caps.setCapability("deviceName","Galaxy S4");
	    caps.setCapability("device ID", "6f0ab945");
	    caps.setCapability("app", "C:\\Program Files\\selenium\\build-tools\\19.1.0\\app.apk");
	driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), caps);
	
	
	driver.findElement(By.linkText("Register")).click();


}
}

And this the error log:

Exception in thread “main” org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Command failed: Exception in thread “main” java.lang.RuntimeException: Unable to rename input apk. C:\Program Files\selenium\build-tools\19.1.0\Shopitize.apk
at s.Sign.sign(Sign.java:421)
at s.Sign.main(Sign.java:532)
) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 71.83 seconds
Build info: version: ‘2.46.0’, revision: ‘87c69e2’, time: ‘2015-06-04 16:17:10’
System info: host: ‘Shopitize001’, ip: ‘192.168.1.155’, os.name: ‘Windows 8.1’, os.arch: ‘amd64’, os.version: ‘6.3’, java.version: ‘1.8.0_51’
Driver info: org.openqa.selenium.remote.RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:605)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:128)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:155)
at appium.androidTest.main(androidTest.java:36)

I will really appreciate it if anyone can help. Thanks

Hi,

Could you check adding the apk in any other location on your machine?

Thanks,
Sujata

You can leave settings blank (unchecked) in the Appium GUI if you provide them in your code.

The problem may be that you are giving both appPackage / appActivity and app capabilities. Use appPackage and appActivity if your apk is already on device. Use app if you want Appium to install the apk on every launch.

Also you wrote app-package and app-activity as server arguments instead of capabilities (appPackage and appActivity). It may be a problem.

In your app path there is a simple “” instead of a double at one point. Is it okay?

One last thing is you don’t need main in Appium java projects.

Hi,

Thanks for the suggestions but still doesnt work. i look at different tutorials and i used one that has a simple concept so i can make it work first and i realised that I was not using ‘TestNG’ so i installed that and I run it using TestNG. Here is a new version of the code:

public class androidTest {

WebDriver driver;

@BeforeClass
public  void setUp() throws Exception{
	
	
	  DesiredCapabilities caps = new DesiredCapabilities();
	    caps.setCapability("app-package", "com.appName.shopper");
	    caps.setCapability("browserName", "Android");
	    caps.setCapability("platformName", "Android");
	    caps.setCapability("app-activity", "com.appName.android.ui.LaunchActivity");
	   // caps.setCapability("takesScreenshot", true);
	    caps.setCapability("version", "5.0.2");
	   // caps.setCapability("deviceName","device");
	    caps.setCapability("deviceName", "BH90KHTBOD");
	    caps.setCapability("app", "C:\\Program Files\\selenium\\build-tools\\19.1.0\\appName.apk");
	driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), caps);
}
@Test
public void testCal() throws Exception {
	
	driver.findElement(By.id("onRegister")).click();
	
}
@AfterClass
public void teardown(){
	
	driver.quit();
}


}

**this is the error console:

=========================================

[TestNG] Running:
C:\Users\Gaetan\AppData\Local\Temp\testng-eclipse-1969668610\testng-customsuite.xml

FAILED CONFIGURATION: @BeforeClass setUp
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Command failed: Exception in thread “main” java.lang.RuntimeException: Unable to rename input apk. C:\Program Files\selenium\build-tools\19.1.0\appName.apk
at s.Sign.sign(Sign.java:421)
at s.Sign.main(Sign.java:532)
) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 9.85 seconds
Build info: version: ‘2.46.0’, revision: ‘87c69e2’, time: ‘2015-06-04 16:17:10’
System info: host: ‘Shopitize001’, ip: ‘192.168.1.155’, os.name: ‘Windows 8.1’, os.arch: ‘amd64’, os.version: ‘6.3’, java.version: ‘1.8.0_51’
Driver info: org.openqa.selenium.remote.RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:605)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:128)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:155)
at appium.androidTest.setUp(androidTest.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

SKIPPED CONFIGURATION: @AfterClass teardown
SKIPPED: testCal

===============================================
Default test
Tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1


Hi,

Could you check if app path is proper in your script:

C:\Program Files\selenium\build-tools`9.1.0\appName.apk

and in the error log you see this:
C:\Program Files\selenium\build-tools\19.1.0\appName.apk

Thanks,
Sujata

yh that fine i think when i copied i must have changed it

Thanks ,You are right.my app was in C disk