ReactNative项目把Android/ios/react剥离出来独立模块

本文介绍了如何将一个ReactNative项目中Android、iOS和react部分拆分成独立的模块,详细讲解了项目结构、Android Native的配置步骤,包括node_modules目录设置、local.properties、settings.gradle及build.gradle的配置,并指导在react目录下执行`yarn install`和`yarn start`来启动项目。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目结构

Android native部分

react部分

Android Native 配置node_modules目录

local.properties配置

sdk.dir=E\:\\Android\\Sdk
react.path=E\:\\ReactNative\\MyReactNativeApp\\react

settings.gradle配置

include ':react-native-gesture-handler', ':common-silent', ':appservice', ':senseid-liveness-silent-offline', ':appcore'
logger.info(rootDir.path)
File file = new File(rootDir.path,"local.properties")
println file.path
Properties mp = new Properties()
mp.load(new FileInputStream(file))
include ':react-native-gesture-handler'
project(':react-native-gesture-handler').projectDir = new File(mp.getProperty("react.path"), '\\node_modules\\react-native-gesture-handler\\android')
include ':app'

build.gradle配置

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.40'
    ext.kotlin_version = '1.3.31'
    ext.kotlin_version = '1.2.71'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

def loadLocalProp() {
    File file = rootProject.file("local.properties")
    if (file.exists()) {
        Properties mp = new Properties()
        mp.load(rootProject.file("local.properties").newDataInputStream())
        def local = [:]
        mp.keySet().each {
            local[it] = mp.getProperty(it.toString())
        }
        return local
    }
}
def local = loadLocalProp()

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            // All of React Native (JS, Android binaries) is installed from npm
            url "${local['react.path']}/node_modules/react-native/android"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

在react目录下 yarn install yarn start

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值