AAPT2 Support

The App Bundles thread was getting a bit long and branch-y, so I’ll mention AAPT2 stuff here.

I ran my large project with UseAAPT2 enabled and got the correct error messages about needing to rename .android-xml files to .xml. After doing this, I encountered a new error running aapt2:

E: The filename or extension is too long
D: | at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo).

This immediately follows the call to aapt2.exe, which in my project was given 344 full-path items, the total command length being ~44k characters. Not sure to what degree this is limited, but it looks like aapt2 may need to be called multiple times after all…

Yeah, I expected this, Windows has limits of howe many parameters can be passed to a process :(. does aapt2 on windows support passing @somefile.txt and reading the parameters from the file instead, like many other tools do? Or does it have an alternative parameter where a single file with a list of filenames can be passed?

Looks like the only option, with the mentioned caveat, is

--dir directory Specifies the directory to scan for resources.

Although you can use this flag to compile multiple resource files with one command, it disables the benefits of incremental compilation and thus, should not be used for large projects.

I wonder how the incremental processing is supposed to work — dopes aapt2 handle that on its own, or is it meant that we check which files have changed, and only call aapt2 for the ones that have changed? (which will be tricky of we also want to handle removals & co).

I suggest I switch to --dir for now, and ignore incremental processing, since we’re caching the aapt2 run anyways, sop it wukld only run if there had been changes to the resources (but if there is a change, it will, for now re-process all). and we can see if we wanna fine-tune that with more granular caching, later?

Except it doesn’t work, sigh :frowning:

D: Users/Shared/Android/sdk/build-tools/29.0.0-rc3/aapt2 compile -v --legacy -o "/Users/mh/Library/Application Support/RemObjects Software/EBuild/Obj/com.remobjects.androidapplication45-B5CB0D4D7B3898F4CC11143E27D750E3B3F7544B/Release/Cooper-Android/res" --dir "/Users/mh/Test Projects/com.remobjects.androidapplication45/res"
E: aapt: Is a directory.

Fixed, on Windows I’ll just run individually for each file, on Unix I’ll run a single command. I also did add checks to only incrementally run for tis exiles that have changed, and to only link if needed, as well.

Myself, I’m still stuck on aapt2 link not liking there manifest file, even though it looks correct to me…

1 Like

link will have the same problem though on Windows. How does ADS call it, if there are many files?

I’ll have to look into it. Android Studio and Gradle are both open source, so I’ll take a look there and let you know.

1 Like

For logging purposes, I’ll post the solution here too.

Dump the list of resources into a filename.txt and call: aapt2 link -R @filename.txt

1 Like