已有Android项目集成react native

已有Android项目集成react native

效果

在这里插入图片描述
在这里插入图片描述

环境

Android studio 4.0.1
gradle
buildscript {
   
    repositories {
   
        google()
        jcenter()
    }
    dependencies {
   
        classpath "com.android.tools.build:gradle:4.0.1"

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

#Thu Feb 18 17:57:36 CST 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

前置准备

Android P(9.0) http网络请求的问题

参考官网,把这些改安装的安装了
在这里插入图片描述

集成步骤

  1. 新建个Android项目

  2. 初始化项目

根目录输入以下命令
npm init
在这里插入图片描述
在第一个包名输入自己项目的包名,其他一直按回车即可

  1. 添加脚本
    在根目录会生成package.json这个文件,将启动脚本加入进去
    "start": "node node_modules/react-native/local-cli/cli.js start"

在这里插入图片描述

  1. 安装React 和React Native

根目录输入以下命令
npm install --save react react-native

  1. 在日志中找到这句话
    在这里插入图片描述
    继续在根目录中执行
    npm i -S react@16.3.1
    在这里插入图片描述

  2. 下载.flowconfig文件(非必须)
    curl -o .flowconfig https://raw.githubusercontent.com/facebook/react-native/master/.flowconfig

  3. 新建index.android.js
    项目根目录下创建index.android.js文件,目录内容如下:

import React from "react";
import { AppRegistry, StyleSheet, Text, View } from "react-native";

class HelloWorld extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.hello}>Hello, World</Text>
      </View>
    );
  }
}
var styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
  },
  hello: {
    fontSize: 20,
    textAlign: "center&#
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值