本文介绍了如何使用aapt2,文档在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用aapt p打包资源并生成R.java.

I have used aapt p to package resources and generate R.java.

但是当我升级到Android 24时,发现了aapt2.exe.

But when I upgraded to Android 24, I found aapt2.exe.

我应该使用aapt2.exe吗?如何使用?我找不到有关它的任何文档.

Should I use aapt2.exe? How do I use it? I could not find any documentation about it.

推荐答案

AAPT和AAPT2的工作方式之间有很大的不同.

There are some big differences between how AAPT and AAPT2 work.

除新功能外,AAPT2的主要思想是将打包"步骤分为两步:编译"和链接".它提高了性能,因为如果仅更改一个文件,则只需要重新编译该文件并使用'link'命令链接所有中间文件即可.

The main idea behind AAPT2, apart from new features, is that it divides the 'package' step into two: 'compile' and 'link'. It improves performance, since if only one file changes, you only need to recompile that one file and link all the intermediate files with the 'link' command.

AAPT2尝试尽早捕获大多数错误.这就是为什么从AAPT切换到AAPT2时,您可能会遇到许多错误,指出某些元素嵌套不正确或某些引用不正确.有关新限制的更多信息,请参见 Android Studio 3.0文档.

AAPT2 tries to catch most bugs as early as possible. That's why when switching from AAPT to AAPT2 you might encounter many errors stating that some elements are nested incorrectly or that some references are incorrect. For more info on the new restrictiveness look at Android Studio 3.0 documentation.

Android Studio 3.0默认情况下启用AAPT2(带有Android Gradle插件3.0.0).但是,如果要在自己的脚本中使用AAPT2,则需要更改处理资源的方式.对于带有AAPT的"package"命令,您将使用-S传递资源目录.使用AAPT2,您首先需要使用'compile命令来编译每个资源,然后才使用-R标志传递所有已编译的文件.
例如:

Android Studio 3.0 comes with AAPT2 enabled by default (with Android Gradle Plugin 3.0.0). But if you want to use AAPT2 in your own script, you will need to change the way you process your resources.For the 'package' command with AAPT you would pass the resource directory with the -S. With AAPT2 you need to compile each resource first with the 'compile command and only then pass all the compiled files with the -R flag.
For example:

aapt package -S app/src/main/res/ ...

代替使用:

aapt2 compile -o compiled/res/ app/src/main/res/values/values.xml
aapt2 compile -o compiled/res/ app/src/main/res/drawable/myImage.png --no-crunch
...
aapt2 link -R compiled/res/values_values.arsc.flat -R compiled/res/drawable_myImage.flat ...

标志

标志用法上有更多差异,例如,在编译"步骤中,每个文件都使用"--pseudo-localize"和"--no-crunch"标志.有关AAPT2标志的完整信息,请输入:

Flags

There are more differences in flag usage, for example the both '--pseudo-localize' and '--no-crunch' flags are used per file during the 'compile' step. For full information about AAPT2 flags type:

aapt2 compile -h
aapt2 link -h

这篇关于如何使用aapt2,文档在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-16 11:38