【问题标题】:React native run-android do not updating modified codeReact native run-android 不更新修改后的代码
【发布时间】:2018-06-26 12:16:39
【问题描述】:

我在我的 Windows PC 上使用 React native 0.52.0 和 react-native-cli 2.0.1 进行 android 开发。尽管我做了所有的改变。当我运行react-native run-android 时,它会成功构建,但是当我运行它时,我会得到默认的反应原生屏幕。

我运行react-native run-android时的结果@-

我得到的应用程序-

index.js

import { AppRegistry } from 'react-native';
import App from './App';

AppRegistry.registerComponent('albums', () => App);

app.js

import React from 'react'
import ReactNative, { Text } from 'react-native'

export default const App = () => {
  return (
    <Text>Hello World</Text>
  )
}

当我运行react-native init albums 时,它只是创建了一个 index.js 文件,没有 index.android.js 或 index.ios.js 文件 我做错了什么?

【问题讨论】:

标签: android react-native npm react-native-android


【解决方案1】:

假设您在正确的文件夹中,请尝试这样做:

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/

如果您有 index.android.js,请改为:

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

然后执行 react-native run-android。

【讨论】:

  • 我按照你说的做了,这是我收到的错误消息 FAILURE: Build failed with an exception。 * 出了什么问题:配置根项目“专辑”时出现问题。 > 无法解析配置 ':classpath' 的所有文件。 > 找不到 com.android.tools.build:gradle:3.0.1。在以下位置搜索:jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle -3.0.1.pom jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle -3.0.1.jar 要求:项目:
  • 运行后,你说的第一行代码,我的Build is failed
  • 确保命令中的路径与项目中的路径相同。
  • 不,你不应该。
  • 就我而言,它需要每次都运行。谁有解决方案?
【解决方案2】:

解决方案

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

输出将是:

