Using Ant, I\'m trying to build an Android application in release mode for distribution. My problem is at the signing process. I\'ve created a keystore and alias via Eclipse
If you're stuck (like me) with a version of Ant older than 1.8.3 and Java 7, here's a workaround:
<exec executable="${java.bin.path}/jarsigner">
<arg value="-signedjar"/>
<arg value="signed-${app.apk.name}"/>
<arg value="-keystore"/>
<arg value="my.keystore"/>
<arg value="-storepass"/>
<arg value="passwd"/>
<arg value="-sigalg"/>
<arg value="MD5withRSA"/>
<arg value="-digestalg"/>
<arg value="SHA1"/>
<arg value="${app.apk.name}"/>
<arg value="my_keystore"/>
</exec>
<!-- Where old version was: -->
<signjar
alias="my_keystore" keystore="my.keystore"
storepass="passwd"
preservelastmodified="true"
signedjar="signed-${app.apk.name}">
<path>
<fileset dir="." includes="${app.apk.name}" />
</path>
</signjar>
It sounds as you may be using JDK 7 (1.7.0) so try adding these options when signing with jarsigner:
-digestalg SHA1 -sigalg MD5withRSA
Per Android developer documentation, you should put these properties within the ant.properties file:
$ cat ant.properties
key.store=C:\\Users\\a512091\\.android\\release.keystore
key.alias=application
key.store.password=android
key.alias.password=android
Using Ubuntu 14.04 (Trusty Tahr) and Windows, create a “.keystore” file.
This file needs to be generated, which can be done with the keytool command that comes with Java. It can typically be found at ‘C:\Program Files\Java\jre7\bin’. Which also has to be added to your PATH variable.
Go to the root of your project and use this command:
Generating a .keystore file:
$ keytool -genkey -v -keystore key-name.keystore -alias alias-name -keyalg RSA -keysize 2048 -validity 10000
Create a file called ant.properties in the folder “platforms/android/” ant.properties.
key.store=D:\\path\\to\\the\\project\\keyname.keystore
key.alias=alias-name
Create the build APK file:
$ cordova build android --release
The long term solution is to patch Ant's signjar task:
https://issues.apache.org/bugzilla/show_bug.cgi?id=52344
The new attributes were added to signjar in Ant 1.8.3, but Android's build script (as of r19) has not yet been modified to utilize them:
http://code.google.com/p/android/issues/detail?id=19567
In the meantime, "presetdef" may provide a workaround:
<presetdef name="signjar">
<signjar sigalg="MD5withRSA" digestalg="SHA1" />
</presetdef>
If you have Ant version < 1.8.3 (ant -version) try this approach for the issue with JDK 7 (based on the previous answer):
Add signjarjdk7 to ANDROID_SDK\tools\ant\build.xml
<macrodef name="signjarjdk7">
<attribute name="jar" />
<attribute name="signedjar" />
<attribute name="keystore" />
<attribute name="storepass" />
<attribute name="alias" />
<attribute name="keypass" />
<attribute name="verbose" />
<sequential>
<exec executable="jarsigner" failonerror="true">
<!-- Magic key, always verbose -->
<arg line="-verbose -digestalg SHA1 -sigalg MD5withRSA" />
<arg line="-keystore @{keystore} -storepass @{storepass} -keypass @{keypass}" />
<arg line="-signedjar "@{signedjar}"" />
<arg line=""@{jar}" @{alias}" />
</exec>
</sequential>
</macrodef>
Replace 'signjar' to 'signjarjdk7' in 'release' target in the same build.xml.
NOTE: You have to define 'key.store.password' and 'key.alias.password' propeties for your project (in project.properties or in local.properties).
UPDATE 1:
If your have installed Ant 1.8.3 (or later) you have a better solution:
Open your ANDROID_SDK\tools\ant\build.xml and add two new parameters - sigalg and digestalg - in the original 'signjar' invocation:
<signjar
sigalg="MD5withRSA"
digestalg="SHA1"
jar="${out.packaged.file}"
signedjar="${out.unaligned.file}"
keystore="${key.store}"
storepass="${key.store.password}"
alias="${key.alias}"
keypass="${key.alias.password}"
verbose="${verbose}" />
UPDATE 2: It seems this answer is deprecated after 'signjar' was replaced to 'signapk' in latest version of Android SDK tools.