How to add apk from URL in capabilities

I am trying to reference apk from url but not successful. Here is what I am trying -

capabilities.setCapability(“app”, new URL(“http://jenkinsserverurl:8181/job/projectname/apk/apkname.apk”));
.
.
.
driver = new RemoteWebDriver(new URL(“http://remote test url:4723/wd/hub”),capabilities);

Appium server throws following error :-

info: → POST /wd/hub/session {“desiredCapabilities”:{“app”:{“userInfo”:null,“query”:null,“hCode”:1439549959,“defaultPort”:80,“path”:“//.apk”,“protocol”:“http”,“ref”:null,“file”:“//.apk”,“port”:8181,“authority”:“:8181”,“host”:“”,“class”:“java.net.URL”},“appPackage”:“”,“appActivity”:“.MainActivity”,“browserName”:“”,“platformName”:“Android”,“version”:“4.4”,“deviceName”:“emulator-5554”,“platform”:“ANDROID”}}
error: Using local app, but didn’t end in .zip, .ipa or .apk

Tried multiple things but no success. Suggestions are welcome.

here it is:

FileUtils.copyURLToFile(URL, File) //download file
File appDir = new File(userDir, fileName); //set file
capabilities.setCapability(MobileCapabilityType.APP, appDir.getAbsolutePath());
1 Like

Thanks @Aleksei !!!

Although I am not sure why appium document says this parameter can be “The absolute local path or remote http URL to an .ipa or .apk file, or a .zip containing one of these”.

Hi @Aleksei,

FileUtils.copyURLToFile(URL, File) in this line what should I pass as my second parameter

change this to capabilities.setCapability("app", "http://jenkinsserverurl:8181/job/projectname/apk/apkname.apk");

@RahulKC
https://www.mkyong.com/java/java-how-to-download-a-file-from-the-internet/