美文网首页
Android studio 集成React Native

Android studio 集成React Native

作者: 放羊娃华振 | 来源:发表于2021-10-17 12:04 被阅读0次

由于之前的项目中也用到Rn,但是很多集成的细节没有记录,随着时间的流逝也逐渐的忘却了。今天抽点时间写个demo记录下点点滴滴。
1、安装Python,这个网上都是文章,不在赘述了。
2、安装node.js ,这个网上都是文章,不在赘述了。
3、利用Android sudio 创建一个Android 工程,由于这个比较简单也就不赘述了。
4、添加依赖和仓库地址:

//依赖
implementation 'com.facebook.react:react-native:0.51.0'

//仓库地址
allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://jitpack.io"
        }
        
    }
}

5、添加RN的view

        mReactRootView = new ReactRootView(this);
        mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(getApplication())
                .setBundleAssetName("index.android.bundle")
                .setJSMainModuleName("index.android")
                .addPackage(new MainReactPackage())
               //.setUseDeveloperSupport(BuildConfig.DEBUG)
                .setUseDeveloperSupport(true) //开发者支持,开发的时候要设置为true,不然无法使用开发者菜单
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();

        // 注意这里的MyReactNativeApp必须对应“index.android.js”中的
        // “AppRegistry.registerComponent()”的第一个参数
        mReactRootView.startReactApplication(mReactInstanceManager, "MyReactNativeApp", null);

参考文章:React Native 中文网

相关文章

网友评论

      本文标题:Android studio 集成React Native

      本文链接:https://www.haomeiwen.com/subject/fghrxktx.html