I am well aware the minimal requirements explicitly state 64GB RAM, but in another how-to article I read 32GB and also comments under that article confirmed that.
But when I try "m -j28" I end up with this: (and now also tested with -j8)
[100% 1/1] analyzing Android.bp files and generating ninja file at out/soong/build.aosp_cf_x86_64_phone.ninja
FAILED: out/soong/build.aosp_cf_x86_64_phone.ninja
cd "$(dirname "out/host/linux-x86/bin/soong_build")" && BUILDER="$PWD/$(basename "out/host/linux-x86/bin/soong_build")" && cd / && env -i "$BUILDER" --top "$TOP" --soong_out "out/soong" --out "out" --soong_variables out/soong/soong.aosp_
cf_x86_64_phone.variables -o out/soong/build.aosp_cf_x86_64_phone.ninja -l out/.module_paths/Android.bp.list --available_env out/soong/soong.environment.available --used_env out/soong/soong.environment.used.aosp_cf_x86_64_phone.build Android.bp
Warning: Module 'androidx.wear_wear' depends on non-existing optional_uses_libs 'wear-sdk'
Warning: Module 'androidx.wear.compose_compose-foundation' depends on non-existing optional_uses_libs 'wear-sdk'
Killed
20:55:51 soong bootstrap failed with: exit status 1
ninja: build stopped: subcommand failed.
#### failed to build some targets (54 seconds) ####
I see no further useful info in the out/verbose.log file.
Also I don't assume the missing optional library 'wear-sdk' is the reason why the build was killed.
So is it the RAM after all?
Try configuring ZRAM. ZRAM is form of memory swapping that compresses swapped memory pages in RAM rather than swapping them to disk. Disk swap is the default configuration utilized by Ubuntu and tends to be a meager 2 GiB; it is slower than ZRAM and that is not nearly enough.
I'd suggest make the ZRAM 3/4 the size of total RAM. This should allow you get close to 64 GiB usable RAM on a machine with 32 GiB physical RAM.
If absolutely necessary use both ZRAM and a disk swap (larger than 2 GiB), but try with just ZRAM and using fewer threads first since disk swap is usually very slow. In theory a large enough disk swap should guarantee success.
Here is an example article explaining how to configure ZRAM: https://fosspost.org/enable-zram-on-linux-better-system-performance
Finally use -j 24
option or so when initiating the build to prevent too many concurrent processes from executing at the same time and consuming excessive RAM.
I notice during AOSP builds there are two phases that require a lot of RAM: