Set the environment variable ANDROID_HOME to point to the Android
SDK. If you downloaded the Android command-line tools, this would be
the folder where you extracted the contents of the ZIP archive.
Later on, gradlew will install necessary SDK components in this folder.
However, you need to accept the SDK component licenses before they can be
downloaded by Gradle. This can be done by running the following command
from the root of the SDK directory, then answering all the prompts
with y:

tools/bin/sdkmanager --licenses

Set the environment variable ANDROID_NDK_ROOT to point to the
Android NDK. You also might need to set the variable ANDROID_NDK_HOME
to the same path, especially if you are using custom Android modules,
since some Gradle plugins rely on the NDK and use this variable to
determine its location.

To set those environment variables on Windows, press Windows + R, type
“control system”, then click on Advanced system settings in the left
pane, then click on Environment variables on the window that
appears.

To set those environment variables on Linux or macOS, use
exportANDROID_HOME=/path/to/android-sdk and
exportANDROID_NDK_ROOT=/path/to/android-ndk
where /path/to/android-sdk and /path/to/android-ndk point to
the root of the SDK and NDK directories.

Godot needs two export templates for Android: the optimized “release”
template (android_release.apk) and the debug template (android_debug.apk).
As Google will require all APKs to include ARMv8 (64-bit) libraries starting
from August 2019, the commands below will build an APK containing both
ARMv7 and ARMv8 libraries.

Compiling the standard export templates is done by calling SCons with
the following arguments:

This will create a fat binary that works on all platforms.
The final APK size of exported projects will depend on the platforms you choose
to support when exporting; in other words, unused platforms will be removed from
the APK.

Godot needs release and debug APKs that were compiled against the same
version/commit as the editor. If you are using official binaries
for the editor, make sure to install the matching export templates,
or build your own from the same version.

The newly-compiled templates (android_debug.apk
and android_release.apk) must be copied to Godot’s templates folder
with their respective names. The templates folder can be located in:

Windows: %APPDATA%\Godot\templates\<version>\

Linux: $HOME/.local/share/godot/templates/<version>/

macOS: $HOME/Library/ApplicationSupport/Godot/templates/<version>/

<version> is of the form major.minor[.patch].status using values from
version.py in your Godot source repository (e.g. 3.0.5.stable or 3.1.dev).
You also need to write this same version string to a version.txt file located
next to your export templates.

However, if you are writing your custom modules or custom C++ code, you
might instead want to configure your APKs as custom export templates
here:

You don’t even need to copy them, you can just reference the resulting
file in the bin\ directory of your Godot source folder, so that the
next time you build you will automatically have the custom templates
referenced.