How to use c++ in react-native?

I am trying to use my c++ code in react-native.
I also searched and found how to use the site below

I wrote the code along the site


package com.thebhwgroup.demo;

import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

public class HelloWorldModule extends /*ReactContextBaseJavaModule*/{
    public native String helloWorldJNI();


    public HelloWorldModule(ReactApplicationContext reactContext){

    public String getName(){    //React-Native에서 Module을 식별하는데 사용하는 문자열 return
        return "HelloWorld";    //JS에서 React.NativeModules.HelloWorld로 참조된다.

    public void helloWorld(Promise promise){    //JAVA에서 JS로 데이터 반환하는 방법 (다른 방법도 있음)
                                                //React-Native 문서에 있음
        try {
            String hello = helloWorldJNI();
        }catch (Exception e){
            promise.reject("ERR", e);


//HelloWorldModule.java를 React-Native에 등록하려면 Package를 추가해주어야 하기 때문에 필요한 파일

package com.thebhwgroup.demo;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MyReactPackage implements ReactPackage{
//    @Override
//    public List<Class<? extends JavaScriptModule>> createJSModules(){
//        return Collections.emptyList();
//    }

    public List<ViewManager> createViewManagers(ReactApplicationContext reactContext){
        return Collections.emptyList();

    public List<NativeModule> createNativeModules(ReactApplicationContext reactContext){    //HelloWorldModule에 생성되는 모듈과 함께 등록되는 부분
        List<NativeModule> modules = new ArrayList<>();

        modules.add(new HelloWorldModule(reactContext));

        return modules;


        protected List<ReactPackage> getPackages() {
            return Arrays.<ReactPackage>asList(
                    new MainReactPackage(),
                    new MyReactPackage()

Identifies the Module in React-native through the getName of and is referenced in JS. It also returns data through the helloWorld method.

I created a file like below to use JNI.

LOCAL_SRC_FILES := hello_world.c
LOCAL_MODULE := hello_world_jni

APP_ABI = all



jstring Java_com_thebhwgroup_demo_HelloWorldModule_helloWorldJNI(JNIEnv *env, jobject thiz){
    return (*env)->NewStringUTF(env, "Hello World!");

The C file was written in JNI format by referring to the JNI official document and site.



android {
    ndkVersion rootProject.ext.ndkVersion

    compileSdkVersion rootProject.ext.compileSdkVersion

    defaultConfig {
        applicationId "com.thebhwgroup"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"

        ndk {
            abiFilters "armeabi-v7a", "x86"
            moduleName "hello_world_jni"
            ldLibs "log"
            cFlags "-std=c99"


I run my react-native project use react-native run-android but this app is build Failed.

Erro is.
error Failed to install the app. Make sure you have the Android development environment set up:
and android/app/build.gradle
build error in import in android/app/build.gradle

There seems to be no problem with my environment variables.
What am I doing wrong?

Source: Windows Questions C++