Skip to content

Instantly share code, notes, and snippets.

@victory-sokolov
Created February 3, 2024 08:52
Show Gist options
  • Select an option

  • Save victory-sokolov/53fba445436c8aef2b45b00184bcc2e3 to your computer and use it in GitHub Desktop.

Select an option

Save victory-sokolov/53fba445436c8aef2b45b00184bcc2e3 to your computer and use it in GitHub Desktop.
ReactNative Bash functions
bapk() # build android apk (Must run inside react-native project)
{
apk_path="./android/app/build/outputs/apk/debug"
if [ ! -f package.json ]; then
echo "package.json was not found. Run command inside root dir of your project."
return 1
fi
if ! grep --quiet '"react-native":' package.json; then
echo "Not a react-native project"
return 1
fi
if [[ -d "./android/app/src/main" && ! -d "android/app/src/main/assets" ]]; then
mkdir android/app/src/main/assets
fi
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/build/intermediates/res/merged/release/ \
&& rm -rf android/app/src/main/res/drawable-* \
&& rm -rf android/app/src/main/res/raw/* \
&& cd android && ./gradlew assembleRelease && cd ..
# open folder where apk file is stored
xdg-open ${apk_path}
}
rna() # clean cache & run react-native android simulator
{
cd android && ./gradlew clean
cd .. && react-native run-android
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment