Skip to content

Commit

Permalink
fix(android): reduce redundant apply(from:) calls
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 committed Oct 22, 2024
1 parent c850d17 commit 76a2070
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 7 deletions.
2 changes: 2 additions & 0 deletions android/autolink.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import groovy.json.JsonSlurper

ext.rnta_autolink_gradle = true

ext.autolinkModules = { File projectRoot, File output, String testAppDir ->
String[] autolink = ["node", "${testAppDir}/android/autolink.mjs", projectRoot.toString(), output.toString()]
def stderr = new StringBuffer()
Expand Down
6 changes: 5 additions & 1 deletion android/config-plugins.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
apply(from: "${buildscript.sourceFile.getParent()}/node.gradle")
ext.rnta_config_plugins_gradle = true

if (!hasProperty("rnta_node_gradle")) {
apply(from: "${buildscript.sourceFile.getParent()}/node.gradle")
}

ext.applyConfigPlugins = { File rootDir, String testAppDir ->
if (!findNodeModulesPath("@expo/config-plugins", rootDir)) {
Expand Down
8 changes: 6 additions & 2 deletions android/dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
apply(from: "${buildscript.sourceFile.getParent()}/node.gradle")
apply(from: "${buildscript.sourceFile.getParent()}/react-native.gradle")
if (!hasProperty("rnta_node_gradle")) {
apply(from: "${buildscript.sourceFile.getParent()}/node.gradle")
}
if (!hasProperty("rnta_react_native_gradle")) {
apply(from: "${buildscript.sourceFile.getParent()}/react-native.gradle")
}

/**
* Returns the recommended Gradle plugin version for the specified React Native
Expand Down
2 changes: 2 additions & 0 deletions android/manifest.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import java.nio.file.Paths

def _manifest = null

ext.rnta_manifest_gradle = true

ext.getAppName = {
def manifest = getManifest()
if (manifest != null) {
Expand Down
2 changes: 2 additions & 0 deletions android/media-types.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ext.rnta_media_types_gradle = true

ext.isFontFile = { File file ->
// https://github.com/facebook/react-native/blob/3dfedbc1aec18a4255e126fde96d5dc7b1271ea7/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/assets/ReactFontManager.java#L28
return [".otf", ".ttf"].any { file.name.endsWith(it) }
Expand Down
6 changes: 5 additions & 1 deletion android/node.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import groovy.json.JsonSlurper
import java.nio.file.Paths

apply(from: "${buildscript.sourceFile.getParent()}/utils.gradle")
ext.rnta_node_gradle = true

if (!hasProperty("rnta_utils_gradle")) {
apply(from: "${buildscript.sourceFile.getParent()}/utils.gradle")
}

def _dependencies = [:]

Expand Down
6 changes: 5 additions & 1 deletion android/react-native.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
apply(from: "${buildscript.sourceFile.getParent()}/node.gradle")
ext.rnta_react_native_gradle = true

if (!hasProperty("rnta_node_gradle")) {
apply(from: "${buildscript.sourceFile.getParent()}/node.gradle")
}

ext.isBridgelessEnabled = { Project project, boolean isNewArchEnabled ->
if (isNewArchEnabled) {
Expand Down
2 changes: 2 additions & 0 deletions android/utils.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import groovy.json.JsonSlurper
import java.nio.file.Paths

ext.rnta_utils_gradle = true

ext.checkEnvironment = { rootDir, testAppDir ->
String[] args = ["node", "-p", "JSON.stringify(require('./android/gradle-wrapper.js').GRADLE_VERSIONS)"]
def stdout = new StringBuffer()
Expand Down
4 changes: 2 additions & 2 deletions test-app.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import java.nio.file.Paths
import org.gradle.initialization.DefaultSettings

def testAppDir = buildscript.sourceFile.getParent()
apply(from: "${testAppDir}/android/utils.gradle")
apply(from: "${testAppDir}/android/node.gradle")
apply(from: "${testAppDir}/android/autolink.gradle")
apply(from: "${testAppDir}/android/config-plugins.gradle")
apply(from: "${testAppDir}/android/media-types.gradle")
apply(from: "${testAppDir}/android/node.gradle")
apply(from: "${testAppDir}/android/utils.gradle")

checkEnvironment(rootDir, testAppDir)
applyConfigPlugins(rootDir, testAppDir)
Expand Down

0 comments on commit 76a2070

Please sign in to comment.