美文网首页
React Native 爬坑问题汇总

React Native 爬坑问题汇总

作者: mike_fei | 来源:发表于2018-09-05 16:57 被阅读79次
    • 执行./gradlew assembleRelease报出Unable to resolve module AccessibilityInfo错误

    打release包失败,项目配置文件如下,React Native 版本号为0.56.0

    "dependencies": {
        "react": "16.4.1",
        "react-native": "^0.56.0"
    },
    "devDependencies": {
        "babel-jest": "23.4.2",
        "babel-preset-react-native": "5",
        "jest": "23.5.0",
        "react-test-renderer": "16.4.1"
    },
    

    错误原因:这是React Native0.56.0最新版本的携带的错误,问题只会发生在Windows操作系统,mac不会。

    解决方法:修改packjosn配置文件,降低到稳定版本

    "dependencies": {
        "react": "^16.4.1",
        "react-native": "^0.55.4"
    },
    "devDependencies": {
        "babel-preset-react-native": "^4.0.0",
    },
    

    然后依次执行cmd命令

    npm update
    npm cache clean --force
    cd android
    gradlew clean
    cd..
    react-native run-android
    

     


     

    • React Native Release包启动闪退,报出Unable to load script from assets 'index.android.bundle'错误

    issue截图:


    image.png

    错误信息:

    AndroidRuntime: FATAL EXCEPTION: Thread-2
           Process: com.awesomeproject, PID: 3218
           java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctly or you're running a packager server.
           at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)
           at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:216)
           at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:31)
           at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:234)
           at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1114)
           at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:113)
           at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:911)
           at java.lang.Thread.run(Thread.java:761)
    

    错误原因:找不到android/app/src/main/assets/index.android.bundle文件

    解决方法:每次编译打包之前需要先执行 js 文件的打包(即生成离线的 jsbundle 文件)。具体的 js 打包命令如下:

    react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/
    src/main/res/
    

    如果 assets 目录不存在,则需要提前自己创建一个。
     


     

    未完待续,持续更新~~~~~

    相关文章

      网友评论

          本文标题:React Native 爬坑问题汇总

          本文链接:https://www.haomeiwen.com/subject/zebawftx.html