How to continue if any of the antcall fails? - android

I am trying to run an ANT script. In which I am calling multiple targets.
<target name="mySuite">
<antcall target="TC1"> </antcall>
<antcall target="TC2"> </antcall>
<antcall target="TC3"> </antcall>
<antcall target="TC4"> </antcall>
<antcall target="TC5"> </antcall>
<antcall target="TC6"> </antcall>
.
.
.
</target>
My ANT script fails if any of the antcall target fail. But I want my ANT script to continue even any of he antcall target fails. What changes do I need to do?

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>

Ant Build Failed

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.

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.

Android ant build - won't load keystore

My ant build for a Flex air 3.0 project for android with native extensions returns this error message:
could not load keystore file (password may be incorrect)
I'm sure password, keystore file name and path are all correct. I've tried to change the keystore file location & path - project root, desktop, c:\certs - but the error message remains the same. I've tried paths with no whitespace in dir names. I've created new certs.
In build.properties my keystore is referenced like this:
KEYSTORE=C:\dev\projects\Certificates\AndroidCert.p12
STOREPASS=mypassword
The part of my build.xml that deals with the keystore looks like so:
<java jar="${ADT.JAR}" dir="${APP_BUILD}" fork="true" failonerror="true">
<arg value="-package"/>
<arg value="-target"/>
<arg value="apk"/>
<arg value="-storetype"/>
<arg value="PKCS12"/>
<arg value="-keystore"/>
<arg value="${KEYSTORE}"/>
<arg value="-storepass"/>
<arg value="${STOREPASS}"/>
<arg value="${APK_NAME}"/>
<arg value="${APP_XML}"/>
<arg value="${APP_SWF}"/>
<arg value="icons/"/>
<arg value="-extdir"/>
<arg value="${EXT_DIR}/"/>
</java>
Any help to explain the error is very much appreciated.
Run the command manually and check the output. Also check for trailing spaces in your properties file.

Categories

Resources