Skip to content

Commit

Permalink
Improved android build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
gosha212 committed Nov 24, 2024
1 parent a89a282 commit 3e89841
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 43 deletions.
53 changes: 29 additions & 24 deletions detox/android/rninfo.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import groovy.json.JsonSlurper

def getRNVersion = { workingDir ->
println("RNInfo: workingDir=$workingDir")
def getRNPackageJsonDir() {
def currentDir = rootDir
while (currentDir != null) {
def nodeModulesDir = new File(currentDir, "node_modules/react-native")
def file = new File(nodeModulesDir, 'package.json')
if (file.exists()) {
return file.path
}
currentDir = currentDir.parentFile
}
throw new GradleException("Unable to find module: $moduleName")
}

def getRNVersion = { rnPackageJsonPath ->
println("RNInfo: package.json=$rnPackageJsonPath")
def jsonSlurper = new JsonSlurper()
def packageFile = "$workingDir/../node_modules/react-native/package.json"
println("RNInfo: reading $packageFile")
Map<String, Object> packageJSON = jsonSlurper.parse(new File(packageFile))
def packageFile =
println("RNInfo: reading $rnPackageJsonPath")
Map<String, Object> packageJSON = jsonSlurper.parse(new File(rnPackageJsonPath))
String rnVersion = packageJSON.get('version')
return rnVersion
}
Expand All @@ -15,24 +28,16 @@ def getMajorVersionInternal = { semanticVersion ->
return rnVersionMajor
}

ext.getRnMajorVersion = { workingDir ->
String rnVersion = getRNVersion(workingDir)
Integer rnVersionMajor = getMajorVersionInternal(rnVersion)
return rnVersionMajor
}

def rnVersion = getRNVersion(rootDir)
def rnVersion = getRNVersion(getRNPackageJsonDir())
def rnMajorVer = getMajorVersionInternal(rnVersion)
if (hasProperty('project')) {
println "[$project] RNInfo: detected React Native version: $rnVersion (major=$rnMajorVer)"
println "RNInfo: detected React Native version: $rnVersion (major=$rnMajorVer)"

project.ext.rnInfo = [
version : rnVersion,
majorVersion : rnMajorVer,
isRN69OrHigher: rnMajorVer >= 69,
isRN70OrHigher: rnMajorVer >= 70,
isRN71OrHigher: rnMajorVer >= 71,
isRN72OrHigher: rnMajorVer >= 72,
isRN73OrHigher: rnMajorVer >= 73,
]
}
ext.rnInfo = [
version : rnVersion,
majorVersion : rnMajorVer,
isRN69OrHigher: rnMajorVer >= 69,
isRN70OrHigher: rnMajorVer >= 70,
isRN71OrHigher: rnMajorVer >= 71,
isRN72OrHigher: rnMajorVer >= 72,
isRN73OrHigher: rnMajorVer >= 73,
]
10 changes: 4 additions & 6 deletions detox/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ include ':detox'

println("RNInfo: rootDir=$rootDir")

def rnMajorVer = getRnMajorVersion(rootDir)
println "[settings] RNInfo: detected React Native version: (major=$rnMajorVer)"
println "[settings] RNInfo: detected React Native version: (major=${ext.rnInfo.version})"

if (rnMajorVer < 72) {
includeBuild('../node_modules/react-native-gradle-plugin')
} else {
if (ext.rnInfo.isRN72OrHigher) {
includeBuild('../node_modules/@react-native/gradle-plugin')
} else {
includeBuild('../node_modules/react-native-gradle-plugin')
}

11 changes: 4 additions & 7 deletions detox/test/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ apply from: file("../../android/rninfo.gradle")
rootProject.name = 'DetoxTest'
include ':app'

def rnMajorVer = getRnMajorVersion(rootDir)
println "[settings] RNInfo: detected React Native version: (major=$rnMajorVer)"
println "[settings] RNInfo: detected React Native version: (major=${ext.rnInfo.version})"

if (rnMajorVer < 72) {
includeBuild('../node_modules/react-native-gradle-plugin')
} else {
if (ext.rnInfo.isRN72OrHigher) {
includeBuild('../node_modules/@react-native/gradle-plugin')
} else {
includeBuild('../node_modules/react-native-gradle-plugin')
}



include ':detox'
project(':detox').projectDir = new File(rootProject.projectDir, '../../android/detox')

Expand Down
10 changes: 4 additions & 6 deletions examples/demo-react-native/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ rootProject.name = 'DetoxRNExample'

include ':app'

println("RNInfo: rootDir=$rootDir")
def rnMajorVer = getRnMajorVersion(rootDir)
println("[settings] RNInfo: detected React Native version: (major=$rnMajorVer)")
println("[settings] RNInfo: detected React Native version: (major=${ext.rnInfo.version})")

if (rnMajorVer < 72) {
includeBuild('../node_modules/react-native-gradle-plugin')
} else {
if (ext.rnInfo.isRN72OrHigher) {
includeBuild('../node_modules/@react-native/gradle-plugin')
} else {
includeBuild('../node_modules/react-native-gradle-plugin')
}


Expand Down

0 comments on commit 3e89841

Please sign in to comment.