Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 492
Mat Avatar asked Jul 06 '12 17:07

Mat


People also ask

What is Android binary XML?

Android uses a special format to save XML and resource files. Also resource files are XML files in the source folder, but all resources are packed into a single resource file called resources. arsc . The underlying format is chunk based and is capable for storing several different information.

How do I find AndroidManifest XML?

Just open your APK and in treeview select "AndroidManifest. xml". It will be readable just like that. and to edit it (that single file) without extracting other files?


2 Answers

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

like image 164
Mat Avatar answered Sep 28 '22 15:09

Mat


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]
like image 21
Talha Asghar Avatar answered Sep 28 '22 13:09

Talha Asghar