1

For debugging reasons, I need to install more instances of my app. I found that the app identifier is located in binary AndroidManifest.xml in APK file so I don't have to mess with the app identifier at the project level that has unwanted consequences.

Note that there are similar questions on stackoverflow but none of them can answer this, as far as I know.

The rename should be as easy as running the following command: (where apk_dir is the directory where the original APK was extracted to)

aapt package -v --rename-manifest-package com.xyz.abc apk_dir

However, it merely enumerates all the resources in the apk directory. Nothing changes, no error message is printed. This is quite confusing - when I instruct a tool to make changes that it can't make, it should let me know clearly it was not done.

There are few 3rd party tools that I don't want to use because the official appt tool should be able to change the package name (and because the other tools have issues). It seems to be a powerfull tool but it is underdocumented. However, the help it prints seems promising:

--rename-manifest-package
   Rewrite the manifest so that its package name is the package name
   given here.  Relative class names (for example .Foo) will be
   changed to absolute names with the old package so that the code
   does not need to change.

It is also very unfortunate that there are two formats of AndroidManifest.xml. Besides the expected one there is the binary (compiled) manifest XML file that is packed into the APK file. This doesn't make reading documentation easier.

MazeGen
  • 180
  • 3
  • 14

2 Answers2

0

If you're using ANT-based builds, the Android SDK Tools 24.3 (and perhaps before) "aapt" task takes a "manifestPackage=<your_package>" argument and you can use this to repackage your APK. Copy the "-package-resources" target from the SDK's ant build.xml to your custom_rules.xml and add the additional argument.

dkneller
  • 937
  • 8
  • 10
  • Could you elaborate more on the custom_rules.xml file? My project doesn't seem to contain it. As far as I can google, this file is related to Ant build process, and my project is not built by Ant. – MazeGen Jul 31 '15 at 21:37
  • You're right. What I mentioned was for ANT-based builds. The SDK "android.bat" tool builds skeletal build.xml files and this file reads the contents of custom_rules.xml (if it exists) in the same folder. I've clarified the answer – dkneller Aug 02 '15 at 21:42
0

--rename-manifest-package changes the manifest package name in the (binary) AndroidManifest.xml, within the apk (not the source (text) AndroidManifest.xml).

You can examine the packaged (binary) version with aapt (d)ump. e.g.

aapt d xmltree myapp.apk AndroidManifest.xml

--rename-manifest-package first completes all the relative names into absolute names using the manifest package in the AndroidManifest.xml, then changes renames the manifest package to the new one from the command line.

I've only used it when an AndroidManifest.xml is being added in a aapt (p)ackage command. e.g.

aapt p -f --rename-manifest-package com.mynewpackagename -M AndroidManifest.xml -F myapp.apk -I android.jar -S res

I suggest: package an app with an AndroidManifest.xml that has a relative path for an activity, without renaming, and check the apk with aapt dump.

Then, package it with renaming, and use aapt dump to confirm what changed.


BTW the usage/help for aapt (d)ump is not very clear. From the dump e.g. above, you can work out that WHAT means one of the 7 lines below; and asset means something in the .apk, like AndroidManifest.xml.

aapt d[ump] [--values] [--include-meta-data] WHAT file.{apk} [asset [asset ...]]
   strings          Print the contents of the resource table string pool in the APK.
   badging          Print the label and icon for the app declared in APK.
   permissions      Print the permissions from the APK.
   resources        Print the resource table from the APK.
   configurations   Print the configurations in the APK.                                
   xmltree          Print the compiled xmls in the given assets.
   xmlstrings       Print the strings of the given compiled xml assets.
hyperpallium
  • 571
  • 5
  • 18