Java 如何清除反应原生缓存?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46878638/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to clear react-native cache?
提问by Ville Miekk-oja
In react-native development, there are multiple caches used when the app is built:
在 react-native 开发中,app 构建的时候会用到多个缓存:
- React-native packager cache
- Emulator cache
- Java side cache (.gradle) folder (only in android)
- npm cache (if relevant?)
- React-native 打包器缓存
- 模拟器缓存
- Java 端缓存 (.gradle) 文件夹(仅在 android 中)
- npm 缓存(如果相关?)
Am I missing something also? Because I'm trying to clear cache in react-native, to be able to repeat a bug that only occurs on first usage. But clearing those caches above did not help. This is on android. When the app is building, most of the rows DO NOT say UP-TO-DATE, as expected, because I cleared the cache.
我也错过了什么吗?因为我正在尝试清除 react-native 中的缓存,以便能够重复仅在第一次使用时出现的错误。但是清除上面的那些缓存并没有帮助。这是在安卓上。当应用程序正在构建时,大多数行不会按预期显示 UP-TO-DATE,因为我清除了缓存。
But, there are still many rows where this text is printed. Like:
但是,仍然有很多行打印此文本。喜欢:
app:preBuild UP-TO-DATE
app:preDebugBuild UP-TO-DATE
:app:preReleaseBuild UP-TO-DATE
app:preBuild 最新
app:preDebugBuild 最新版本
:app:preReleaseBuild 最新版本
The question is, how can I clear the whole cache related to react-native development?
问题是,如何清除与 react-native 开发相关的整个缓存?
回答by sfratini
Have you tried gradle cleanBuildCache?
你试过 gradle cleanBuildCache 吗?
https://developer.android.com/studio/build/build-cache.html#clear_the_build_cache
https://developer.android.com/studio/build/build-cache.html#clear_the_build_cache
回答by Vikram Biwal
Clearing the Cache of your React Native Project:
清除 React Native 项目的缓存:
npm < 6.0 and RN < 0.50:
npm < 6.0 和 RN < 0.50:
watchman watch-del-all && rm -rf $TMPDIR/react-* &&
rm -rf node_modules/ && npm cache clean && npm install &&
npm start -- --reset-cache
npm >= 6.0 and RN >= 0.50:
npm >= 6.0 和 RN >= 0.50:
watchman watch-del-all && rm -rf $TMPDIR/react-native-packager-cache-* &&
rm -rf $TMPDIR/metro-bundler-cache-* && rm -rf node_modules/ && npm cache clean --force &&
npm install && npm start -- --reset-cache
回答by Haris Anwar
For React Native Init approach (without expo) use:
对于 React Native Init 方法(没有 expo)使用:
npm start -- --reset-cache
回答by Abhishek Nalwaya
You can clean cache in React Native >= 0.50 and npm > 5 :
您可以清除 React Native >= 0.50 和 npm > 5 中的缓存:
watchman watch-del-all &&
rm -rf $TMPDIR/react-native-packager-cache-* &&
rm -rf $TMPDIR/metro-bundler-cache-* &&
rm -rf node_modules/
&& npm cache clean --force &&
npm install &&
npm start -- --reset-cache
Apart from cleaning npm cache you might need to reset simulator or clean buildetc.
除了清理 npm 缓存之外,您可能还需要重置模拟器或清理构建等。
回答by Mohsin
For those who are using expo-cli
对于那些使用 expo-cli 的人
expo start -c
博览会开始 -c
回答by Firoz Ahmed
This is what works for me:
这对我有用:
watchman watch-del-all && rm -f yarn.lock && rm -rf node_modules && yarn && yarn start --reset-cache
回答by spacedev
try this
尝试这个
react-native start --reset-cache
回答by Hyman Wire
I had a similar problem, I tried to clear all the caches possible (tried almost all the solutions above) and the only thing that worked for me was to kill the expo app and to restart it.
我遇到了类似的问题,我试图清除所有可能的缓存(尝试了上面几乎所有的解决方案),唯一对我有用的方法就是杀死 expo 应用程序并重新启动它。
回答by Olcay Erta?
If you are using WebStorm
, press configuration selection drop down button left of the run button and select edit configurations:
如果您正在使用WebStorm
,请按运行按钮左侧的配置选择下拉按钮并选择编辑配置:
Double click on Start React Native Bundler
at bottom in Before launch
section:
双击Start React Native Bundler
底部的Before launch
部分:
Enter --reset-cache
to Arguments
section:
进入--reset-cache
到Arguments
部分:
回答by Fabricio Cunha
Clearing the Cache of your React Native Project: if you are sure the module exists, try this steps:
清除 React Native 项目的缓存:如果您确定模块存在,请尝试以下步骤:
- Clear watchman watches: npm watchman watch-del-all
- Delete node_modules: rm -rf node_modules and run yarn install
- Reset Metro's cache: yarn start --reset-cache
- Remove the cache: rm -rf /tmp/metro-*
- 清除守望者手表:npm watchman watch-del-all
- 删除 node_modules: rm -rf node_modules 并运行 yarn install
- 重置 Metro 的缓存:yarn start --reset-cache
- 删除缓存:rm -rf /tmp/metro-*