Skip to content

Instantly share code, notes, and snippets.

@daemswibowo
Last active May 22, 2019 10:59
Show Gist options
  • Save daemswibowo/be5bdc526a9d823e38ff5b8dcaca2212 to your computer and use it in GitHub Desktop.
Save daemswibowo/be5bdc526a9d823e38ff5b8dcaca2212 to your computer and use it in GitHub Desktop.
My React Native Initial Setup for Every Projects
// android/app/build.gradle
android {
...
defaultConfig {
...
versionCode versionMajor * 10000 + versionMinor * 100 + versionPatch
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
}
// setup keystore for release
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
}
// android/build.gradle
// start versioning
import groovy.json.JsonSlurper
def getNpmVersion() {
def inputFile = new File("../package.json")
def packageJson = new JsonSlurper().parseText(inputFile.text)
return packageJson["version"]
}
def getNpmVersionArray() { // major [0], minor [1], patch [2]
def (major, minor, patch) = getNpmVersion().tokenize('.')
return [Integer.parseInt(major), Integer.parseInt(minor), Integer.parseInt(patch)] as int[]
}
subprojects {
ext {
def npmVersion = getNpmVersionArray()
versionMajor = npmVersion[0]
versionMinor = npmVersion[1]
versionPatch = npmVersion[2]
}
}
// end of versioning
//...
// Generate keystore file and place it into android/app folder
MYAPP_RELEASE_STORE_FILE=your_keystore_name.keystore
MYAPP_RELEASE_KEY_ALIAS=your_alias
MYAPP_RELEASE_STORE_PASSWORD=your_store_password
MYAPP_RELEASE_KEY_PASSWORD=your_release_key_password
// add npm run script, for better
// yarn android # run app on android (debug)
// yarn android-releaes # run app on android (release)
// yarn ios # run app on ios (debug)
// yarn ios-release # runapp on ios (release)
// npm version # for app versioning
// ...
"scripts": {
"android": "node node_modules/react-native/local-cli/cli.js run-android",
"android-release": "node node_modules/react-native/local-cli/cli.js run-android --variant=release",
"ios": "node node_modules/react-native/local-cli/cli.js run-ios",
"ios-release": "node node_modules/react-native/local-cli/cli.js run-ios --configuration Release",
"version": "./version-ios.sh",
...
},
// ...
#!/usr/bin/env bash -e
PROJECT_DIR="ios/YourAppName"
INFOPLIST_FILE="Info.plist"
INFOPLIST_DIR="${PROJECT_DIR}/${INFOPLIST_FILE}"
PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')
BUILD_NUMBER=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${INFOPLIST_DIR}")
BUILD_NUMBER=$(($BUILD_NUMBER + 1))
# Update plist with new values
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${PACKAGE_VERSION#*v}" "${INFOPLIST_DIR}"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD_NUMBER" "${INFOPLIST_DIR}"
git add "${INFOPLIST_DIR}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment