7

The command cordova build android fails with the following output

BUILD FAILED
F:\Programs\SDK\tools\ant\build.xml:597: The following error occurred while executing this line:
F:\Programs\SDK\tools\ant\build.xml:649: The following error occurred while executing this line:
F:\Programs\SDK\tools\ant\build.xml:694: Execute failed: java.io.IOException: Cannot run program
"F:\code\asistenciaBT\platforms\android\CordovaLib\${aapt}" 
(in directory   "F:\code\asistenciaBT\platforms\android\CordovaLib"): CreateProcess error=2, 
El sistema no puede encontrar el archivo especificado

Meaning, as far as I can tell, that ant can't find the aapt file. Ant is installed:

ant -version
Apache Ant(TM) version 1.9.4 compiled on April 29 2014

ANDROID_HOME and PATH are correctly set as well. I have made cordova work on this system before, now it just refuses to.

Should cordova be looking for appt in the project directory? Shouldn't it be looking on ANDROID_HOME/build_tools ?

Some further detail, in case is needed:

npm -v
2.7.4

node -v
v0.12.2

cordova -v
5.1.1

os: windows 8.1 pro 64 bits

Project was cloned from github so it might have some inherited incompatibility somewhere.

EDIT:

Just tested 'cordova build' on a new project and it fails with the same error.

jlasarte
  • 583
  • 6
  • 27

7 Answers7

13

It looks like ant commands are broken in Android SDK 24.3, which cordova build is using. I downgraded to previous release (24.2.0) and ant works fine now.

You can download previous SDK from: http://dl-ssl.google.com/android/repository/tools_r24.2-windows.zip

EDIT: There is better solution, See kartikeya's answer below: https://stackoverflow.com/a/31603358/1453578

Also, if you're not using cordova but relying on ant to build your android project, just move to gradle already.

Community
  • 1
  • 1
Pranav Gupta
  • 894
  • 6
  • 11
  • Fyi: for the osx or linux versions of the tools zip, just replace "windows" with "macosx" or "linux". Howto downgrade: http://stackoverflow.com/questions/9555337/how-to-downgrade-my-sdk-version – th3hamm0r Jun 17 '15 at 09:30
  • Downgrading??? Downgrading anything is a best option for rusty developers. Instead of this, I highly recommend Kartikeya's solution. – Filip Veličković Aug 12 '15 at 17:47
3

no need to downgrade or upgrade your SDK. Follow this step. Go to .../sdk/tools/ant/build.xml and find there:

    <!-- find location of build tools -->
    <getbuildtools name="android.build.tools.dir" verbose="${verbose}" />

add below the lines:

    <property name="aidl" location="${android.build.tools.dir}/aidl${exe}" />
    <property name="aapt" location="${android.build.tools.dir}/aapt${exe}" />
    <property name="dx" location="${android.build.tools.dir}/dx${bat}" />
    <property name="zipalign" location="${android.build.tools.dir}/zipalign${exe}" />
2

SDK is broken ... downgrade to previous version ! i.e , ant version 1.9.4 TO Ant 1.9.5 or downgrade android skd tools

OverLink
  • 21
  • 3
2

ant build looks definitely broken. Even using an older SDK was still failing for me. I had Cordova 4.2. My solution was to switch to gradle build which is now the default in cordova 5. (so I guess you updated to Cordova 5 but did not update the android project)

$ npm install -g cordova

Project needs to be updated to use the gradle build

$ cordova platform update android

Building should now be using gradle

$ cordova build android
alextk
  • 4,079
  • 16
  • 30
2

Upgrading Android SDK Tools to 24.3.3 solves the problem.

Chris
  • 21
  • 1
0

Reverting back to 24.3.1 solves it.
osx: http://dl.google.com/android/android-sdk_r24.3.1-macosx.zip

more on this issue here: https://code.google.com/p/android/issues/detail?id=176488

oori
  • 5,057
  • 1
  • 27
  • 35
0

You need to use the following command:

 cordova platform update android@5.0.0
Syed Danish Haider
  • 1,126
  • 9
  • 14