3

I have an Android app published on the Android Market. I prepare the builds for release by simply typing ant release. I have a keystore configured so that I can build the final signed, obfuscated, zipaligned market-ready APK in a single step. I have not modified any of the build.xml files other than to point them to my keystore.

Now, I need to release the app on the Amazon store too. This requires me to produce an unsigned build. As part of the process of building the normal release build as described above, a MyApp-release-unsigned.apk file is produced in the bin directory. This looks promising, except the timestamp of this file is earlier than the -unaligned.apk variant which is also produced. This suggests that the -unsigned.apk has not been zipaligned and is therefore not ready for release.

What modifications do I need to make to the build process so I can produce an (unsigned, obfuscated, zipaligned) Amazon-ready APK with a single command?

Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
Graham Borland
  • 60,055
  • 21
  • 138
  • 179

2 Answers2

5

Firstly, looking at the echo statements from my build.xml, you're right - the unsigned package is not aligned.

Assuming you are using the latest SDK then I modified the build.xml to make an extra file (projectname-release-unsigned-aligned.apk) like this:

Override the -set-release-mode target, by adding the line in between the comments

<target name="-set-release-mode" depends="-set-mode-check">
<property name="out.packaged.file" location="${out.absolute.dir}/${ant.project.name}-release-unsigned.apk" />
<!-- NEW PROPERTY FOR UNSIGNED ALIGNED FILE -->
<property name="out.unsignedaligned.file" location="${out.absolute.dir}/${ant.project.name}-release-unsigned-aligned.apk" />
<!-- NEW PROPERTY FOR UNSIGNED ALIGNED FILE END -->

Then add to the release target the line between the NEW zip comments

<!-- Zip aligns the APK -->
<zipalign-helper in.package="${out.unaligned.file}"out.package="${out.final.file}" />
<!-- NEW Zip aligns the unsigned APK -->
<zipalign-helper in.package="${out.packaged.file}" out.package="${out.unsignedaligned.file}" />
<!-- NEW Zip aligns the unsigned APK  END --> 

This should give you that extra unsigned and aligned file. I've not tested the resulting APK but it looks quite straightforward to change

NickT
  • 23,844
  • 11
  • 78
  • 121
  • Your suggested changes worked absolutely great, thanks. Using your answer as inspiration, I ended up modifying just the release target (not the -set-release-mode target) to remove the signing step altogether. (I have a separate build.xml for my Amazon build and my regular Android Market build.) – Graham Borland Jan 24 '12 at 14:12
  • 1
    Could you post the whole build.xml file please? I have a library project called `common`, which is referenced and I get this error: `BUILD FAILED /srv/android-sdk-linux_x86/tools/ant/build.xml:466: The following error occurred while executing this line: Target "${build.target}" does not exist in the project "common".` – Stefan Anca Jun 09 '12 at 15:49
3

You don't need to zipalign the package, because, according to this question, amazon will zipalign the package after they sign it.

And according to this page on the Android developer site, zip aligning of the unsigned package is useless, because the signing operation that amazon will do will de-align the package.

Community
  • 1
  • 1
Pascal Dimassimo
  • 6,908
  • 1
  • 37
  • 34