【问题标题】:Loading Old Bundle in React native . While running on Physical device在 React native 中加载旧包。在物理设备上运行时
【发布时间】:2018-04-07 15:29:41
【问题描述】:

尝试在物理设备上运行生成的构建 apk 或调试时,它正在加载旧包。并且不反映任何变化,它只发生在同一网络上的物理设备上。

以下技巧对我不起作用。 1.

 Run the command in a terminal: ps ax | grep react-native
    Kill all processes and run bundle script again.

2.

 rm -rf $TMPDIR/react-*

3.

--resetCache true

4.

--reset-cache

5.

Permanent delete node_modules
npm cache clean –force
npm install
npm start -- --reset-cache

【问题讨论】:

    标签: react-native react-native-android


    【解决方案1】:

    故事从这里开始。

    在物理设备上加载时出错。

    所以,为了修复它。 必须按照项目根文件夹中的以下几行

    mkdir android/app/src/main/assets
    
    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
    
    react-native run-android
    

    从第二次开始,在加载到物理设备之前需要执行以下代码来更新捆绑包

    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
    

    【讨论】:

      【解决方案2】:

      试试这个来清理你当前的构建。
      cd android && ./gradlew clean
      cd .. && react-native run-android

      同时删除当前在 android 内的 output/apk 文件夹中生成的 APK。

      如果您使用的是 windows,请尝试以管理员身份运行终端窗口。

      【讨论】:

      • 是的,我是 Windows 用户。它不工作。仍然返回旧的捆绑输出。没有反映任何变化
      • 尝试从模拟器中卸载应用程序,或擦除模拟器上的数据,看看是否能解决此问题。我不确定发生了什么,只是一个建议。
      • 模拟器没问题,运行良好。问题出在仅在物理设备上运行时
      • 我不知道发生了什么。您是否尝试在其他 Android 设备上安装捆绑包?
      • 我修复了它并找到了解决方案!
      【解决方案3】:

      试试这个命令

      curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
      

      然后按照命令再次运行

      react-native run-android
      

      【讨论】:

      • 我看到这也是为 android 更新捆绑包的另一种方式。
      • 但是上面的命令会给我返回错误,因为我的入口文件是 index.js 而不是 index.android .js ..
      【解决方案4】:

      这些是对我有用的正确步骤,以便手动构建捆绑包并将其安装在设备上,我一直摸不着头脑,直到我设法找到如何正确执行此操作:

      cd android
      
      ./gradlew clean
      
      cd ../
      
      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
      
      ./gradlew assembleRelease
      
      ./gradlew installRelease
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-06-03
        • 2021-11-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-24
        • 2021-04-16
        • 2019-01-06
        相关资源
        最近更新 更多