Documentation of available Ant tasks for Android? - android

I just accidentally discovered the ant task for test coverage reports with emma.
I'm now looking for a target that only invokes the unit test and generates unit testing output.
Is there a list with the available ant targets somewhere, or is it possible to look them up somewhere inside the code of the SDK?

Is there a list with the available ant targets somewhere, ...
You can get a list of all ant targets with -projecthelp and -verbose. While in the root directory of the project:
$ ant -projecthelp -verbose
The private ones show under the heading "Other targets:", but the targets with a leading dash are impossible to invoke from the command line. You can add a "wrapper" target to your build.xml and simply make it depend on the target you want.
I use ones like this for exposing the main targets to the IntelliJ IDEA platform:
<!-- Wrapper targets for setting up IntelliJ IDEA with Ant Build -->
<target name="Android clean" depends="clean" />
But you could also do something like:
<target name="Generate Resource Source" depends="-resource-src" />

Is there a list with the available ant
targets somewhere
Not that I am aware of. I can't even see how to get Ant to dump a list. :-(
is it possible to look them up
somewhere inside the code of the SDK?
They're on your development machine in $ANDROID_HOME/platforms/$API/templates, where $ANDROID_HOME is where you installed the SDK and $API is some Android version (e.g., android-2.1).

ant help would display all the available targets with detailed description.
Help target is at the end of ${SDK.HOME}/tools/ant/build.xml

Related

Automated unit testing for Android / Ant

I have an Android project and JUnit tests in my code.
I wanted to know if there is an ant task to run some tests.
In fact, I have several classic tests which are run using JUnit to test several methods, and some tests that need an android emulator or at least need to be run on an android device.
As I didn't find any documentation, I wanted to know if it's possible to do that kind of thing.
Like
junit-android dir="."...
Thanks a lot for your help and time.
Just to be clear because I've search on the web and didn't find many things, so hope you can help.
I have an Android project that contains NO activities.
Actual build.xml file:
I compile java source code
It generates me a .jar file.
I need to run some tests defined in my project/tests/ folder, using
the previous generated library. Thoses tests need to be runned on an
emulator device using ANT build file, whithout being dependent of
Eclipse.
Project:
src (java source code)
gen
bin
res
tests (Android test project)
AndroidManifest.xml
build.xml
...
The test project generated is containing a build.xml that has been automatically generated using android update command. Sadly, there is no task "run-tests". And how do I specify that I would like to use my library for those tests?
Everything you need to create and run android test projects from the command line, provided by Google itself ;-)
http://developer.android.com/tools/testing/testing_otheride.html
The command line you need is something like:
adb shell am instrument -w <test_package_name>/<runner_class>
To call that from Ant, use the <run-tests/> task, described here.
Create a target in your build.xml like this
<target name="run-tests">
<test-junit includedTests="pathToPackageContainingTests}/*.class" />
</target>
Then you can simply do this
ant clean release run-tests

android aapt in eclipse

i saw some info regarding this question in several threads but non suited my condition.
I have an android application which i now need to customized some resources and code.
For the time being i have some problems using android library so i have an ant build that copies base resources and Assets plus specific ones to my android project and than changes the package name in the manifest as needed. All my activity have constant path and non relative to the package name so that's not an issue.
The problem is with the R object in the gen folder that is generated in the aapt. aapt does have a parameter to not use the android manifest package but another one, but it's available only if i use the ant build file, the parameters for the ADT are hard coded in the plugin.
has anyone found solution to this ? i mean i can always use ant task to change all R references (imports) but it looks to me error prone. Any way except wrapper script that wont do it on windows to customize aapt ?
again... no answer for my question, i'll start thinking you guys got something against me.
in short, i see there's no solution, the things i can do:
use ant task that regexps all the import com....R; to the new package - disadvantage: even the smallest issue with the regexp i may mess something up in the code that will show only in runtime.
use wrapper script around aapt.exe or aapt binary that adds --custom-package my.package.name that even if i change the manifest package will keep the original R files, for both ant and eclipse - disadvantage, some: 1. on windows this needs to be an exec file as eclipse looks for one it took me a while to build one properly in C, on linux\mac this could be a script of any kind so we need 2 versions of it\ 2. every update to the SDK we need to install the wrapper all over again.
edit the ant tasks jar code to allow --custom-package and edit the adt source code to enable in the menu custom parameters - this is great feature that should be included! but the disadvantage is until the code is accepted (if it is accepted) and added to the SDK itself , i'll needs to merge my changes every new SDK emerges, unlike #2 this is a lot harder.
I chose option #2, for now i have executable for windows, and i'll check options for Linux and mac (probably simple bash script) once i'm there, and i'll create a python installation script and save it all in the svn along with my build project.
Good luck to everyone....

