Mat
Mat

Reputation: 336

How to convert XML to Android Binary XML

I'm creating a piece of software that can deploy Android apps but the AndroidManifest that is located within the apk file is in a custom binary XML format. What I am trying to find out is if there is a tool that will allow me to add my own AndroidManifest.xml file into an apk (converting it to AXML when it is added), or is the format explained anywhere so I can create my own converter

Upvotes: 7

Views: 14111

Answers (3)

Talha Asghar
Talha Asghar

Reputation: 116

xml2axml.jar

After a lot of research I have found a tool on Github which allows us to convert axml (Binary AndroidManifest.xml) to xml (Readable AndroidManifest.xml) and vice versa.

Download the xml2axml.jar file of the tool from release page here and then you can use these commands to decode axml and encode xml files.

Encoding xml files to axml:

java -jar xml2axml e [AndroidManifest-readable-in.xml] [AndroidManifest-bin-out.xml]

Decoding axml files to xml:

java -jar xml2axml d [AndroidManifest-bin-in.xml] [AndroidManifest-readable-out.xml]

Upvotes: 3

Check out 'apktool': http://ibotpeaches.github.io/Apktool/

It can decode resources to nearly original form and rebuild them after making some modifications; it makes possible to debug smali code step by step. Also it makes working with an app easier because of project-like file structure and automation of some repetitive tasks like building apk, etc.

Upvotes: 2

Mat
Mat

Reputation: 336

Figured this out using the Android packaging tool (aapt.exe)

aapt.exe package -f -m -J src -M AndroidManifest.xml -S res -A assets  -0 "" -I android.jar -F MyApp.apk

According to the docs:

-f
    force overwrite of existing files

-m
    make package directories under location specified by -J

-J
    specify where to output R.java resource constant definitions

-M
    specify full path to AndroidManifest.xml to include in zip

-S
    directory in which to find resources. Multiple directories will be scanned and the first match found (left to right) will take precedence

-A
    additional directory in which to find raw asset files

-0
    specifies an additional extension for which such files will not be stored compressed in the .apk. An empty string means to not compress any files at all.

-I
    add an existing package to base include set

-F
    specify the apk file to output

This takes a plain xml manifest and packages it into binary XML and inserts it into the apk.

Unfortunately it requires that the resources and assets be present (if you refer to them within the manifest file itself). I also have to add any other data back into the apk file. Not ideal but it works at least

Upvotes: 10

Related Questions