Hot Reload无法在react-native android中工作

fri*_*cko 4 watchman react-native react-native-android create-react-native-app hot-reload

我在Windows 10和Ubuntu 16.04上尝试过它.在这两种情况下,Hot Reload仅适用于jsx中的更改,但不能用于更改javascript中的变量或函数或其他内容.热重新加载已启用.实时重新加载已禁用.当我在Visual Studio代码编辑器中保存更改时,虚拟设备(android studio)重新加载,但更改不存在.在EXPO App中的物理设备上也是如此.

首先,我没有安装守望者.Hot Relaod无法正常工作.安装后,Hot Reload也不能正常工作.

我使用create-react-native-app启动应用程序.它没有被驱逐出境.

的package.json:

{
  "name": "NativeReduxSaga",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "jest-expo": "25.0.0",
    "react-native-debugger-open": "^0.3.17",
    "react-native-scripts": "1.11.1",
    "react-test-renderer": "16.2.0"
  },
  "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
  "scripts": {
    "start": "react-native-scripts start",
    "eject": "react-native-scripts eject",
    "android": "react-native-scripts android",
    "ios": "react-native-scripts ios",
    "test": "node node_modules/jest/bin/jest.js",
    "postinstall": "rndebugger-open --expo"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "@redux-offline/redux-offline": "^2.3.2",
    "expo": "^25.0.0",
    "prop-types": "^15.6.1",
    "react": "16.2.0",
    "react-native": "0.52.0",
    "react-native-autocomplete-input": "^3.5.0",
    "react-navigation": "^1.5.2",
    "react-redux": "^5.0.7",
    "redux": "^3.7.2",
    "redux-devtools-extension": "^2.13.2",
    "redux-logger": "^3.0.6",
    "redux-observable": "^0.18.0",
    "redux-promise-middleware": "^5.0.0",
    "redux-saga": "^0.16.0",
    "redux-thunk": "^2.2.0",
    "rxjs": "^5.5.7"
  }
}
Run Code Online (Sandbox Code Playgroud)

守望者版

{
    "version": "4.9.1",
    "buildinfo": "94e66865386e844f2cffe52e355a94c96562d2e3 2018-03-12T19:58:02.0000000Z"
}
Run Code Online (Sandbox Code Playgroud)

节点版本v6.13.1

我在这里读了一些文章,它可以帮助Windows,提高MAX_WAIT_TIME.但我没有\node_modules\react-native \node_modules \node-haste\lib\FileWatcher\index.js文件.

为什么它也不适用于Ubuntu?

我真的需要守望者吗?应该如何配置?我的.watchmanconfig文件是一个空对象,如{}.

Hot Reload通常与create-react-native-app一起使用吗?

有谁知道我可以在这里试试,让热重装工作?Thanx求救!

Aja*_*pta 16

实际上,热门和实时重新加载之间存在差异.

热重新加载是即时重新加载,同时保持应用程序的状态不变.但是,它仅在render方法内部工作,并且仅在类React.Component和Component的扩展时触发

如:

class A extends Component ...
class B extends React.Component ...
Run Code Online (Sandbox Code Playgroud)

另一方面,Live Reload会重建您的应用程序并丢弃您的应用程序状态.它包括从变量和方法到最简单的字符串的所有内容.这就是为什么总是从应用程序的开始屏幕开始(因为状态丢失).

希望能帮助到你!


小智 5

删除git index.lock文件对我有用

rm -rf .git/index.lock


小智 5

在 android 中转到 MainApplication.Java 搜索 @Override public boolean getUseDeveloperSupport() { return true; }

确保它返回 true。这可能是问题所在