Edit image resources inside an android APK file

Today I had to change some image resources in a APK file, the process is easy once you know it, so I just post it here for future reference:

First use the tool “aapt” from the android SDK to list the resources:
$ANDROID/tools/aapt list file.apk

Once we locate the resources that we need to change, we use “remove” and “add” to replace them:

$ANDROID/tools/aapt remove file.apk res/drawable/file.png
$ANDROID/tools/aapt add file.apk res/drawable/file.png

Then we have to remove the old APK signature and replace it with a new one.
We will generate a fake self signed key to sign the APK:

$ openssl genrsa -out key.pem 1024
$ openssl req -new -key key.pem -out request.pem
$ openssl x509 -req -days 9999 -in request.pem -signkey key.pem -out certificate.pem
$ openssl pkcs8 -topk8 -outform DER -in key.pem -inform PEM -out key.pk8 -nocrypt

Remove the old signature from the APK:

for f in `$ANDROID/tools/aapt list file.apk |grep "META-INF"` ; do
$ANDROID/tools/aapt remove file.apk $f
done

And now we sign the APK, I use signapk.jar to do this:
$ java -jar signapk.jar certificate.pem key.pk8 file.apk file-signed.apk

That’s it, our APK is now ready to install… just remember to setup your android phone to allow installing applications from unknown sources :)

This entry was posted in android, linux and tagged , , , . Bookmark the permalink.

4 Responses to Edit image resources inside an android APK file

  1. truebit says:

    Thanks for the post. the aapt remove script part helped me a lot

  2. Tudic Filip says:

    hello
    I’m having some problems with de aapt’s add command. Remove and all other commands work fine but i can only use aapt add to add files to the root folder of the apk. It won’t let me set the path like in your example or any other path.
    So when I use this command: $ANDROID/tools/aapt add file.apk res/drawable/file.png it says that it can’t find the file file.png at this location: res/drawable/
    If i only use aapt add file.apk file.png it works fine. It adds the file to the root folder of the apk.
    If you have any ideea, that would be awesome.
    Thanks

  3. Mahesh says:

    Thanks, it helped me a lot.

  4. Koodari says:

    Sorry, but I’m not very good at this kind of things… Can you explain, where I’ll find out that “aapt” -program (?)? I want to change the moped at “ScooterHero” :)

    Does it work if I edit those resources with winrar and build that directory again to apk -file with apkbuilder?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>