react native android 踩的坑

1. 按照官网进行相关的配置

https://reactnative.cn/docs/environment-setup

2. 注意点

目前所需要的环境是 node >12 npm >5  java>8

 

我的环境是

3. 按照android studio

4. 配置中踩的坑

4.1其中按照官网提供的配置SDK出现各种下载很慢的问题

尝试多种代理和镜像。无法正常获取到相应的数据,如果你是2020.3.1的版本,建议直接是不采取任何代理。

 

 

 

 4.2 无法下载addons

Connection refused:connect
IOExpection https://dl.google.com/android/repository/addons_list-3.xml
IOExpection https://dl.google.com/android/repository/addons_list-2.xml

几乎翻遍了所有的博客,FQ也没有成功。这个原因是因为gradle、SDK等版本的不匹配的问题。

解决方案: 手工调整gradle为最新版

dependencies {
classpath("com.android.tools.build:gradle:7.0.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}

 


 其中,build路径在

 

 

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

如果下载还是不成功,直接从官网上下载https://services.gradle.org/distributions/
我是默认安装路径,可以直接放到路径下面:

 

 解压之后就可以

SDK配置版本:

这个步骤非常关键,我按照官网下载的29死活在react native 编译出问题,最终定位gradle建立的文件确定下载:这个与你的文件内容一定要匹配。我按照官网选择29的版本,结果yarn android 出现各种获取不了源。就算开了VPN配置了镜像也是各种问题。

 

 

 

 

 

 

 

 4.3 配置代理的问题

以尝试阿里云提供的maven 镜像,将android/build.gradle中的jcenter()google()分别替换为maven { url 'https://maven.aliyun.com/repository/jcenter' }maven { url 'https://maven.aliyun.com/repository/google' }(注意有多处需要替换)。

 

 4.4 Unable to load script. Make sure you're either running Metro (run 'npx react-native start') or that

 

 这个问题的解决方案是gradle的问题:

是因为debug的时候没有一起打包,所以配置一下即可

 

 project.ext.react = [
enableHermes: false, // clean and rebuild if changing
bundleInDebug : true//debug的时候可以配置连接
]

5. 运行成功

 

 

经过几天的额探索,android真是无语死了。我还是倾向于web的构建。。。由于APP的应用市场和推广的难度现在发现这块的业务真的是出现死角。。。

 

posted @ 2021-12-22 15:52  李悠然  阅读(539)  评论(0编辑  收藏  举报