React Native 之坑

一、运行React Native项目遇到的坑

1、React Native项目连接不上 模拟器或者手机

Error:

Could not install the app on the device, read the error above for details

明明连接上模拟器或者手机了,但是RN project说不识别
方法:
在项目根目录运行下面命令,提升权限

chmod 755 android/gradlew
2、Facebook本身的坑
[SyntaxError:Strict mode does not allow function declaration 
in a lexically nested statement.]

方法:
修改React Native版本号!

3、react-native-vector-icons build error
Error: react-native-vector-icons:compileReleaseJavaWithJavac

方法: 一般是用Windows的电脑,有个文件名长度的限制,所以找到error中的文件,然后删除,重新react-native run-android 就可以了!

4、
React Native 之坑_第1张图片
error.png

解决方法:
cd android
sudo ./gradlew clean

5、react-native 项目运行在真机上面

com.android.ddmlib.InstallException: Failed to establish session
    at com.android.ddmlib.Device.installPackages(Device.java:894)
    ........
    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
:app:installDebug FAILED

FAILURE: Build failed with an exception.

主要是国产机,我用的红米手机,解决办法就是
打开开发者选项,然后找到开启MIUI优化选项,然后关闭他,重启手机 就可以了

6、setState(…): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op

在React Native中控制控件的隐藏或者显示是通过this.setState boolean变量来设置的,但是重复设置会导致这个Warnning,所以需要在setState之前要加一个判断,避免重复设置. 比如如下设置

if (!this.state.loaded){
      this.setState({loaded: true});
}

------------------------------------分割线----------------------------------------

二、在现有Android项目中集成RN遇到的坑

1、在现有Android项目中初始化RN配置,重新sync gradle出现下面错误

Error:Conflict with dependency 'com.google.code.findbugs:jsr305' in project ':app'. Resolved versions for app (3.0.0) and test app (2.0.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.

解决方法在:app/build.gradle里面添加

android{
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.0'
    }
}

然后重新sync gradle,问题解决了!!,但是too young too sample,还没好遇到下面的问题了!!
2、

Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed with multiple errors, see logs

解决方案:rn最低支持Android4.1

minSdkVersion 16
targetSdkVersion 25

你可能感兴趣的:(React Native 之坑)