Android signing with Ant

If you have Ant version < 1.8.3 (ant -version) try this approach for the issue with JDK 7 (based on the previous answer):

  1. 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 &quot;@{signedjar}&quot;" />
                <arg line="&quot;@{jar}&quot; @{alias}" />
            </exec>
        </sequential>
    </macrodef>
    
  2. 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.

Leave a Comment