On this page
Read the error
Find the first meaningful error that explains why a Gradle task failed, rather than treating the final BUILD FAILED line as the diagnosis. Record the failed task, relevant file or dependency, and the causal message before changing configuration.
Inside Apirex, the builder reads build output and fixes the source as part of its build-and-check workflow. You can also ask for help by quoting the first meaningful error line and the change that preceded it. A concise reproducible failure is more useful than a screenshot containing only the final summary.
If you investigate manually, wait until Apirex is not editing or building the same project. Open a terminal in the generated Android project folder containing the Gradle wrapper. Use that wrapper rather than an unrelated global Gradle installation so your command uses the project's configured distribution.
Run ./gradlew assembleDebug --stacktrace on macOS or Linux. On Windows, use gradlew.bat from Command Prompt, or .\gradlew.bat from PowerShell, with the same task and flags. Add --info when you need more context about task execution or dependency resolution, and sanitize output before sharing it.
./gradlew --version
./gradlew assembleDebug --stacktrace
./gradlew assembleDebug --stacktrace --info
./gradlew :app:dependencies
./gradlew --stopThese commands are separate diagnostic choices, not a mandatory sequence to run after every failure. Start with the failing build and add only the report needed for its cause. Read the relevant exception and causal chain; the earliest warning in a log may be unrelated to the actual error.
Preserve a source checkpoint before changing versions or deleting generated state. Make one targeted correction and rerun the same task so you can attribute the result to that change. After compilation succeeds, test the application's main journey on a phone because successful compilation is not proof of correct behavior.
| Error message pattern | Likely cause | Fix |
|---|---|---|
| Android Gradle plugin requires Java 17 | Gradle is running with an incompatible JDK. | Check the wrapper JVM and select a compatible JDK for that AGP release. |
| Failed to find Platform SDK | The required SDK platform is missing or the SDK path is wrong. | Check the configured SDK location and install the matching platform. |
| Duplicate class | Two artifacts contain overlapping classes. | Inspect dependencies and remove or align the conflicting artifacts. |
| Could not resolve / offline mode | Missing cached dependency, repository issue, or network failure. | Check offline settings, repositories, credentials, and connectivity. |
| Java heap space | The relevant JVM exhausted its heap. | Check available RAM and adjust the appropriate JVM memory setting. |
| Gradle daemon disappeared unexpectedly | Possible process termination, memory pressure, or JVM failure. | Read daemon and system logs before assuming the cache is corrupt. |
SDK/JDK mismatch
Match the JDK running Gradle, the Gradle wrapper, and the Android Gradle plugin before changing application source. The compilation toolchain and the JVM that launches Gradle are related settings, but configuring one does not necessarily configure the other.
As of November 2026, the official AGP 9.2 compatibility table lists JDK 17 as its minimum and default. JDK 17 is also required by AGP 8.0. Check the release notes for the plugin version actually used by your project rather than assuming that upgrading Java alone makes every wrapper and plugin combination compatible.
Inspect ./gradlew --version to identify the JVM used by your command-line build. Android Studio may use a different Gradle JDK from the shell. If the builder succeeds and a manual build fails, compare the environments before replacing dependencies or editing otherwise valid Kotlin code.
A Kotlin JVM toolchain can specify the compiler's Java toolchain. The following is a build.gradle.kts fragment for a compatible Kotlin Android configuration, not a replacement for the project's complete build file. Keep existing plugin configuration, and check its compatibility before adding a duplicate block.
// Fragment for the module build.gradle.kts.
// Requires a compatible Kotlin plugin configuration.
kotlin {
jvmToolchain(17)
}
// The JVM running Gradle must also satisfy AGP requirements.Selecting this toolchain does not repair a Gradle launcher that cannot run the Android plugin. Likewise, changing Java source compatibility is not a substitute for installing the required runtime JDK. Follow the error's distinction between running Gradle, compiling source, and the Android platform APIs available to the application.
Check the Android SDK independently. compileSdk selects the Android API surface used during compilation, whereas targetSdk declares the Android behavior level the application targets. Neither setting installs an SDK platform by itself. A missing platform error usually requires checking the SDK location and installing the platform the project expects.
Do not lower compileSdk or targetSdk merely to hide a missing download. That can introduce API failures, dependency incompatibility, or release-policy problems. Instead, verify the project's intended versions, the plugin's supported API range, and the installed packages, then make a coordinated change if an upgrade is genuinely required.
Apirex prepares Java, the Android SDK, and Gradle during Android setup, without requiring Android Studio just to build. If setup is incomplete, inspect the helper's messages and reported disk shortage or download issue. Repeated source edits cannot fix a platform installation that is still unavailable.
Dependency conflicts
Inspect the dependency graph to identify which artifacts and versions actually enter the failing build. Fix the source of a conflict instead of adding arbitrary exclusions or forcing every library to the same version number.
Run ./gradlew :app:dependencies to view the app module's dependency report. For a narrower report, select the configuration associated with the failing variant, such as debugRuntimeClasspath. If your module is not named app or you use product flavors, adapt the module and configuration to the actual project.
Use dependencyInsight when you need to understand why a particular version was selected. The dependency report can reveal both direct declarations and transitive dependencies introduced by another library. Compare the selected version with the failing artifact rather than assuming the version written in one build file is the one being used.
Version catalogs can centralize dependency aliases and version declarations, often in gradle/libs.versions.toml. Check the catalog and the build scripts together before changing a version. A catalog makes declarations easier to manage; it does not automatically enforce compatibility between unrelated artifacts or remove duplicate transitive classes.
For Jetpack Compose, use the supported Bill of Materials to align the Compose libraries it covers. The official BOM documentation explains that participating library declarations do not need independent version numbers. Do not assume the BOM also selects the Kotlin plugin, Android plugin, or every third-party library in the app.
A duplicate-class failure can indicate two artifacts packaging the same implementation, not merely two versions of one coordinate. Read the named classes and artifacts, trace why both are present, and remove the redundant source or select compatible dependencies. An exclusion is appropriate only when you understand why the removed classes are unnecessary.
Keep dependency changes narrow and documented. Update the related catalog entry or platform declaration, rerun the failing task, and test the affected feature. Avoid deleting lockfiles or broadly upgrading unrelated packages as a debugging shortcut; those changes make it harder to identify which compatibility issue you actually solved.
Memory and cache
Adjust memory only when the evidence indicates memory pressure, and treat cache deletion as a targeted recovery step rather than routine maintenance. Network failures, missing SDK packages, and incompatible source cannot generally be repaired by clearing every Gradle cache.
For a Java heap space error in the Gradle JVM, a possible setting is org.gradle.jvmargs=-Xmx4g in the project's gradle.properties. This allows a maximum heap of four gibibytes for that JVM, not a guarantee that the computer can afford it. Preserve any necessary existing JVM flags and account for the IDE, compiler processes, and other applications using RAM.
Check user-level gradle.properties as well as the project file if a setting appears ineffective. Gradle's build-environment documentation describes configuration precedence. Increasing the heap on a machine already under memory pressure can make termination more likely, so inspect available memory and system evidence before repeatedly raising the value.
Stop related builds before restarting daemons with ./gradlew --stop. A daemon restart can help after an environment change, but it does not correct an invalid dependency declaration. If the daemon disappears unexpectedly, inspect its log and the operating system's process-termination evidence rather than assuming every disappearance is a heap configuration issue.
For suspected dependency cache trouble, first consider a targeted build using --refresh-dependencies while online. Check whether the artifact exists in the configured repository and whether authentication or a proxy is preventing access. Refreshing cannot download a private artifact without valid credentials or restore a repository that is unavailable.
Deleting ~/.gradle/caches is a last-resort action with a wide impact on projects using that Gradle user home. Stop builds and daemons first, confirm the actual Gradle user-home location, and consider renaming the affected cache directory so recovery remains possible. Do not delete the entire ~/.gradle folder, which can contain configuration and credentials beyond caches.
Expect dependencies and other cached resources to need downloading again after cache removal. Do not do this when offline if the next build needs those files. Preserve source, signing keys, configuration, and any useful diagnostic output before taking a destructive cleanup step.
For offline errors, check whether offline mode was intentionally enabled and whether all required artifacts are cached. For online failures, read whether the cause is DNS, TLS, authentication, timeout, or a missing artifact. Do not disable certificate verification or paste repository passwords into source to bypass the problem.
Once the targeted correction succeeds, rerun the original build and test the main journey on your Android phone. In Apirex, you can ask the builder to investigate using the first meaningful error line and the recent change. Keep the helper terminal open, and avoid launching a competing manual build during its work.
Frequently asked questions
Should I clear caches after every failure?
No. Start from the error and make a targeted correction. Cache deletion can force downloads without addressing incompatible source or configuration.
Does jvmToolchain(17) select the JVM running Gradle?
Not necessarily. It configures the Kotlin compilation toolchain; check the wrapper runtime and AGP requirements separately.
Do I need Android Studio for Apirex builds?
No. The helper prepares Java, the Android SDK, and Gradle. You can still open the generated project in Android Studio for its tools.
What should I send the builder?
Send the first meaningful error, the failing task, and the recent change. Remove secrets and unrelated personal information from logs.
Does assembleDebug success mean the app works?
No. It confirms that build completed, not that the main journey, permissions, or device behavior are correct. Test the app with realistic input.
All guides
Native foundations
Build with AI
- How to build an Android app with AI
- How to build an iOS app with AI
- How to build an iPad app with AI
- How to build a Mac app with AI
- How to build an app without coding
- Prompts that produce good apps
- Local AI app builder: build apps on your own computer
- How to add payments to your app
- Gradle build failed: common fixes
Google Play
Apple distribution
Build it on your own computer
Describe the app and Apirex writes real source you own, then builds it on your machine.
Opens Apirex with this prompt. Pick the Android · Kotlin tab before you send. The Free plan includes 5 Rex Credits a day.