[英]Getting the aapt2 parameters of a gradle build?
I am interested in trying to compile an android application from the command line using aapt2. 我有兴趣尝试使用aapt2从命令行编译android应用程序。 I am having a problem linking the constraint-layout library when I try to perform the
aapt2 link
command. 尝试执行
aapt2 link
命令时,链接约束布局库时出现问题。 This program builds successfully from Android studio/gradle. 该程序可从Android studio / gradle成功构建。 How can I make gradle command line invocation show me the aapt2 command it is running?
如何使gradle命令行调用向我显示正在运行的aapt2命令?
For the record, I have tried to run ./gradlew assembleDebug --debug and all I can see is the calls to the aapt2-proto library. 作为记录,我尝试运行./gradlew assembleDebug --debug,我所看到的只是对aapt2-proto库的调用。
Link
链接
The command will be a bit complicated and will depend on many things (like your resources, the project's dependencies, flags used etc), so the easiest way to get the full command is to actually "break" a resource. 该命令会有点复杂,并且取决于很多事情(例如您的资源,项目的依赖项,使用的标志等),因此获取完整命令的最简单方法是实际“破坏”资源。
Edit your res/values/strings.xml file to contain:
编辑您的res / values / strings.xml文件以包含:
<string name="incorrect">@string/idontexist</string>
Go to the project's directory and run "gradlew clean assembleDebug". 转到项目目录,然后运行“ gradlew clean assembleDebug”。 AAPT2 will fail during linking and Android Gradle Plugin will print out the full command used.
AAPT2在链接期间将失败,并且Android Gradle插件将打印出所使用的完整命令。
I'm using version 3.2.0-alpha13 and it gives me the command in full: 我正在使用3.2.0-alpha13版本,它为我提供了完整的命令:
error: failed linking references.
Command: <path>/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.0-alpha13-4662957-linux.jar/cbe84ab07c48b199e5fe8d202dd5845e/aapt2-3.2.0-alpha13-4662957-linux/aapt2 link -I\
<path>/Android/Sdk/platforms/android-27/android.jar\
--manifest\
<path>/AndroidStudioProjects/Library/app/build/intermediates/merged_manifests/debug/processDebugManifest/merged/AndroidManifest.xml\
-o\
<path>/AndroidStudioProjects/Library/app/build/intermediates/processed_res/debug/processDebugResources/out/resources-debug.ap_\
-R\
@<path>/AndroidStudioProjects/Library/app/build/intermediates/incremental/processDebugResources/resources-list-for-resources-debug.ap_.txt\
--auto-add-overlay\
--java\
<path>/AndroidStudioProjects/Library/app/build/generated/not_namespaced_r_class_sources/debug/processDebugResources/r\
--proguard-main-dex\
<path>/AndroidStudioProjects/Library/app/build/intermediates/legacy_multidex_aapt_derived_proguard_rules/debug/processDebugResources/manifest_keep.txt\
--custom-package\
com.example.foo.bar\
-0\
apk\
--output-text-symbols\
<path>/AndroidStudioProjects/Library/app/build/intermediates/symbols/debug/R.txt\
--no-version-vectors
Daemon: AAPT2 aapt2-3.2.0-alpha13-4662957-linux Daemon #0
The flags used here for AAPT2: 此处用于AAPT2的标志:
Other flags that might be useful to you: 其他可能对您有用的标志:
Compile
编译
Compile command is pretty straightforward. 编译命令非常简单。 You basically tell AAPT2 which single file to compile and where to output it.
您基本上可以告诉APT2编译哪个文件以及在哪里输出。
<path>aapt2 compile -o /path/to/output/dir /path/to/file/to/compile.xml
The flags for compile are: 编译标志为:
One thing to keep in mind is that the compiled files are binary .flat files and the output name is based in the input name and the file's parent directory name. 要记住的一件事是,编译文件是二进制.flat文件,输出名称基于输入名称和文件的父目录名称。 That means if an input file was
res/drawable-450dpi/img.png the output file will be
drawable-450dpi_img.png.flat .
这意味着,如果输入文件为res / drawable-450dpi / img.png,则输出文件将为
drawable-450dpi_img.png.flat 。 Compiled values files get the extension "arsc.flat" instead of just ".flat", so a file
res/values-en/strings.xml will be compiled to
values-en_strings.arsc.flat .
编译后的值文件的扩展名为“ arsc.flat”,而不仅仅是“ .flat”,因此res / values-en / strings.xml文件将被编译为
values-en_strings.arsc.flat 。 This is done automatically by AAPT2 so you don't need to worry about it, but it's good to know in case you need to find the compiled file later on.
这是由AAPT2自动完成的,因此您不必担心,但是如果以后需要查找已编译的文件,很高兴知道这一点。
Another fun fact about compile is that it's nifty when it comes to remembering what the input file was (and the line numbers for XML files), so if linking fails the error won't point to the .flat file, but to the original input file instead. 关于编译的另一个有趣的事实是,记住输入文件的内容(以及XML文件的行号)很漂亮,因此,如果链接失败,错误将不会指向.flat文件,而是指向原始输入文件代替。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.