Where Is the Android Native Code Located in the React Native Repository?
The Android native code in React Native is located primarily in the packages/react-native/ReactAndroid directory, which contains the Java/Kotlin framework, C++/JNI native layer, and Gradle build configuration.
The React Native repository on GitHub organizes its platform-specific implementations into dedicated packages. If you are looking for the Android native code located in the React Native repository, you will find the bulk of the implementation inside the ReactAndroid package. This directory houses everything from the bridge lifecycle managers to the compiled C++ libraries that power the JavaScript engine integration.
Core Directory Structure: packages/react-native/ReactAndroid
The ReactAndroid directory is the single source of truth for Android-specific native functionality. According to the React Native source code, this folder is organized into four primary areas:
- Java/Kotlin framework – UI managers, bridge infrastructure, module system, and activity helpers
- C++/JNI native layer – Bridge to the Java side, Yoga layout engine, Fabric renderer, and TurboModules
- Build scripts and Gradle integration – Gradle module configuration, CMake files, and ProGuard rules
- Resources – XML layouts, style files, and string tables packaged with the AAR
Java and Kotlin Framework Layer
The Java and Kotlin source files expose React Native to Android applications through a set of manager classes. In packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java, the ReactInstanceManager class orchestrates the bridge lifecycle, JavaScript executor, and UI manager creation.
Key entry points in this layer include:
ReactInstanceManager.java– Manages the bridge lifecycle and JS executorReactNativeHost.java– A convenience wrapper used by the app'sApplicationclassReactApplication.java– Interface that anApplicationmust implementReactRootView.java– The native view that hosts the React tree
C++ and JNI Native Layer
The heavy lifting for React Native on Android occurs in the C++ libraries compiled via JNI. The entry point for native method registration is packages/react-native/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp, which loads when the library initializes.
Critical JNI components include:
OnLoad.cpp– Registers native methods on library loadJavaScriptExecutorHolder.h– Abstracts the JS engine (Hermes, V8, JSC)YGJNI.h– JNI bridge for the Yoga layout engine located insrc/main/jni/first-party/yogajni/jni/
Build System Integration
The Android native code is assembled into an AAR using Gradle and CMake. The packages/react-native/ReactAndroid/build.gradle.kts file defines the module, its dependencies, and invokes the CMake build.
Key build files:
build.gradle.kts– Gradle module definition for the AARsrc/main/jni/CMakeLists.txt– Top-level CMake file that compiles native code and links third-party libraries
Practical Integration Examples
Minimal Android Integration (Kotlin)
To integrate React Native into an existing Android application, implement ReactApplication in your Application class:
// MyApplication.kt
class MyApplication : Application(), ReactApplication {
private val mReactNativeHost = object : ReactNativeHost(this) {
override fun getUseDeveloperSupport() = BuildConfig.DEBUG
override fun getPackages() = listOf(
MainReactPackage(),
// add other packages here
)
override fun getJSMainModuleName() = "index"
}
override fun getReactNativeHost(): ReactNativeHost = mReactNativeHost
}
Launching a React View from an Activity
Use ReactActivity or manually manage a ReactRootView:
class MainActivity : ReactActivity() {
// ReactActivity already sets up the ReactRootView.
// If you need a custom setup, you can do:
override fun getMainComponentName() = "MyApp"
// Optional: provide a custom ReactInstanceManager
override fun getReactInstanceManager(): ReactInstanceManager {
return (application as MyApplication).reactNativeHost.reactInstanceManager
}
}
Accessing a Native Module from JavaScript
Create a native module by extending ReactContextBaseJavaModule:
// MyNativeModule.java
public class MyNativeModule extends ReactContextBaseJavaModule {
MyNativeModule(ReactApplicationContext ctx) { super(ctx); }
@Override
public String getName() { return "MyNativeModule"; }
@ReactMethod
public void showToast(String msg) {
Toast.makeText(getReactApplicationContext(), msg, Toast.LENGTH_SHORT).show();
}
}
Then call it from JavaScript:
// MyComponent.js
import {NativeModules} from 'react-native';
NativeModules.MyNativeModule.showToast('Hello from JS!');
Summary
- The Android native code for React Native is centralized in
packages/react-native/ReactAndroid. - The Java/Kotlin framework exposes native functionality through
ReactInstanceManager,ReactNativeHost, andReactRootView. - The C++/JNI layer handles the bridge, layout engine, and JS execution via files like
OnLoad.cppandJavaScriptExecutorHolder.h. - Build configuration relies on
build.gradle.ktsandCMakeLists.txtto compile the AAR and native libraries. - Sample integration code demonstrates how
MainApplication.ktandMainActivity.ktwire these components together.
Frequently Asked Questions
What is the exact path to the Android native code in React Native?
The Android native code is located at packages/react-native/ReactAndroid in the React Native repository. This directory contains the Java/Kotlin source files under src/main/java/, C++ JNI code under src/main/jni/, and build scripts including build.gradle.kts and CMakeLists.txt.
Which file manages the React Native bridge lifecycle on Android?
The ReactInstanceManager.java file located at packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java manages the bridge lifecycle. It orchestrates the JavaScript executor, UI manager creation, and communication between JavaScript and native Android code.
Where is the C++ JNI code located in React Native's Android implementation?
The C++ JNI code resides in packages/react-native/ReactAndroid/src/main/jni/. Key files include react/jni/OnLoad.cpp for native method registration, react/jni/JavaScriptExecutorHolder.h for JS engine abstraction, and first-party/yogajni/jni/YGJNI.h for the Yoga layout engine bridge.
How do I integrate React Native into an existing Android app using these native files?
To integrate React Native, implement the ReactApplication interface in your Application class using ReactNativeHost as shown in private/helloworld/android/app/src/main/java/com/helloworld/MainApplication.kt. Then create an Activity that extends ReactActivity or manually manages a ReactRootView, referencing the ReactInstanceManager from your application class to coordinate the native bridge.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →