Running out of memory during Android build

I get this during the deployment phase of an Android build:

UEDeployAndroid.RunCommandLineProgramWithExceptionAndFiltering: Making .apk with Gradle...
UEDeployAndroid.FilterStdOutErr: Error occurred during initialization of VM
UEDeployAndroid.FilterStdOutErr: Could not reserve enough space for 2097152KB object heap

I had to adjust the java heap size in Gradlew.bat because it can’t support 4096MB in 2021 like a normal program. However no matter what I set it to (4000M works) it still runs out of the exact same amount of memory.

I’ve cranked the pagefiles up and ensured the disks all have lots of space free. I am now out of ideas.