Ant Build Failed - android

I am trying to build an Android Project using Apache Ant through Command Line but it is giving me Build Failed with the following error statements:
Java.io.IOException: Cannot run Program. "..\android_sdk\platform-tools\aapt.exe"
D:\MediaSync\build.xml:429: Execute failed: java.io.IOException: Cannot run program "..\android_sdk\platform-tools\aapt.exe"
I am new to this thing so i am not getting any idea how to get over this error. Searched alot about it but still scratching my head..
Anybody any idea about it then please tell me.
EDIT: Here are parts of my Buil.xml file
<!-- General SDK location -->
<property name="sdk-folder" value="D:/sdk" />
<!-- Preset tools location -->
<property name="android-platform-tools" value="${sdk-folder}/platform-tools"/>
<!-- Tools -->
<condition property="aapt" value="${android-platform-tools}/aapt.exe" else="${android-platform-tools}/aapt" >
<os family="windows"/>
</condition>
<!-- Generate the R.java file for this project's resources. -->
<target name="resource-src" depends="init, localization, replace-template-values">
<echo>Generating R.java / Manifest.java from the resources...</echo>
<exec executable="${aapt}" failonerror="true">
<arg value="package" />
<arg value="-m" />
<arg value="-J" />
<arg value="${outdir-r}" />
<arg value="-M" />
<arg value="${outdir.manifest}/AndroidManifest.xml" />
<arg value="-S" />
<arg value="${resource-dir}" />
<arg value="-I" />
<arg value="${android-jar}" />
</exec>
</target>

Make sure aapt.exe is installed at the correct path relative to your build.xml file (../android_sdk/platform-tools). That path is likely relative to your project, but not the build.xml.

I encountered the same problem on a 64-bit fedora platform and finally worked it out following this: http://blog.mx17.net/2012/10/25/android-on-ubuntu-ioexception-on-aapt/
It had failed because of trying to run a 32-bit program on an 64-bit architecture.
Maybe this would help.

Your error message says:
D:\MediaSync\build.xml:429: Execute failed: java.io.IOException: Cannot run program "..\android_sdk\platform-tools\aapt.exe"
while your aapt.exe is located in:
C:\android-sdk-windows\sdk\platform-tools\aapt.exe\
Obviously the build.xml tries to search D:\ for android_sdk\platform-tools\aapt.exe, which is the wrong path.
There should be a property for you to specify the path of aapt.exe, or it reads from system's PATH varibles.
To get a solution, post the lines around line 429 in build.xml. In line 429, there should be a <exec> task, be sure to include the whole content of that task (copy from <exec ...> to </exec>).

There is a bug in the intellij android studio and perhaps other IDEs that points to platform-tools for some executables/libs that now live in build-toos. A workaround for now is to make sim-links fof the necessary files.
So on linux/mac
platform-tools$ ln -s ../build-tools/android-version-blah/bin/appt appt
and
platform-tools$ ln -s ../build-tools/android-version-blah/lib lib
for Windows, install LinkExtensions and replace ln with mklink and read the help from typing mklink with no args. In Windows, the file would be appt.exe

A quick fix you can do is copy the aapt.exe and lib folder from the build-tools to the platform-tools folder.

Related

Cannot run UIAutomator tests in latest version of Android SDK

