"ant debug" Command and Build Error

This section provides a tutorial example on the 'ant' build command. An error occurred when running 'ant debug'. The error message says '...${aapt}': CreateProcess error=2, The system cannot find the file specified.

Based on the documentation, the Ant build file allows you build 2 types of binary outputs:

1. debug - Builds the application and signs it with a debug key. The 'nodeps' target can be used to only build the current project and ignore the libraries using: 'ant nodeps debug'.

2. release - Builds the application. The generated apk file must be signed before it is published. The 'nodeps' target can be used to only build the current project and ignore the libraries using: 'ant nodeps release'

Let me try to build the "debug" binary output first.

C:\>cd \herong\HelloAndroid

C:\herong\HelloAndroid>\local\apache-ant-1.9.5\bin\ant debug

Buildfile: C:\herong\HelloAndroid\build.xml

-set-mode-check:

-set-debug-files:

-check-env:
 [checkenv] Android SDK Tools Revision 24.3.2
 [checkenv] Installed at C:\local\android-sdk-windows

-setup:
     [echo] Project Name: HelloAndroid
  [gettype] Project Type: Application

-set-debug-mode:

-debug-obfuscation-check:

-pre-build:

-build-setup:
[getbuildtools] Using latest Build Tools: 22.0.1
     [echo] Resolving Build Target for HelloAndroid...
[gettarget] Project Target:   Android 5.1.1
[gettarget] API level:        22
[gettarget] WARNING: No minSdkVersion value set.
            Application will install on all Android versions.
     [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: C:\herong\HelloAndroid\bin\res
    [mkdir] Created dir: C:\herong\HelloAndroid\bin\rsObj
    [mkdir] Created dir: C:\herong\HelloAndroid\bin\rsLibs
    [mkdir] Created dir: C:\herong\HelloAndroid\gen
    [mkdir] Created dir: C:\herong\HelloAndroid\bin\classes

    [mkdir] Created dir: C:\herong\HelloAndroid\bin\dexedLibs
     [echo] ----------
     [echo] Resolving Dependencies for HelloAndroid...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency]
[dependency] ------------------
     [echo] ----------
     [echo] Building Libraries with 'debug'...
   [subant] No sub-builds to iterate on

-code-gen:
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
     [echo] Handling aidl files...
     [aidl] No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
     [echo] ----------
     [echo] Handling Resources...
     [aapt] Generating resource IDs...

BUILD FAILED
C:\local\android-sdk-windows\tools\ant\build.xml:649: The following
 error occurred while executing this line:
C:\local\android-sdk-windows\tools\ant\build.xml:694: Execute failed:
 java.io.IOException: Cannot run program
 "C:\herong\HelloAndroid\${aapt}": CreateProcess error=2, The system
 cannot find the file specified
  at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
  at java.lang.Runtime.exec(Runtime.java:620)
  at org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec
     (Java13CommandLauncher.java:58)
  ...
Total time: 0 seconds

Too bad, the build process failed. It looks like the "${aapt}" expression was not resulting to a path name for the "aapt" command. In other words, "aapt" was not a defined variable in the build.xml file.

I compared the Android SDK R24 installation with the old R17 installation, and found the following differences:

1. ${aapt} is no longer explicitly defined in R24 .\tools\ant\build.xml file:

In Android SDK R24:
    <property name="adb"
       location="${android.platform.tools.dir}/adb${exe}" />
    <property name="lint"
       location="${android.tools.dir}/lint${bat}" />

In Android SDK R17:
   <property name="adb"
      location="${android.platform.tools.dir}/adb${exe}" />
   <property name="zipalign"
      location="${android.tools.dir}/zipalign${exe}" />
   <property name="aidl"
      location="${android.platform.tools.dir}/aidl${exe}" />
   <property name="aapt"
      location="${android.platform.tools.dir}/aapt${exe}" />
   <property name="dx"
      location="${android.platform.tools.dir}/dx${bat}" />
   <property name="renderscript"
      location="${android.platform.tools.dir}/llvm-rs-cc${exe}"/>

2. Location of "aapt.exe" is changed:

In Android SDK R24:
   C:\local\android-sdk-windows\build-tools\22.0.1\aapt.exe

In Android SDK R17:
   C:\local\android-sdk-windows-R17\platform-tools\aapt.exe

Searching on the Internet does not get any good information. So I decided reinstall "Android SDK Tools 24.3.3" and "Android SDK Build-tools 22.0.1" with Android SDK Manager.

See next tutorial on the result of "ant debug".

Table of Contents

 About This Book

 Installing JDK 1.8 on Windows System

 Installation of Android SDK R24 and Emulator

 Installing Apache Ant 1.9 on Windows System

Developing First Android Application - HelloAndroid

 Creating Android Project with "android" Command

 Listing Target Android Platforms

 "HelloAndroid" - First Android Project

 "HelloAndroid.java" - First Android Java Code

"ant debug" Command and Build Error

 Building the Debug Binary Package

 Installing the Debug Binary Package

 Running the Debug Binary Package

 Android Application Package (APK) Files

 Android Debug Bridge (adb) Tool

 Android File Systems

 AboutAndroid - Application to Retrieve System Information

 android.app.Activity Class and Activity Lifecycle

 View Objects and Layout Resource Files

 Using "adb logcat" Command for Debugging

 Build Process and Package File Content

 Building Your Own Web Browser

 Android Command Line Shell

 Samsung Galaxy Tab 3 Mini Tablet

 USB Debugging Applications on Samsung Tablet

 Android Tablet - LG-V905R

 USB Debugging Applications on LG-V905R Tablet

 Android Phone - LG-P925g

 USB Debugging Applications on LG-P925g Phone

 Archived Tutorials

 References

 Full Version in PDF/EPUB