如何设置 aapt add 命令添加文件的路径
我正在使用 aapt 工具从我的 apk 的不同文件夹中删除一些文件。这很好用。
但是当我想向 apk 添加文件时,aapt 工具 add 命令不允许我指定要添加文件的路径,因此我只能将文件添加到 apk 的根文件夹中。 这很奇怪,因为我认为开发人员永远不会想将文件添加到 apk 的子文件夹(例如 res 文件夹)。这可以通过 aapt 或任何其他方法实现吗?因为从任何文件夹中删除文件都可以正常工作,而添加文件仅适用于 apk 的根文件夹。无法将其用于任何其他文件夹。
谢谢
I'm using aapt tool to remove some files from different folders of my apk. This works fine.
But when I want to add files to the apk, the aapt tool add command doesn't let me specify the path to where I want the file to be added, therefore I can add files only to the root folder of the apk.
This is strange because I don't think that developers would never want to add files to a subfolder of the apk (res folder for example). Is this possible with aapt or any other method? Cause removing files from any folder works fine, and adding file works only for the root folder of the apk. Can't use it for any other folder.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
aapt 工具保留在 add 命令中指定的目录结构,如果您想将某些内容添加到 apk 中的现有文件夹中,您只需在系统上有一个类似的文件夹,并且必须指定要添加的每个文件,完整列出该目录。示例
将添加的 pic1.png 位于终端 res/drawable-hdpi/ 的当前工作目录中的文件夹中,希望这能回答您的问题
The aapt tool retains the directory structure specified in the add command, if you want to add something to an existing folder in an apk you simply must have a similar folder on your system and must specify each file to add fully listing the directory. Example
The pic1.png that will is added resides in a folder in the current working directory of the terminal res/drawable-hdpi/ , hope this answered your question
实际上,
aapt
中存在一个错误,该错误会导致这种情况随机发生。它应该工作的方式正如其他答案所声明的那样:保留路径,除非您传递-k
。让我们看看它是如何实现的:控制路径是否被忽略的标志是
mJunkPath
:变量位于一个名为
Bundle
的类中,并由两个访问器控制:这个 用户在命令行指定
-k
,它被设置为true
:并且,当将数据添加到文件时,会进行检查:
不幸的是,应用程序使用的
Bundle
实例在堆栈上的main
中分配,构造函数中没有对mJunkPath
进行初始化,因此该值变量是随机的;如果没有办法将其显式设置为 false,在我的系统上,我(似乎是确定性的)无法在指定路径添加文件。但是,您也可以只使用
zip
,因为 APK 只是一个 Zip 文件,并且zip
工具可以正常工作。(郑重声明,我还没有将这个简单的修复程序作为 Android 的补丁提交,如果其他人想要这个世界可能会是一个更好的地方。我在 Android 代码提交过程中的经验是必须忍受极其复杂的提交机制,最终花了六个月的时间才有人回复我,在某些情况下,只要他们的提交过程不是那么复杂,就可以进行一些细微的修改,因为有一个非常简单的过程。这个问题的解决方法,我认为没有必要再次烦恼所有这些问题。)
There is actually a bug in
aapt
that will make this randomly impossible. The way it is supposed to work is as the other answer claims: paths are kept, unless you pass-k
. Let's see how this is implemented:The flag that controls whether the path is ignored is
mJunkPath
:This variable is in a class called
Bundle
, and is controlled by two accessors:If the user specified
-k
at the command line, it is set totrue
:And, when the data is being added to the file, it is checked:
Unfortunately, the one instance of
Bundle
used by the application is allocated inmain
on the stack, and there is no initialization ofmJunkPath
in the constructor, so the value of the variable is random; without a way to explicitly set it tofalse
, on my system I (seemingly deterministically) am unable to add files at specified paths.However, you can also just use
zip
, as an APK is simply a Zip file, and thezip
tool works fine.(For the record, I have not submitted the trivial fix for this as a patch to Android yet, if someone else wants to the world would likely be a better place. My experience with the Android code submission process was having to put up with an incredibly complex submission mechanism that in the end took six months for someone to get back to me, in some cases with minor modifications that could have just been made on their end were their submission process not so horribly complex. Given that there is a really easy workaround to this problem, I do not consider it important enough to bother with all of that again.)