I've upgraded to latest version of Android Studio (1.5) and SDK and now my UIAutomator tests, run from ant, don't work anymore (they used to, till Android Studio 1.0.x).
This is the script I use to run tests:
#echo off
cls
set ANDROID_HOME=C:\Users\xxxx\AppData\Local\Android\sdk
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_65
cmd /c ..\..\..\..\..\..\..\..\thirdparty\ant\bin\ant build
if ERRORLEVEL 1 goto end
:run
cmd /c adb push ..\..\..\..\..\..\..\app\libs\uiautomator.jar /data/local/tmp
cmd /c adb push .\bin\MyTestsUIAutomatorTest.jar /data/local/tmp
cmd /c adb shell uiautomator runtest MyTestsUIAutomatorTest.jar -c xxxxxx.haylugar.uiautomator.src.SettingsActivityUIAutomatorTest
cmd /c adb shell uiautomator runtest HayLugarUIAutomatorTest.jar -c xxxxxx.haylugar.uiautomator.src.ParkingListActivityUIAutomatorTest
cmd /c adb shell uiautomator runtest HayLugarUIAutomatorTest.jar -c xxxxx.haylugar.uiautomator.src.ParkingDetailActivityUIAutomatorTest
When building with ant, uiautomator.jar objects are not found:
src\ParkingDetailActivityUIAutomatorTest.java:3: error: package com.android.uiautomator.core does not exist
[javac] import com.android.uiautomator.core.UiObject;
Apparently, instructions have been changed according to this and this, but I followed them and they are missing something (I get an error when running tests saying that "no tests found to run"). Anyway, I just want to run my tests the same way I used to! I don't want to change configurations and waste time with the new nitty britty idea of the Android SDK team...
Fixed!
I needed to edit manually the build.xml to overwrite the compile and the dex targets of the uibuild.xml provided by the SDK to do the job correctly, copying the required libraries (uiautomator.jar and junit.jar) somewhere in my project structure:
<property name="jar.libs.dir" value="../../../../../../libs" />
<property name="jar.libs.absolute.dir" location="${jar.libs.dir}" />
<path id="classpath">
<fileset dir="${jar.libs.absolute.dir}">
<include name="uiautomator.jar" />
<include name="junit-4.12.jar" />
</fileset>
</path>
<!-- version-tag: VERSION_TAG -->
<import file="${sdk.dir}/tools/ant/uibuild.xml" />
<!-- overwrite the compile target in uibuild.xml to include to external
jars -->
<target name="compile" depends="-build-setup, -pre-compile">
<javac encoding="${java.encoding}" source="${java.source}"
target="${java.target}" debug="true" extdirs="" includeantruntime="false"
destdir="${out.classes.absolute.dir}" bootclasspathref="project.target.class.path"
verbose="${verbose}" fork="${need.javac.fork}">
<src path="${source.absolute.dir}" />
<classpath refid="classpath" />
<compilerarg line="${java.compilerargs}" />
</javac>
</target>
<!-- overwrite the -dex target in uibuild.xml to include external jar files
into the target dex file. -->
<target name="-dex" depends="compile, -post-compile">
<dex executable="${dx}" output="${intermediate.dex.file}"
nolocals="#{nolocals}" verbose="${verbose}">
<path path="${out.classes.absolute.dir}" />
</dex>
</target>
</project>

Executing `android update project` fails in ANT, can't find sdkmanager.jar

When trying to execute an android update on a project i am getting the following error. Using linux.
Here is the ant code (where ${directory} is the directory of an android project):
<exec
executable="/bin/bash"
failonerror="true">
<arg value="android"/>
<arg value="update"/>
<arg value="project"/>
<arg value="-p"/>
<arg value="${directory}"/>
</exec>
Here is the error:
[exec] android: can't find sdkmanager.jar
I have tried changing the permissions of sdkmanager.jar to 777 and it still gives the same error.
When executing the same command from a bash or shell script it works fine. And when running on the terminal it works fine.
What is causing this problem and how can i fix it?
If the script you are calling already contains the !/bin/sh at the top of the script you do not need to call the /bin/bash executable in the ant exec.
Therefore, if i change the code posted in the question to this...
<exec
executable="android"
failonerror="true">
<arg value="update"/>
<arg value="project"/>
<arg value="-p"/>
<arg value="${directory}"/>
</exec>
... it works fine.
Thanks, hope this helps someone in the future.

Android built apk with ant

I want to compile a cm9 theme using ant so I have this code given in the sample theme :
<?xml version="1.0" encoding="UTF-8"?>
<project name="TemplateTheme" default="help">
<!-- ADD YOUR ANDROID SDK PATH TO THIS FILE -->
<loadproperties srcFile="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- DON'T TOUCH THIS ONE -->
<loadproperties srcFile="default.properties" />
<!-- ADD YOUR KEYSTORE PROPERTIES HERE -->
<loadproperties srcFile="key.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'"
unless="sdk.dir"
/>
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />
<target name="-package-resources">
<echo>Optimizing theme resources</echo>
<exec executable="./prepare-resources" failonerror="true" />
<echo>Packaging theme resources</echo>
<exec executable="./aapt" failonerror="true">
<arg value="package" />
<arg value="-f" />
<arg value="-M" />
<arg path="AndroidManifest.xml" />
<arg value="-I" />
<arg path="${android.jar}" />
<arg value="-F" />
<arg path="${out.absolute.dir}/${resource.package.file.name}" />
<arg value="-S" />
<arg path="res-final" />
<arg value="-x" />
<arg value="10" />
</exec>
<echo>Cleaning up resources</echo>
<exec executable="./prepare-resources" failonerror="true">
<arg value="clean" />
</exec>
</target>
</project>
but when I execute I get the error :
cannnot run program ".\prepare-resources":Create Process Error=193, %1 is not a valid win32 Application
prepare-resources:
#!/bin/sh
if [ "$*" == "clean" ]; then
rm -rf res-final/
else
rm -rf res-final/
rsync -a res/ res-final/
echo "Themeing quasi-clone packages..."
rsync res-final/xml/com_cyanogenmod_trebuchet.xml res-final/xml/com_anddoes_launcher.xml
rsync res-final/xml/com_cyanogenmod_trebuchet.xml res-final/xml/com_teslacoilsw_launcher.xml
echo "Running pngcrush..."
for png in `find res-final/ -type f -name \*.png`; do
pngcrush -q $png $png.out 2>/dev/null >/dev/null && mv $png.out $png
done
fi
prepare-resources" is a shell script, not an executable. To be able to execute it, install cygwin, a UNIX-like environment that includes lots of software including shells capable of executing the script.
This page describes what packages you need and how to setup yourself.

