How do I clear the entire Android Gradle cache?
Inside the android/ folder, run './gradlew clean'. If issues persist, kill active daemons with './gradlew --stop' and delete the android/.gradle folder.
A React Native Android build usually fails in Gradle because of a mismatch between the Android Gradle Plugin (AGP), the Gradle wrapper version, and the Kotlin compiler version across native third-party dependencies. Running a clean build and aligning your android/build.gradle and gradle-wrapper.properties resolves the majority of compile failures.
React Native versions mandate specific Java Development Kit (JDK) versions. For example, React Native 0.73+ requires JDK 17. Using JDK 21 with older Gradle wrappers triggers 'Unsupported class file major version 65' errors.
When third-party libraries define their own conflicting ext.kotlin_version, Gradle fails during compileKotlin. Enforcing a unified Kotlin version in android/build.gradle prevents conflicting compiler bytecode.
Incremental build caches frequently become poisoned after updating React Native or adding a native library. A full stop of the Gradle daemon and clearing ~/.gradle/caches is required.
buildscript {
ext {
buildToolsVersion = "34.0.0"
minSdkVersion = 23
compileSdkVersion = 34
targetSdkVersion = 34
ndkVersion = "26.1.10909125"
kotlinVersion = "1.9.22" // Align Kotlin version across all subprojects
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:8.2.1")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
}
}| Symptom / Error | Root Cause | Targeted Solution |
|---|---|---|
| major version 65 error | Java 21 used with old Gradle | Switch to JDK 17 (JAVA_HOME) |
| compileDebugKotlin failed | Conflicting Kotlin versions | Force kotlinVersion in root build.gradle |
| NDK does not contain build-tools | Missing NDK component | Install exact NDK in SDK Manager |
| Duplicate class found in modules | Jetifier or dependency conflict | Add exclude group or force resolutionStrategy |
Pin ext.kotlinVersion and compileSdkVersion to match RN release requirements.
Ensure distributionUrl matches compatible AGP release (e.g., gradle-8.5-bin.zip).
Run './gradlew clean' inside android/ directory after resetting the daemon.
Production Verification
A production React Native app using native Skia rendering and background Bluetooth services, built with custom Gradle configurations.
Inside the android/ folder, run './gradlew clean'. If issues persist, kill active daemons with './gradlew --stop' and delete the android/.gradle folder.
React Native 0.73 and newer officially targets OpenJDK 17. Run 'java -version' to verify your active environment.
Yes. CI failures are typically caused by missing environment variables, unaccepted Android SDK licenses, or differing Gradle cache states between local and runner machines.
If this error is blocking your release build or production pipeline, Syed Alijah Muhammad can diagnose and deploy a clean fix. Send the repository access, error trace, and platform details.