10
votes

I this documentation:

Cordova documentation

I cloned the latest Cordova here: https://github.com/apache/cordova-android

But when I run "ant jar" as described in the documentation, I get this error:

cordova-android-master/framework/build.xml:124: Cannot find /Users/neigaard/Library/Android/sdk/tools/ant/build.xml imported from /Users/me/cordova-android-master/framework/build.xml

Google say that is because ant/build.xml was removed from Android SDK. I found a post saying that I should download a old Android SDK tools and replace my SDK tools folder with that, but I rely on my Android SDK to be working and up to date.

Is there no way to build the Cordova Android jar without an outdated Android SDK or is there somewhere I can download a pre-built jar or is there another way to integrate Cordova into a existing Android app?

2
Which android SDK version you are using?NullPointer
@Neigaard As per the cordova android 7.0.0 release (cordova.apache.org/announcements/2017/12/04/…), ant builds are officially deprecated and not supported anymore. So you may have to use gradle instead. Any tweaks to build using ant will be a workaround.Gandhi
The easiest way to do that is: Create Cordova app and move all your java sources there. It will take you around 1 hour instead to integrate Cordova into existing Android app. Every time you could fail on other pitfallMaxim Shoustin

2 Answers

2
votes

You don't really need the .jar anymore, Cordova is distributed through gradle, so you can just add this in the dependencies section of your app gradle file:

implementation 'org.apache.cordova:framework:7.1.0'

0
votes

Tutorial cordova.apache.org/docs/en/latest/guide/platforms/android/… looks outdated. If you just want to embed a cordova webview you don't really need the .jar anymore, Cordova is distributed through gradle, so you can just add this in the dependencies section of your app gradle file:

implementation 'org.apache.cordova:framework:7.1.0'

However if you want to create jar through ant then you don't required to use complete outdated Android SDK.You have to just place ant/build.xml in tools folder. Below are the steps to create corodva.x.x.x.jar on Windows

Step-1 Download Android tool package from below location: https://dl.google.com/android/repository/tools_r25.2.5-windows.zip

Step-2 Copy ant folder to
C:\Users\xxxx\AppData\Local\Android\sdk\tools

Step-3 Install Cordova using npm

npm install -g cordova

You can install specific version of cordova using cordova@version.

Step-4 Go to below location and copy your local.properties from your android project: C:\Users\xxxxx\.cordova\lib\npm_cache\cordova-android\x.x.xx\package\framework

Step-5 Navigate to the Android package's /framework directory and run ant jar. It creates the Cordova .jar file, formed as /framework/cordova-x.x.x.jar

FYI: It is recommended to refer the cordova requirements-and-support https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#requirements-and-support