Android ant build - won't load keystore - android

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.

Related

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.

How to continue if any of the antcall fails?

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?

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.

Categories

Resources