Clean react native project
React NativeCode CleanupReact Native Problem Overview
How to clean react native project?
Is there any way to clean react native project as we can clean xcode project?
Any help will be appreciated!
React Native Solutions
Solution 1 - React Native
A react-native Project is about one XCode Project and one Android Project. (for pure js code, there's no need to do clean)
So, what you need would be
Clean XCode Project with
cd ios
xcodebuild clean
And then clean Android Project with
cd android
./gradlew clean
You can simply write a batch file for it.
Solution 2 - React Native
For android project
cd android &&./gradlew clean && cd ../
For iOS project
cd ios && xcodebuild clean && cd ../
If you need build clean again and again then add this scripts in the package.json file like this
scripts: {
"clean:android": "cd android && ./gradlew clean && cd ../",
"clean:ios": "cd ios && xcodebuild clean && cd ../",
}
Then run for android
yarn clean:android
And run for iOS
yarn clean:ios
Solution 3 - React Native
For Android
cd android
gradlew clean
For IOS
cd ios
xcodebuild clean
Solution 4 - React Native
Delete node modules and
npm ci
react-native link
followed by
react-native start --reset-cache
Solution 5 - React Native
React Native clean-project is now the best and easiest way to do deal with react-native artifacts and cleanup. Since it's automatically detected by react-native, it becomes its own command in react-native.
$ yarn add -D react-native-clean-project
$ react-native clean-project
Solution 6 - React Native
To reset react-native specific cache, run:
npm start -- --reset-cache
if in package.json you have
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
}
Solution 7 - React Native
this script will clean the Android and IOS build cache, then removes node modules and caches, and reinstall the react native project.
# rm -rf $HOME/.gradle/caches/
cd android && ./gradlew cleanBuildCache
cd ..
cd ios && pod cache clean --all && rm -rf build
cd ..
rm -rf node_modules
yarn cache clean --force
yarn install
cd ios && pod install
To reset the iOS simulator and erase all simulator data, focus on the simulator then go to Hardware -> Erase All Content and Settings
To reset the Android emulator and erase all data, open Android Studio then goes to menu Tools -> AVD Manager, then click the dropdown menu on the selected simulator and click on wipe data.
Solution 8 - React Native
I added the following scripts to my package.json
scripts: {
....
"clean:android": "echo 'require(\"child_process\").execSync(\"cd android; ./gradlew clean\", {stdio: \"inherit\"})' | node ",
"clean:ios": "echo 'require(\"child_process\").execSync(\"cd ios; xcodebuild clean\", {stdio: \"inherit\"})' | node ",
"clean": "npm run clean:android && npm run clean:ios",
....
}
now you can clean android
npm run clean:android
clean ios
npm run clean:ios
clean both
npm run clean
Solution 9 - React Native
More useful cleaner scripts. Seperating modules cleaning & native cleaning, based on the other great answers:
"scripts": {
"npm:clean": "rm -rf node_modules && npm cache clean && npm install"
"yarn:clean": "rm -rf node_modules && yarn cache clean --force && yarn install"
"android:clean": "cd android && ./gradlew clean && ./gradlew cleanBuildCache && cd ..",
"ios:clean": "cd ios && xcodebuild clean && rm -rf ~/Library/Caches/CocoaPods && rm -rf Pods && rm -rf ~/Library/Developer/Xcode/DerivedData/* && pod cache clean --all && pod deintegrate && pod setup && pod install && cd ..",
}
Solution 10 - React Native
React and node specific cleaning:
Remove node_modules
to avoid inconsitence which may appear somehow rarely:
rm -rf node_modules
(reinstall if need with npm
or yarn
)
Clean npm
cache if npm
is used
npm cache clean
Clean react temp files:
rm -rf $TMP/react*
Solution 11 - React Native
Clean the Android Project with:
cd android/
gradlew clean
Solution 12 - React Native
remove android folder run
react-native upgrade
then
react-native run-android