Alex Rivera | Logout

Repackage APK file to contain custom assets - what build tool to use?

Asked 2011-01-25T11:59:26.130
10

Update: This is an old post, and references below to broken aapt versions will be out of date.


Based on previous feedback, I am storing custom text fields in the assets directory of my app.

I will write the app, using default user details in an asset file, and the client would like to rebuild the app for each user, including that user's details in the asset file.

(I am aware this is method has some serious shortcomings, but the client is still keen to do it in this way - see Embed login details in APK file, different for each user (or other options?))

This question relates to troubles I am having with rebuilding the APK file, once I have unzipped it, and updated the custom asset file. I am quite convinced I am missing something small, however, the documentation and posts I have found on these methods are not helpful enough for a newcomer.

  1. aapt - Android sdk tool: Unfortunately the android docs on "Using aapt" on the android docs [link 2 below] are very limited. The console command -help shows a bit more info. When trying to use it to just add a file to the test.apk, it ends up deleting the original, and creating a new file test.apk.zip containing only the file I tried to add. I have not been able to find the correct command line combination to take an unzipped apk and repackage it - that would be my first prize.

  2. apkbuilder - Android sdk tool: Firstly this tool is deprecated, which is a negative point for it. I also can't get it to work with what I have in that unzipped folder. I think I'm missing a pre-apkbuilder step because apkbuilder asks for a resource zip archive, and I have a resource folder.

  3. ant - build tool: Other similar posts say to build with ant, rather than using the android tools. I am having trouble getti

Edit
Report

3 Answers

10

To answer my own question with the method we finally chose, and "for the record":

I was unable to get Ant working correctly for me (my lack of understanding).

I ended up using the aapt tool. It works as per the Android sdk documentation and really is quite simple to use:

aapt add -v Test.apk "assets/readme.txt"

This will add a readme.txt file (we were storing it in a subfolder of the current running folder, called assets. If you want to store the new file somewhere else, aapt does offer a command line switch to specify that)

However, there are some caveats:

  1. I couldn't get it to work on signed APK files.
  2. some versions of aapt don't work properly! They don't recognise the subfolder...

To solve 1:

  1. Export the APK from eclipse as an unsigned APK.
  2. Use the keytool to generate a key (see Android dev docs).
  3. Use aapt.
  4. Sign the APK using jarsigner.

To solve 2:

I can't really help with this. Every version of the SDK (on Mac) I tried to download included an aapt tool that did not recognize the subfolders. A colleague downloaded a version that worked, but we could still not figure out which version it was that he downloaded, so we kept this "magic" copy and renamed it and will be using it until we find a new version that works.

answered 2011-02-09T12:16:19.020
3

The simplest solution would be to give the template source of the app to your client with a script that rebuild the app from scratch.

This way your client simply have to change the assets in the folder, double click a batch file and get the apk in a minute or so.

You don't have to know anything about ANT to compile and package without the IDE, just follow the steps here :

http://developer.android.com/guide/developing/other-ide.html

The ANT script is generated by the "android create" "android update" commands. You then just need to run "ant release" and off you go.

answered 2011-01-25T12:34:57.277
2

A bit late, probably, but this post appears in lots of searches, so I thought this may be of interest.

I just used a standard Zip tool to 'unsign' the APK by removing the META-INF folder, updated any asset files, and then resigned the APK using jarsigner. (If I could find a way to sign JARs without using jarsigner, so we wouldn't need the Java SDK installed everywhere, this would be really useful - ideas anyone?)

answered 2011-05-19T03:34:47.290

Your Answer