Code-Apprentice Code-Apprentice - 4 months ago 23
Android Question

Setting the location of debug.keystore for command-line build without rewriting Ant targets

When I run "ant debug" from the command line, I get the following error message:

[apkbuilder] keytool error: java.io.FileNotFoundException: \stulab2\folderRedir
ection$.android\debug.keystore (The system cannot find the path specified)

BUILD FAILED
e:\programs\java\android-sdk\tools\ant\build.xml:919: The following error occurred while executing this line:
e:\programs\java\android-sdk\tools\ant\build.xml:930: The following error occurred while executing this line:
e:\programs\java\android-sdk\tools\ant\build.xml:295: com.android.sdklib.build.ApkCreationException: Unable to get debug signature key
at com.android.sdklib.build.ApkBuilder.getDebugKey(ApkBuilder.java:277)


A very long stack trace follows.

The problem is that I am on a public computer and do not have write access to the folder where Ant expects to find .android\debug.keystore. Some research found the following in the Android documentation:


If necessary, you can change the location/name of the debug keystore/key or supply a custom debug keystore/key to use. However, any custom debug keystore/key must use the same keystore/key names and passwords as the default debug key (as described above). (To do so in Eclipse/ADT, go to Windows > Preferences > Android > Build.)


Unfortunately, this doesn't explain how to change the locationof the debug keystore using the command-line tools.

Several months ago, someone asked basically the same question here on stackoverflow: Specify location of debug keystore for Android commandline/ant build. The best answer so far is to rewrite the -do-debug target. From what I can tell, I would also need to set the properties specified.

One problem with this answer is that it uses the same properites as the release build does. Also, it would be nice to simply set the correct properties rather than rewriting (and debugging) the whole -do-debug target. Does anyone know if there are properties that can be set to specify the location of the debug.keystore file?

Answer

In .bashrc, set the ANDROID_SDK_HOME environment variable to the location of your Android SDK installation. For example:

export ANDROID_SDK_HOME="/home/myusername/path/to/androidsdk"

Then, in a new shell, running ant debug creates a ${ANDROID_SDK_HOME}/.android/debug.keystore file.

Alternatively, without changing the variable globally, you can simply run:

ANDROID_SDK_HOME="/home/myusername/path/to/androidsdk" ant debug