I have messed the files up in the Android folder and would like to rebuild the Android project inside of the Android folder. How do I do this?
Is it safe to delete the
The solution if ur version of react-native >= 0.61.0 :
sudo rm -rf android/ ios/
yarn add react-native-eject
npx react-native eject
enjoy !
Below command will create the android and ios folders.
react-native eject
Here my solution: (I'm doing this for android)
First command:(Navigation to the Android folder of your react-native project)
cd Android
Second command:
./gradlew clean
Third commmand:
./gradlew cleanBuildCache
I'm not fan of deleting android folder. (I think this not a best approaches)
To generate apk file for production: (First one from /Android)(second one from root project)
./gradlew bundleRelease
react-native run-android --variant=release
Happy coding!!!
Funny solution here Create a new react native app and copy the new android folder over and then run $react-native run-android
Running following commands should do the trick:
sudo rm -rf android/ ios/ #Delete Android and ios folders first...
react-native eject
react-native upgrade //rebuilds android/ios folders
react-native link
react-native run-android
react-native run-ios
Yes, it is safe to delete the Android and IOS folder and you can make it again by following steps:
1.First Method: react-native eject <=0.59.0
React-native had this command in the previous version. Running this command will check if the ios and android directories exist and then rebuild whichever one is missing.
sudo rm -rf android/ ios/
react-native eject // Will create new Android and IOS folder.
react-native link
react-native run-android
2.Second Method: react-native upgrade --legacy true>=0.60.0
Now you should use the react-native upgrade --legacy true command to back up your android folders or ios as the case may be as this command will replace your files.