Hudson Android multi-configuration test project can't find test results - "No test report files were found. Configuration error?"

I have android test project that i've integrated into the Hudson. I have created a free-style software project with next settings :
1. Source Code Management - custom workspace
2. Run an Android emulator during build :
* Android OS Version: 4.0.3
* Screen density: 240
* Screen resolution: WVGA
* Device locale: en_US
* SD card size: 16M
3. Invoke Ant:
Target: all clean emma debug install test
Build File: workspace/Project/build.xml
4. Post-build Actions
* Archive the artifacts: **/*test-TEST.xml
* Publish JUnit test result report: **/*test-TEST.xml
* Record Emma coverage report: **/coverage.xml
* Record fingerprints of files to track usage: **/*test-TEST.xml
Here's build.xml file part that covers my ant target:
<!-- version-tag: custom -->
<target name="test" depends="-test-project-check"
description="Runs tests from the package defined in test.package property">
<property name="tested.project.absolute.dir" location="${tested.project.dir}" />
<property name="test.runner" value="android.test.InstrumentationTestRunner" />
<!-- Application package of the tested project extracted from its manifest file -->
<xpath input="${tested.project.absolute.dir}/AndroidManifest.xml"
expression="/manifest/#package" output="tested.manifest.package" />
<xpath input="AndroidManifest.xml"
expression="/manifest/#package" output="manifest.package" />
<property name="emma.dump.file"
value="/data/data/${tested.manifest.package}/coverage.ec" />
<if condition="${emma.enabled}">
<then>
<echo>WARNING: Code Coverage is currently only supported on the emulator and rooted devices.</echo>
<run-tests-helper emma.enabled="true">
<extra-instrument-args>
<arg value="-e" />
<arg value="coverageFile" />
<arg value="${emma.dump.file}" />
</extra-instrument-args>
</run-tests-helper>
<echo>Downloading coverage file into project directory...</echo>
<exec executable="${adb}" failonerror="true">
<arg line="${adb.device.arg}" />
<arg value="pull" />
<arg value="${emma.dump.file}" />
<arg value="coverage.ec" />
</exec>
<echo>Extracting coverage report...</echo>
<emma>
<report sourcepath="${tested.project.absolute.dir}/${source.dir}"
verbosity="${verbosity}">
<!-- TODO: report.dir or something like should be introduced if necessary -->
<infileset dir=".">
<include name="coverage.ec" />
<include name="coverage.em" />
</infileset>
<!-- TODO: reports in other, indicated by user formats -->
<html outfile="${basedir}/coverage/coverage.html" />
<xml outfile="${basedir}/coverage/coverage.xml" />
</report>
</emma>
<echo>Cleaning up temporary files...</echo>
<delete file="coverage.ec" />
<delete file="coverage.em" />
<echo>Saving the report file in ${basedir}/coverage/coverage.html</echo>
</then>
<else>
<run-tests-helper />
</else>
</if>
<mkdir dir="${basedir}/junit-results" />
<echo>Base dir is ${basedir}</echo>
<exec executable="${adb}" failonerror="true" dir="${basedir}/junit-results">
<arg line="${adb.device.arg}" />
<arg value="pull" />
<arg value="/data/data/${tested.manifest.package}/files/" />
</exec>
</target>
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>
Now, this project works fine and i get both emma coverage and test results, but when i configured multi-configuration project with the same options, except for android emulator i set different variables with os, density and screen resolution, i got stuck with one error -
test:
[echo] WARNING: Code Coverage is currently only supported on the emulator and rooted devices.
[echo] Running tests ...
[exec]
[exec] com.mobclix.android.externaltestharness.test.UnitActivityTest:.
[exec] Test results for PolideaInstrumentationTestRunner=.
[exec] Time: 25.122
[exec]
[exec] OK (1 test)
[exec]
[exec]
[exec] Generated code coverage data to /data/data/com.mobclix.android.externaltestharness/coverage.ec
[echo] Downloading coverage file into project directory...
[exec] 355 KB/s (2043 bytes in 0.005s)
[echo] Extracting coverage report...
[echo] Cleaning up temporary files...
[delete] Deleting: /Users/biercoff/Work/Workspace/HarnessExternalTest/coverage.ec
[delete] Deleting: /Users/biercoff/Work/Workspace/HarnessExternalTest/coverage.em
[echo] Saving the report file in /Users/biercoff/Work/Workspace/HarnessExternalTest/coverage/coverage.html
[echo] Base dir is /Users/biercoff/Work/Workspace/HarnessExternalTest
[exec] pull: building file list...
[exec] pull: /data/data/com.mobclix.android.externaltestharness/files/com.mobclix.android.externaltestharness.test-TEST.xml -> ./com.mobclix.android.externaltestharness.test-TEST.xml
[exec] 1 file pulled. 0 files skipped.
[exec] 40 KB/s (499 bytes in 0.012s)
BUILD SUCCESSFUL
Total time: 1 minute 20 seconds
$ /Users/biercoff/.hudson/tools/android-sdk/platform-tools/adb disconnect localhost:53830
[android] Stopping Android emulator
[android] Archiving emulator log
$ /Users/biercoff/.hudson/tools/android-sdk/platform-tools/adb kill-server
Recording fingerprints
Recording test results
No test report files were found. Configuration error?
Archiving artifacts
Description set:
Emma: looking for coverage reports in the provided path: /Users/biercoff/Work/Workspace/HarnessExternalTest/coverage/coverage.xml
Emma: found 1 report files:
/Users/biercoff/Work/Workspace/HarnessExternalTest/coverage/coverage.xml
Emma: stored 1 report files in the build folder: /Users/biercoff/.hudson/jobs/MulitTestHarnessProject/configurations/axis-density/240/axis-os/4.0.3/axis-resolution/WVGA/builds/2012-05-18_17-26-05/emma
Emma: Coverage: Classes 21/39 (54%). Methods 40/128 (31%). Blocks 833/2928 (28%). Lines 154.5/528 (29%).
[DEBUG] Skipping watched dependency update for build: MulitTestHarnessProject/density=240,os=4.0.3,resolution
For emma coverage i had to change path in Hudson into /Users/biercoff/Work/Workspace/HarnessExternalTest/coverage/coverage.xml to make it work,
but when i tried to do the same thing for Junit test results, Hudson refused to "see" it. File is in the project folder under junit-results folder, but everytime i run new build, i get the same No test report files were found. Configuration error? error message. Tried many variations, but no luck. I'm missing probably something really tiny. Could somebody help me, please?
Hudson searches for jUnit test results relative to its workspace. And you can't specify an absolute path (I've been using Hudson/Jenkins for more than a year and still not sure why not). So in your case it is looking only at things that are deeper in the directory level than the workspace. Now, for a multi-congiguration project the workspace does not start at the top level, but deeper - it includes axes names (e.g.: workspace_root/AXIS1_NAME/AXIS1_VAL...). But your tests are located up the directory tree from that workspace. You have to copy them in a build step into ${WORKSPACE} and then Hudson will be able to publish them.

Use ant (build.xml) to compile jni directory

I'm using ant to build my android app (ant compile, ant install and so on) and I'm adding some NDK sources (inside jni/ directory) and I want to have a rule to recompile the jni/ directory with ant and THEN install my app into my device/emulator, like this:
$ ant jni-and-install
Instead of:
$ make -f jni/Makefile APP=myapp
(jni compilation & installation)
...
$ ant install
I was trying to find the place to put my rules in build.xml but I don't know where.
What should I edit for ant to call make on jni/ directory before installing into device?
You could use the exec ant task :
<target name="install">
<!-- ... -->
</target>
<target name="jni">
<exec executable="make">
<arg line="-f jni/Makefile APP=myapp"/>
</exec>
</target>
<target name="jni-and-install" depends="jni, install"/>
You can use an exec ant task for this. I think putting the following in your -pre-build target in build.xml will do the trick:
<exec executable="make" failonerror="true">
<arg line="-f jni/Makefile APP=myapp"/>
</exec>
Edit: JB's solution allows for things like ant jni to build the jni code without building the rest of your project. You can get the best of both worlds by wrapping the above in a target named "jni" and then adding depends="jni" to your -pre-build target.

Categories

Resources