使用 aapt 重命名包名 [英] Rename package name using aapt

查看:58
本文介绍了使用 aapt 重命名包名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于调试原因,我需要安装更多应用实例.我发现应用标识符位于 APK 文件中的二进制 AndroidManifest.xml 中,因此我不必在项目级别混淆应用标识符,从而产生不必要的后果.

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.

请注意,stackoverflow 上也有类似的问题,但据我所知,没有一个可以回答这个问题.

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

重命名应该像运行以下命令一样简单:(其中 apk_dir 是原始 APK 提取到的目录)

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

然而,它只是枚举了apk 目录中的所有资源.没有任何变化,也没有打印错误消息.这很令人困惑 - 当我指示工具进行它无法进行的更改时,它应该让我清楚地知道它没有完成.

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.

我不想使用的 3rd 方工具很少,因为官方 appt 工具应该能够更改包名称(并且因为其他工具有问题).它似乎是一个强大的工具,但它的文档不足.然而,它打印的帮助似乎很有希望:

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.

同样很遗憾的是AndroidManifest.xml有两种格式.除了预期的文件之外,还有打包到 APK 文件中的二进制(编译的)清单 XML 文件.这不会让阅读文档变得更容易.

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.

推荐答案

--rename-manifest-package 更改(二进制)AndroidManifest.xml 中的清单包名称,在 apk(不是源(文本)AndroidManifest.xml).

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

您可以使用 aapt (d)ump 检查打包的(二进制)版本.例如

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

aapt d xmltree myapp.apk AndroidManifest.xml

--rename-manifest-package 首先使用AndroidManifest.xml中的manifest包将所有相对名称补全为绝对名称,然后在命令行中修改manifest包为新名称.

--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.

我仅在 aapt (p)ackage 命令中添加 AndroidManifest.xml 时使用它.例如

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

我建议:使用具有活动相对路径的 AndroidManifest.xml 打包应用程序,无需重命名,并使用 aapt dump 检查 apk.

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.

然后,重命名打包,使用aapt dump确认修改了什么.

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

顺便说一句,aapt (d)ump 的用法/帮助不是很清楚.从转储,例如上面,您可以计算出 WHAT 表示以下 7 行之一;并且 asset 表示 .apk 中的某些内容,例如 AndroidManifest.xml.

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.

这篇关于使用 aapt 重命名包名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