5

React Native 环境搭建指南

 3 years ago
source link: https://segmentfault.com/a/1190000038835167
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

写的有些仓促 主要用于自己备忘 仔细阅读文章 不能错过任何一步 大家有问题可以留言

第一步 下载android studio 安装 SDK

1.下载Android studio 我是随便下载的 没看版本号 官网,下载完成后 安装相关SDK   _file>setting>Android SDK_

2 切换到SDK Tools 都选中后 点击apply

第二步 各种安装

1.安装 nodejs(大于12版本 配置环境变量)

2.安装python(2.7版本 配置环境变量)

3.jdk1.8(配置环境变量 JAVA_HOME)

ps:这些我都是用 联想电脑管家>软件管理  下载速度非常快 特别香!

第三步 创建RN 项目

1.执行npx react-native init AwesomeProject  即可

第四步 更换国内镜像(非常重要)

1.修改 根目录/android/build.gradle  更换国内镜像

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

buildscript {
    ext {
        buildToolsVersion = "29.0.2"
        minSdkVersion = 16
        compileSdkVersion = 29
        targetSdkVersion = 29
    }
    repositories {
        // google()
        // jcenter()
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
        maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.5.3")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        // google()
        // jcenter()
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
        maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
        maven { url 'https://www.jitpack.io' }
    }
} 

2.命令行输入  npm config set registry https://registry.npm.taobao.org

第五步  你可能会遇到下载 gradle-6.2-all.zip 非常慢的问题 如果有解决如下

1.建议把连接放到迅雷下载 下载成功后放到 根目录/android/gradle/wrapper

2.配置一下 gradle-wrapper.properties 如下

第六步 手机打开USB调试 连接电脑 (或者用android studio的手机模拟器)进入项目目录 yarn android启动项目 耐心等待运行 成功出现如下页面

第七步 相信你们不会那么顺利 把问题发到留言区吧


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK