React Native Android Build Failed: How to Fix Gradle & NDK Errors

    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.

    Common Symptoms & Error Signatures

    • •Terminal shows: 'Execution failed for task :app:compileDebugKotlin' or ':app:processDebugResources'
    • •Error: 'Could not determine the dependencies of task :app:compileDebugJavaWithJavac'
    • •Gradle throws: 'Unsupported class file major version' or Java 17 vs Java 21 incompatibility
    • •Native module builds fail with 'NDK at /path/to/ndk was not found or is corrupted'
    • •Build passes on Android Studio GUI but consistently fails on 'npx react-native run-android'

    Root Causes & Diagnostic Checks

    1. Gradle Wrapper and Java SDK Version Incompatibility

    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.

    2. Kotlin Version Mismatch Across Native Libraries

    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.

    3. Corrupted Gradle Daemon or Android Cache

    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.

    Targeted Code Solution

    android/build.gradle (Resolution Fix)
    android/build.gradle (Resolution Fix)groovy
    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")
        }
    }

    Diagnostic & Action Matrix

    Symptom / ErrorRoot CauseTargeted Solution
    major version 65 errorJava 21 used with old GradleSwitch to JDK 17 (JAVA_HOME)
    compileDebugKotlin failedConflicting Kotlin versionsForce kotlinVersion in root build.gradle
    NDK does not contain build-toolsMissing NDK componentInstall exact NDK in SDK Manager
    Duplicate class found in modulesJetifier or dependency conflictAdd exclude group or force resolutionStrategy

    What I Change in the Codebase

    android/build.gradle

    Pin ext.kotlinVersion and compileSdkVersion to match RN release requirements.

    android/gradle/wrapper/gradle-wrapper.properties

    Ensure distributionUrl matches compatible AGP release (e.g., gradle-8.5-bin.zip).

    Clean Process

    Run './gradlew clean' inside android/ directory after resetting the daemon.

    Production Verification

    Verified in Voltix — Real-Time Solar Energy Intelligence

    A production React Native app using native Skia rendering and background Bluetooth services, built with custom Gradle configurations.

    Frequently Asked Questions

    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.

    Which JDK version should I use for React Native?

    React Native 0.73 and newer officially targets OpenJDK 17. Run 'java -version' to verify your active environment.

    Can you fix our Android build if it only fails on CI/CD?

    Yes. CI failures are typically caused by missing environment variables, unaccepted Android SDK licenses, or differing Gradle cache states between local and runner machines.

    Related Troubleshooting Guides

    Need this resolved on your app?

    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.