@@ -2,7 +2,7 @@ apply plugin: "com.android.application"
2
2
3
3
import com.android.build.OutputFile
4
4
import org.apache.tools.ant.taskdefs.condition.Os
5
- import groovy.swing.SwingBuilder
5
+ import groovy.json.JsonSlurper
6
6
7
7
/**
8
8
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
@@ -92,6 +92,15 @@ project.ext.react = [
92
92
93
93
apply from : new File ([" node" , " --print" , " require.resolve('react-native/package.json')" ]. execute(null , rootDir). text. trim(), " ../react.gradle" )
94
94
95
+ def getVersionFromPackageJson () {
96
+ // Read and parse package.json file from project root
97
+ def inputFile = new File (" $rootDir /../package.json" )
98
+ def packageJson = new JsonSlurper (). parseText(inputFile. text)
99
+
100
+ // Return the version, you can get any value this way
101
+ return packageJson[" version" ]
102
+ }
103
+
95
104
/**
96
105
* Set this to true to create two separate APKs instead of one:
97
106
* - An APK that only works on ARM devices
@@ -147,7 +156,7 @@ android {
147
156
minSdkVersion rootProject. ext. minSdkVersion
148
157
targetSdkVersion rootProject. ext. targetSdkVersion
149
158
versionCode 1
150
- versionName " 1.0.0 "
159
+ versionName getVersionFromPackageJson()
151
160
buildConfigField " boolean" , " IS_NEW_ARCHITECTURE_ENABLED" , isNewArchitectureEnabled(). toString()
152
161
153
162
if (isNewArchitectureEnabled()) {
0 commit comments