File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "app/build/outputs/apk/");
File app = new File(appDir, "app-debug.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","Android");
capabilities.setCapability("appium-version", "1.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "Your package name");
capabilities.setCapability("appActivity", "MainActivity");
Explanation:
Line 1: Get the Path to your Project's Root Directory
O/P: classPathRoot: /Users/john.doe/AppiumProject/app
Line 2: Append the Path to the Directory of the folder where your ".apk" is placed, with the Project's Root Directory.
O/P: classPathRoot: /Users/john.doe/AppiumProject/app/build/outputs/apk/
Line 3: Append your ".apk" file name, with the Project's Root Directory(till your apk folder).
O/P: classPathRoot: /Users/john.doe/AppiumProject/app/build/outputs/apk/apk-debug.apk
Line 4 and onwards: Initiate Desired capabilitieas and set them as per your platform and device