Most build failures are environment problems, and the message names the culprit if you read past the stack trace. A wrong JAVA_HOME stops the build before Gradle 19,597 starts:
JAVA_HOME=/usr/lib/jvm/no-jdk cordova build androidOutput
... Using Android SDK: /opt/android-sdk Reading build config file: .../booknest/build.json ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/no-jdk Please set the JAVA_HOME variable in your environment to match the location of your Java installation. Command failed with exit code 1: gradle -p .../platforms/android/tools wrapper --gradle-version 8.14.2
The failures this chapter hit:
| Symptom | Cause | Fix |
|---|---|---|
| JAVA_HOME is set to an invalid directory | Wrong or stale JAVA_HOME | Point it at JDK 17 (JAVA_HOME and PATH) |
| keystore password was incorrect at :app:signReleaseBundle | Release build without passwords | Pass --storePassword and --password |
| INSTALL_FAILED_UPDATE_INCOMPATIBLE | Debug and release keys differ | adb uninstall first (Build Batch Files) |
| Can't find service: package | Emulator not fully booted | Wait and retry (run, build and prepare) |
| bad_record_mac or a corrupt Gradle zip | Download broken in transit | Delete the half-written folder in ~/.gradle, retry |
When the message is not enough, cordova build android --verbose prints the exact Gradle command to rerun with --stacktrace, and cordova platform rm android plus platform add android rebuilds a suspect project from config.xml (config.xml Mistakes). A wrong ANDROID_HOME did not fail at all: cordova-android fell back to the SDK beside the adb on the PATH, so check the Using Android SDK: line when two SDKs are installed.