简体   繁体   English

使用aapt重命名包名称

[英]Rename package name using aapt

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. 我发现应用程序标识符位于APK文件中的二进制AndroidManifest.xml中,因此我不必在项目级别上弄乱具有不必要后果的应用程序标识符。

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) 重命名应该像运行以下命令一样简单:(其中apk_dir是原始APK提取到的目录)

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

However, it merely enumerates all the resources in the apk directory. 但是,它仅枚举apk目录中的所有资源。 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). 我不想使用第三者工具,因为官方的appt工具应该能够更改程序包名称(并且其他工具有问题)。 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. 同样不幸的是,AndroidManifest.xml有两种格式。 Besides the expected one there is the binary (compiled) manifest XML file that is packed into the APK file. 除了预期的一个以外,还有二进制(已编译)清单XML文件,该文件打包到APK文件中。 This doesn't make reading documentation easier. 这不会使阅读文档变得容易。

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. 如果您使用的是基于ANT的版本,则Android SDK Tools 24.3(可能之前)的“ aapt”任务将使用“ manifestPackage = <your_package>”参数,您可以使用它来重新打包APK。 Copy the "-package-resources" target from the SDK's ant build.xml to your custom_rules.xml and add the additional argument. 将“ -package-resources”目标从SDK的ant build.xml复制到您的custom_rules.xml并添加其他参数。

--rename-manifest-package changes the manifest package name in the (binary) AndroidManifest.xml, within the apk (not the source (text) AndroidManifest.xml). --rename-manifest-package更改apk中的(二进制)AndroidManifest.xml中的清单包名称(而不是源(文本)AndroidManifest.xml)。

You can examine the packaged (binary) version with aapt (d)ump . 您可以使用aapt (d)ump检查打包(二进制)版本。 eg 例如

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. --rename-manifest-package首先使用AndroidManifest.xml中的manifest包将所有相对名称完整为绝对名称,然后更改从命令行将manifest包重命名为新的。

I've only used it when an AndroidManifest.xml is being added in a aapt (p)ackage command. 我仅在aapt (p)ackage命令中添加AndroidManifest.xml时才使用它。 eg 例如

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 . 我建议:使用AndroidManifest.xml打包具有活动相对路径的应用程序,而不进行重命名,并使用aapt dump检查apk。

Then, package it with renaming, and use aapt dump to confirm what changed. 然后,使用重命名对其进行打包,然后使用aapt dump确认更改了什么。


BTW the usage/help for aapt (d)ump is not very clear. 顺便说一句, aapt (d)ump的用法/帮助不是很清楚。 From the dump eg above, you can work out that WHAT means one of the 7 lines below; 从上面的转储中,您可以算出WHAT意味着下面的7行之一; and asset means something in the .apk, like AndroidManifest.xml. asset表示.apk中的内容,例如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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM