反应本机代码更改未反映在设备上
Posted
技术标签:
【中文标题】反应本机代码更改未反映在设备上【英文标题】:React native code changes not reflecting on device 【发布时间】:2019-10-16 02:18:40 【问题描述】:今天早上在病房里,我遇到了 react native android build 的问题。代码中的新更改未反映在设备上。没有构建失败。我尝试了以下方法
删除并重新安装节点模块 react-native 链接 ./gradlew clean 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 watchman 关机服务器 rm -rf /usr/local/var/run/watchman && brew uninstall watchman && brew install watchman npm start - --reset-cache我的 package.json
"name": "",
"version": "0.0.1",
"private": true,
"scripts":
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"ipad": "react-native run-ios --simulator 'iPad Pro (10.5-inch) (12.0)' --configuration Debug"
,
"dependencies":
"@babel/runtime": "^7.2.0",
"accordion-collapse-react-native": "^0.1.9",
"aws-amplify": "^1.1.18",
"aws-amplify-react-native": "^2.1.6",
"aws-sdk": "^2.394.0",
"buffer": "^5.2.1",
"i18next": "^12.1.0",
"moment": "^2.24.0",
"nanoid": "^2.0.0",
"native-base": "^2.8.1",
"react": "^16.6.3",
"react-i18next": "^8.3.8",
"react-native": "^0.57.8",
"react-native-app-intro-slider": "^2.0.1",
"react-native-check-box": "^2.1.7",
"react-native-collapsible": "^1.4.0",
"react-native-fetch-blob": "^0.10.8",
"react-native-gesture-handler": "^1.0.10",
"react-native-image-crop-picker": "^0.21.3",
"react-native-image-resizer": "^1.0.0",
"react-native-img-button": "^1.0.1",
"react-native-keyboard-aware-scroll-view": "^0.8.0",
"react-native-keyboard-manager": "^4.0.13-10",
"react-native-keyboard-spacer": "^0.4.1",
"react-native-languages": "^3.0.1",
"react-native-linear-gradient": "^2.5.3",
"react-native-locale-detector": "^1.0.1",
"react-native-material-dropdown": "^0.11.1",
"react-native-material-ripple": "^0.8.0",
"react-native-modal-datetime-picker": "^6.0.0",
"react-native-paper": "^2.15.2",
"react-native-segmented-control-tab": "^3.3.1",
"react-native-signature-pad-react-16": "^0.4.0",
"react-native-size-matters": "^0.1.4",
"react-native-vector-icons": "^6.1.0",
"react-navigation": "^2.18.2",
"react-redux": "^5.1.1",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0",
"remote-redux-devtools": "^0.5.16",
"rnkit-alert-view": "^0.1.2"
,
"devDependencies":
"babel-jest": "23.6.0",
"jest": "23.6.0",
"metro-react-native-babel-preset": "0.49.2",
"react-test-renderer": "16.6.1"
,
"jest":
"preset": "react-native"
,
"rnpm":
"assets": [
"./src/assets/fonts"
]
【问题讨论】:
通常当我遇到这个问题时,终端总是有错误,但调试器中没有。所以看起来应用程序运行良好并且构建没有任何错误,但实际上终端中存在错误并且导致此 UI 不更新问题 【参考方案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
在 Android 中运行 react native。该命令将 JS 服务器捆绑在包 (APK) 中。因此不会与系统上运行的 Metro 服务器进行通信。
使用react-native run-android
命令调试应用程序。在这个 js 服务器中不会附带包。因此,更改将在您刷新应用程序时反映出来
【讨论】:
我已经尝试了该命令,但仍然无法刷新代码,直到我进入模块并按 Ctrl+S 保存代码。 @UserSharma 您必须将代码保存在文件中。否则,它不会反映在应用中 我说的是节点模块。假设我已经从 NPM 服务器升级了一个节点模块的版本,然后我运行了 android 调试构建,然后新版本中的更新代码不会反映在应用程序中,直到我转到节点模块的每个文件然后按 Ctrl+S。以上是关于反应本机代码更改未反映在设备上的主要内容,如果未能解决你的问题,请参考以下文章