This is a newer version with a bit more details and workarounds from this gist. Especially for Android R+.
I recommend to read the previous gist to get an idea about what I'm trying to achieve.
This note will be straight forward on commands to perform.
Some commands use zipalign and apksigner which are located in the build-tools of your Android SDK installation folder.
Mine are located in: ~/Library/Android/sdk/build-tools/34.0.0/.