`c:\Users\lenger\Desktop\webrowser>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
Scanning folders for symlinks in c:\Users\lenger\Desktop\webrowser\node_modules (43ms)
Scanning folders for symlinks in c:\Users\lenger\Desktop\webrowser\node_modules (38ms)
Loading dependency graph, done.
bundle: start
bundle: finish
bundle: Writing bundle output to: android/app/src/main/assets/index.android.bundle
bundle: Done writing bundle output

之后

再次运行react-native run-android,你会发现你的修改工作。

https://lengerrong.blogspot.am/2018/01/react-native-run-android-do-not.html

【讨论】:

  • 好像每次编译前都要运行这个命令?
  • @fujianjin6471 你有解决办法吗?还是我每次都需要跑?
  • @BhaveshHirpara 到现在是
  • 谢谢+1。目前我在 iOS 中运行,在开发结束时我只是在 android 中测试,这样我就可以避免多次执行命令
【解决方案3】:

这对我有用。 第 1 步)

rm -rf /usr/local/var/run/watchman && brew uninstall watchman && brew install watchman

第二步)

react-native start

【讨论】:

    【解决方案4】:

    您可能更新了错误的文件,而不是在 AppRegistry 类中调用它。

    检查(或发布)您的完整 index.android.js 并确保它正在调用和导入的文件是您实际修改的文件。

    【讨论】:

      【解决方案5】:

      在您的终端窗口中转到您的项目文件夹,然后尝试此命令

      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/
      

      【讨论】:

        【解决方案6】:

        打开 package.json 文件并更新此代码。

        "scripts": {
        "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 && react-native run-android",
        "ios": "react-native run-ios"
        },
        

        假设您在正确的文件夹中,请尝试这样做:

        仅运行此命令,它会自动执行这两个命令。

        npm run android

        【讨论】:

        • 每次应用运行时都不好
        【解决方案7】:

        运行脚本:

        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 clean
        $ react-native link
        

        【讨论】:

          【解决方案8】:

          这对我有用:

          在你的项目文件夹中运行这个

          c:\Users\lenger\Desktop\YourProjectFolder>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
          

          在 c: 中扫描符号链接的文件夹

          \Users\lenger\Desktop\webrowser\node_modules (43ms)
          Scanning folders for symlinks in c:\Users\lenger\Desktop\webrowser\node_modules (38ms)
          Loading dependency graph, done.
          bundle: start
          bundle: finish
          bundle: Writing bundle output to: android/app/src/main/assets/index.android.bundle
          bundle: Done writing bundle output
          

          再次运行 react-native run-android

          我分享了找到此解决方案的链接: https://lengerrong.blogspot.com/2018/01/react-native-run-android-do-not.html

          【讨论】:

          • 但是,我需要在运行时每次都编写 bundle 吗?
          【解决方案9】:

          github 上的 comment 解决了我的问题。

          @neonsec Cool, it do works !
          
          and I find a reason why this happened
          
          https://github.com/facebook/watchman/blob/4b98623e8fde17588f27494f3ae8f084b9b227d3/QueryableView.cpp#L48
          
          it looks like when a .git/index.lock or a .hg/wlock file exist, watchman will do nothing
          

          解决方法:删除.git/index.lock文件

          ## root app dir
          rm -f .git/index.lock
          

          其他链接: https://github.com/facebook/watchman/blob/4b98623e8fde17588f27494f3ae8f084b9b227d3/QueryableView.cpp#L48

          【讨论】:

            【解决方案10】:

            对于 CodePush 用户

            我遇到了同样的问题,但它并没有在生产版本中更新我的代码,它在开发中运行良好。

            我的问题是 CodePush,它正在更新我的应用程序,因为它与上一个 CodePush 发布目标版本具有相同的版本,并且是强制更新(我没有更改版本目标,因为它只是为了测试目的),然后,我在我的 App.js 上注释了 CodePush 代码,它运行良好。

            【讨论】:

              【解决方案11】:

              尝试@SmoggeR_js 回答后,如果您遇到同样的问题,请尝试以下操作 (假设您已创建密钥并已签署 apk)

              1. 删除build文件夹内的android/app文件夹
              2. 删除buildandroid文件夹内
              3. 运行rm -rf $HOME/.gradle/caches/ 删除缓存
              4. 打开build.gradle --> android/app/build.gradle
              5. 注释掉这一行 apply from: "../../node_modules/react-native/react.gradle"
              6. assets 文件夹( android/app/src/main/assets/index.android.bundle) 中删除index.android.bundle 文件
              7. 运行以下命令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
              8. react-native run-android --variant=release(您必须生成签名密钥,并且所有密钥都应在 gradle 文件 ref (https://s-pace.github.io/react-native/docs/signed-apk-android.html) 中更新

              【讨论】:

                【解决方案12】:

                在我的情况下,删除 gradle.properties 中的以下行解决了它。

                org.gradle.configureondemand = true

                【讨论】:

                  【解决方案13】:

                  对我来说,问题是我已经从我的 AndroidManifest.xml 中删除了互联网权限(因为从技术上讲不需要它)。 React Native 使用该权限将您的应用连接到开发机器(并启用实时调试)。

                  <uses-permission android:name="android.permission.INTERNET" />
                  

                  【讨论】:

                    【解决方案14】:

                    打开你的Android Studio -> “Tools”菜单 -> “AVD manager”并右键点击你正在使用的模拟器,选择“Wipe Data" 然后 "Cold Boot Now" 应该可以解决问题。

                    【讨论】:

                      【解决方案15】:

                      如果您使用的是 index.android.js,请按照以下步骤操作:

                      删除 android/app/src/main/assets 中的 index.android.bundle,然后 -

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

                      2. cd ./android

                      3. ./gradlew assembleRelease -x bundleReleaseJsAndAssets

                      【讨论】:

                        【解决方案16】:

                        三步修复:

                        1. 启用实时重新加载
                        2. 禁用热重载
                        3. 在开发设置中,取消选中 JS 开发模式

                        现在您的应用会在您每次更改代码时自动更新。

                        【讨论】:

                        • 我认为这是一个错误,忘记了每次克隆到新系统时都需要重新启用实时重载和热重载
                        【解决方案17】:

                        试试这个

                        cd .git (in your react-native folder)
                        rm index.lock
                        

                        并重新启动 Metro bundler,即react-native start

                        哇哇!!...

                        【讨论】:

                          【解决方案18】:

                          没有 index.android.js 或 index.ios.js 文件

                          在这种情况下,您必须按照以下手机/模拟器上的说明进行操作:

                          保存App.js后,记得输入两次R大写

                          要使其自动更改,请在 Android 模拟器上按 CTRL + M(MacOS 上为 CMD + M)或摇动正在运行的应用程序的 Android 设备并选择 Hot reloading(保持当前状态,仅更改您已更改的文件) 或Live reloading(重新加载整个应用程序)。

                          【讨论】:

                            【解决方案19】:

                            我犯了一个愚蠢的错误,即不保存对 App.js 的编辑。保存数据后会反映:)

                            【讨论】:

                            • 嗨,目前的答案看起来更像评论,当你有 50 次以上的代表时,你就可以添加评论了。
                            【解决方案20】:

                            就我而言,当我禁用调试时,它会更新。 所以这是我的解决方案。

                            在 Chrome 开发工具中 > 网络 > 禁用缓存 希望 shell 对你有用

                            【讨论】:

                              【解决方案21】:

                              如果您使用“codepush”。

                              我现在尝试了两个小时来弄清楚为什么我的 Android 版本总是回滚到旧代码并且不显示新功能。

                              原因是旧的 CodePush 导致应用降级。

                              【讨论】:

                                【解决方案22】:

                                尝试删除

                                • ./android/.idea 文件夹。
                                • ./android/.gradle 文件夹。

                                它对我有用

                                【讨论】:

                                  【解决方案23】:

                                  在你的项目目录下,有 package.json 文件。您可以在脚本下的该 json 文件中添加以下代码 sn-p:。之后,您可以使用npm run android-windows 一个命令运行应用程序。要正常工作,您应该添加以下代码脚本。

                                  "android-windows": "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"
                                  

                                  【讨论】:

                                  • 我们是否必须每次运行才能看到代码的修改?
                                  猜你喜欢
                                  • 1970-01-01
                                  • 1970-01-01
                                  • 1970-01-01
                                  • 2018-06-01
                                  • 2021-06-14
                                  • 1970-01-01
                                  • 1970-01-01
                                  • 1970-01-01
                                  • 2019-12-20
                                  相关资源
                                  最近更新 更多