Last active
May 28, 2021 16:46
-
-
Save Pasi-D/f6aaa9abfddbb837f481289fda81b2c9 to your computer and use it in GitHub Desktop.
Android build gradle for react native with configurable versioning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: "com.android.application" | |
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" | |
.... | |
android { | |
... | |
defaultConfig { | |
applicationId "com.rnversioner" | |
minSdkVersion rootProject.ext.minSdkVersion | |
targetSdkVersion rootProject.ext.targetSdkVersion | |
versionCode generateVersionCode() | |
versionName generateVersionName() | |
} | |
... | |
} | |
/** | |
* Internal version number generator | |
* Refer https://developer.android.com/google/play/publishing/multiple-apks.html#using-a-version-code-scheme | |
*/ | |
private Integer generateVersionCode() { | |
return rootProject.ext.minSdkVersion * 10000000 + project.env.get("MAJOR_VERSION").toInteger() * 10000 + project.env.get("MINOR_VERSION").toInteger() * 100 + project.env.get("PATCH_VERSION").toInteger() | |
} | |
/** | |
* Internal version name generator | |
*/ | |
private String generateVersionName() { | |
String versionName = "${project.env.get("MAJOR_VERSION")}.${project.env.get("MINOR_VERSION")}.${project.env.get("PATCH_VERSION")}" | |
if(project.env.get("PRE_RELEASE") != null && !project.env.get("PRE_RELEASE").isEmpty()) { | |
versionName = versionName + "-" + project.env.get("PRE_RELEASE") | |
} | |
return versionName | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment