Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.

Get Started Now!

How to Fix React Native Android Build Errors (JDK 25, NDK 26, CMake & Emulator Issues)

If you are working with React Native (especially 0.84+) and suddenly your Android app:

  • Opens the emulator but does not launch the app
  • Fails with configureCMakeDebug error
  • Shows std::format not found error
  • Or says “No Android device connected”

Then this complete guide will help you fix everything step by step.

This guide is based on a real-world troubleshooting session on Windows with React Native 0.84.


Problem 1: Gradle Using Wrong Java Version (JDK 25 Instead of JDK 17)

Symptoms

Running:

gradlew.bat -version

Showed:

Launcher JVM: 25.0.2
Daemon JVM: jdk-25

Even though java -version showed JDK 17.

This caused:

Execution failed for task ':app:configureCMakeDebug[arm64-v8a]'
WARNING: A restricted method in java.lang.System has been called

Why This Happens

Gradle was using JDK 25 internally, but React Native Android builds are stable with JDK 17.

Gradle launcher and daemon must both use Java 17.


Solution: Force Gradle to Use JDK 17

Step 1: Locate Your JDK 17 Folder

Example:

C:\Program Files\Microsoft\jdk-17.0.18.8-hotspot

Step 2: Add This to android/gradle.properties

Open:

android/gradle.properties

Add:

org.gradle.java.home=C:\\Program Files\\Microsoft\\jdk-17.0.18.8-hotspot

Use double backslashes.


Step 3: Stop Gradle and Clean

cd android
gradlew.bat --stop
rmdir /s /q .gradle
rmdir /s /q .cxx
rmdir /s /q app\.cxx
gradlew.bat clean

Step 4: Verify

gradlew.bat -version

Now both should show:

Launcher JVM: 17.x
Daemon JVM: 17.x

If not, temporarily force in CMD:

set "JAVA_HOME=C:\Program Files\Microsoft\jdk-17.0.18.8-hotspot"
set "PATH=%JAVA_HOME%\bin;%PATH%"

Problem 2: CMake Error – std::format Not Found (NDK Issue)

After fixing Java, build failed with:

error: no member named 'format' in namespace 'std'
return std::format("{}%", dimension.value);

This came from:

react-native-safe-area-context

And NDK path showed:

ndk\26.1.10909125

Why This Happens

React Native 0.84 uses C++20 features like std::format.

NDK 26 does not properly support this setup.

You must use NDK 27.1+.


Solution: Install and Force NDK 27.1

Step 1: Install NDK 27.1

In Android Studio:

  • Settings
  • Android SDK
  • SDK Tools
  • Enable “NDK (Side by side)”
  • Select 27.1.12297006
  • Apply

Step 2: Force Project to Use NDK 27.1

Open:

android/build.gradle

Inside android {} add:

ndkVersion "27.1.12297006"

Step 3: Clean Native Build

cd android
gradlew.bat --stop
rmdir /s /q .cxx
rmdir /s /q app\.cxx
rmdir /s /q .gradle
gradlew.bat clean

Step 4: Run Again

cd ..
npx react-native run-android

Now build succeeds.


Problem 3: Emulator Opens but CLI Says “No Android Device Connected”

Even though:

adb devices

Showed:

emulator-5554 device

Sometimes it showed blank.


Why This Happens

  • ADB server mismatch
  • Multiple adb.exe in PATH
  • Emulator not cold booted

Fix Emulator Detection

Step 1: Restart Emulator

Cold boot from Android Studio Device Manager.


Step 2: Reset ADB

adb kill-server
taskkill /F /IM adb.exe
adb start-server
adb devices

Now emulator should show:

emulator-5554 device

Step 3: Run with Correct Flag

New React Native versions use:

npx react-native run-android --device emulator-5554

(Not --deviceId)


Step 4: Ensure Correct ADB in PATH

where adb

Make sure this path is first:

C:\Users\YourUser\AppData\Local\Android\Sdk\platform-tools\adb.exe

If not:

set "ANDROID_SDK_ROOT=%LOCALAPPDATA%\Android\Sdk"
set "PATH=%ANDROID_SDK_ROOT%\platform-tools;%PATH%"

Final Working Configuration Summary

For React Native 0.84 (Windows):

  • Java: JDK 17
  • Gradle JVM: 17
  • NDK: 27.1.12297006
  • CMake: Installed via SDK Tools
  • Use: --device instead of --deviceId

Final Command That Worked

npx react-native run-android --device emulator-5554

Everything built smoothly.


Key Lessons Learned

  1. Gradle launcher and daemon must both use Java 17.
  2. NDK 26 is not compatible with React Native 0.84 C++20 requirements.
  3. Always force ndkVersion in build.gradle.
  4. Always clean .cxx when changing NDK.
  5. If emulator shows but CLI doesn’t detect, reset ADB.

Related Posts

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Artificial Intelligence
0
Would love your thoughts, please comment.x
()
x