How do I build just the LatinIME package from AOSP?

I'm trying to test some changes that I made to the LatinIME package in AOSP. The problem is, that the documentation only shows how to build the entire thing.
What I really need to know is how to build a single package (in this case, LatinIME), from the command line
edit: What isn't made clear (at least to me), is that in the repo root directory, you can type make PACKAGE (e.g. `make LatinIME'), and it will build that. I haven't tested it thoroughly, but it does appear to build all the prerequisites of the required package as well.
I think you want the mm or mmm command. See this documentation
Building only an individual program or module
If you use build/envsetup.sh, you can use some of the defined functions to build only a part of the tree. Use the 'mm' or 'mmm' commands to do this.
The 'mm' command makes stuff in the current directory (and sub-directories, I believe). With the 'mmm' command, you specify a directory or list of directories, and it builds those.
To install your changes, do 'make snod' from the top of tree. 'make snod' builds a new system image from current binaries.

How to filter files in the generated test coverage report by EMMA, using Ant in Android

I have an Android project and I am correctly generating test coverage reports using Ant and EMMA (I did it by following the instructions here: https://wiki.jenkins-ci.org/display/JENKINS/Building+an+Android+app+and+test+project)
What I would like to know is how can I filter the files that appear in the report generated by EMMA (for example, the R generated classes, files in an already tested library...).
I included both ${sdk.dir}/tools/ant/test_rules.xml and ${sdk.dir}/tools/ant/main_rules.xml in my own build.xml file and there I tried to change the "-emma-instrument" target to look like that:
<target name="-emma-instrument" depends="compile">
<echo>Instrumenting classes from ${out.absolute.dir}/classes...</echo>
<!-- It only instruments class files, not any external libs -->
<emma enabled="true">
<instr verbosity="${verbosity}"
mode="overwrite"
instrpath="${out.absolute.dir}/classes"
outdir="${out.absolute.dir}/classes">
<filter excludes="*R*" />
</instr>
<!-- TODO: exclusion filters on R*.class and allowing custom exclusion from
user defined file -->
</emma>
</target>
I also tried to apply another variations of EMMA coverage filters specified here http://emma.sourceforge.net/reference_single/reference.html#instrset.filters, but that does not work either, and the R generated files still appear in the coverage report.
Anybody knows how to solve this?
Update: Filtering is built in as of revision r18 of the android SDK, just see my answer to the linked question.
There is another question asking for this, where you've been already the half way down the road. To solve your issue just make sure, that you do not modify the test projects build file, but the one of the target project. I've got really no clue what kind of ant magic is involved in the android app build files, but of course to some extend your target projects build file must play an important role, so it's kinda logical that you've got to specify the coverage modification within the target project.
It took me the whole morning to sort this thing out, so I hope it's of some value for other developers.
As a side note, this functionality should be built-in as of revision 16 of the SDK tools.

Upgraded to 2.3, now ant builds don't include the jars in my libs directory

I've been doing all my builds using ant on the command line (Ubuntu 10.04). I loaded up the 2.3 SDK and made the necessary path changed (platform-tools). Now my builds don't include the jars in my libs directory. Any thoughts on what I need to change?
The Ant build system now requires Ant 1.8+
Unfortunately it "works" (broken) with 1.7 because we rely on a new behavior in 1.8, not a new task or attribute that would break 1.7
i'm not familiar with the ant builde for android as i'm usig eclipse(why shouldn't ou ? it generates build.xml autotmatically).
In any case whe you say platform tools you mean $ANDROID_HOME/platforms/android-9 ?
Are you sure it's needed for ant ? i know the ant build file itself is pretty empty and most of the work is done in their java .sh files so it's ard to tell what they are missing, cold it be you found a bug in their new SDK ?
I've got other more serious problems with SDK2.3 (the AVDs are bust). I'd set up Ant builds OK to work on 2.2 and was looking to see if an Ant build would run. My custom build.xml overrode quite a bit of the stuff in ant_rules_r3.xml but still used some of it. I noticed that this has now been removed and replaced with main_rules.xml, which is a bit different. 'project.libraries' replaces 'android.libraries' for one thing. It's probably worth you looking at the differences if your build.xml was based on ant_rules_3.
I'm not going to look at it myself until my main problem is fixed.

Categories

Resources