AOSP already has the Go makefiles in the build directory. Want to check them out? Look at the files here. There are three files:
go_defaults_512.mk. I’ll go over them all and describe what they do.
go_defaults_common.mk, as the name might imply, has all the “common” traits of all Go-optimized devices. It houses all the build flags, and essentially is the base for building Go-centered builds. Things like memory optimization, dex optimization, and other goodies are listed here. You can check the file out here.
The next file,
go_defaults.mk, just inherits
go_defaults_common.mk and does not seem to do anything special yet. You can check it out here.
The final file,
go_defaults_512.mk, is a bit of a special one. Essentially, it adds one more build flag for devices with 512MB of memory only. (I am not sure if Android will boot on devices that have less than 512MB of RAM, or if this file will benefit that device much.) Essentially, it allows the OOM killer (Out-Of-Memory killer) to kill more aggressively. You can check out the file over here.
Everything I explained is on this nice little XDA article that can be found here.
So how do you actually build Android-Go versions of builds? Well, it’s super easy. Just inherit one of the three files above in your device makefile, like this sample commit from LineageOS, and start building. Good luck!