热门搜索 :
考研考公
您的当前位置:首页正文

ReactNative报错集锦(持续更新)

来源:东饰资讯网

RN真是个巨坑,只有本文章的最后一个坑,我没踏过,其他都入坑了

image.png

或是


image.png

解决:更改APP下的gradle

 defaultConfig {
        applicationId "com.example.laer.rn_demo"
        minSdkVersion 18
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    packagingOptions {
        exclude "lib/arm64-v8a/librealm-jni.so"
    }

金典bug:这个bug,基本是刚开始将RN集成到原生安卓项目必现的bug

image.png
原因:多半是因为没有生产打包所需要的bundle文件(也就是没有图中的文件)
image.png
出现这种情况的可能性还比较多,可以看这里:

解决:我们先在main下面创建asserts文件夹,然后进入工程根目录打开cmd输入
react-native bundle --platform android --entry-file index.android.js --bundle-output app/src/main/assets/index.android.bundle --dev false(注意-output后面的参数根据自己的项目目录结构来写)

生成打包bundle文件

成功后的项目

image.png

如果摇晃手机重新加载js报错Unable to download JS bundle

image.png
两种产生此问题的可能(我遇到的):

①第一种可能:没设置第三步的ip,按照如下方法设置就行了

这里写图片描述 这里写图片描述

如果出现上面的界面,有可能就是你的server没打开,命令 react-native start
这个时候重新输入以上的url,浏览器显示下图:

这里写图片描述
java.lang.IllegalAccessError: Method ‘void  
is inaccessible to class  (declaration of 
 appears in /data/app/package.name-2/base.apk

解决办法:把support相关包改成23.0.1
compile 'com.android.support:appcompat-v7:23.0.1'

出现Got JS Exception: TypeError: undefined is not a function (evaluating ‘(bridgeConfig.remoteModuleConfig || []).forEach’) 的错误,原因是被官方文档坑了,官方文档是这样描述的:
allprojects {
    repositories {
        ...
        maven {
            // All of React Native (JS, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
    ...
}

然而正确应该是(这里还是要根据自己的项目结构来配置路径,但是不出意外都是下面的):

allprojects {
    repositories {
        jcenter()

        maven {
            // All of React Native (JS, Android binaries) is installed from npm
            url "$rootDir/node_modules/react-native/android"
        }
    }
}

Error:Conflict with dependency 'com.google.code.findbugs:jsr305'

Top