-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathdependencies.gradle
117 lines (102 loc) · 5.13 KB
/
dependencies.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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
* version.
*/
def getDefaultGradlePluginVersion = { int reactNativeVersion ->
// Gradle plugin version can be found in the template:
// https://github.com/facebook/react-native/blob/main/packages/react-native/template/android/build.gradle
if (reactNativeVersion == 0 || reactNativeVersion >= v(0, 73, 0)) {
return ""
} else if (reactNativeVersion >= v(0, 71, 0)) {
return "7.3.1"
} else {
return "7.2.2"
}
}
def getKotlinVersion = { File baseDir ->
def fallbackVersion = "1.7.21"
def packagePath = findNodeModulesPath("react-native", baseDir)
def versionCatalog = file("${packagePath}/gradle/libs.versions.toml")
if (!versionCatalog.exists()) {
return fallbackVersion
}
def m = versionCatalog.text =~ /kotlin = "([.0-9]+)"/
def version = m.size() > 0 ? m[0][1] : fallbackVersion
logger.info("Detected Kotlin version: ${version}")
return version
}
ext {
reactNativeVersion = getPackageVersionNumber("react-native", rootDir)
compileSdkVersion = rootProject.findProperty("react.compileSdkVersion") ?: 34
minSdkVersion = rootProject.findProperty("react.minSdkVersion") ?: 24
targetSdkVersion = rootProject.findProperty("react.targetSdkVersion") ?: 33
autodetectReactNativeVersion = reactNativeVersion == 0 || reactNativeVersion >= v(0, 71, 0)
enableNewArchitecture = isNewArchitectureEnabled(project)
enableBridgeless = isBridgelessEnabled(project, enableNewArchitecture)
usePrefabs = reactNativeVersion == 0 || reactNativeVersion >= v(0, 71, 0)
androidPluginVersion = getDefaultGradlePluginVersion(reactNativeVersion)
kotlinVersion = rootProject.findProperty("KOTLIN_VERSION") ?: getKotlinVersion(rootDir)
// We need only set `ndkVersion` when building react-native from source.
if (rootProject.hasProperty("ANDROID_NDK_VERSION")) {
ndkVersion = rootProject.properties["ANDROID_NDK_VERSION"]
} else if (reactNativeVersion >= v(0, 74, 0)) {
// https://github.com/facebook/react-native/commit/9ce7b564131c5b2075489c09ff05325ddc28014a
ndkVersion = "26.1.10909125"
} else if (System.properties["os.arch"] == "aarch64" && androidPluginVersion == "7.2.2") {
// NDK r23c has been patched to support Apple M1 and is default in AGP
// 7.3.0. Prior to 0.71, we still need to set `ndkVersion` because we'll
// be using AGP 7.2.2 (see `androidPluginVersion` above).
// Note that even though newer 23.x versions exist, we'll stick to AGP's
// default. See also
// https://developer.android.com/build/releases/past-releases/agp-7-3-0-release-notes
ndkVersion = "23.1.7779620"
}
def kotlinVersionNumber = toVersionNumber(kotlinVersion)
/**
* Dependabot requires a `dependencies.gradle` to evaluate Java
* dependencies. It is also very particular about the formatting and cannot
* evaluate string literals.
*
* Hint: When making conditional changes, check whether the correct version
* is set with `./gradlew app:dependencies`.
*
* See https://github.com/dependabot/feedback/issues/345.
*/
libraries = [
androidAppCompat : "androidx.appcompat:appcompat:1.7.0",
androidCamera : "androidx.camera:camera-camera2:1.4.1",
androidCameraMlKitVision : "androidx.camera:camera-mlkit-vision:1.4.1",
androidCoreKotlinExtensions : "androidx.core:core-ktx:1.13.1",
androidRecyclerView : "androidx.recyclerview:recyclerview:1.3.2",
materialComponents : "com.google.android.material:material:1.12.0",
mlKitBarcodeScanning : "com.google.mlkit:barcode-scanning:17.3.0",
]
// Separate block so bots can parse this file properly
if (kotlinVersionNumber < v(1, 8, 0)) {
libraries.androidAppCompat = ["androidx.appcompat", "appcompat", "1.6.1"].join(":")
libraries.androidCamera = ["androidx.camera", "camera-camera2", "1.2.0-beta02"].join(":")
libraries.androidCameraMlKitVision = ["androidx.camera", "camera-mlkit-vision", "1.2.0-beta02"].join(":")
libraries.androidCoreKotlinExtensions = ["androidx.core", "core-ktx", "1.9.0"].join(":")
}
getReactNativeDependencies = {
// Hint: Use `./gradlew buildEnvironment` to check whether these are
// correctly set.
def dependencies = [
androidPluginVersion == ""
? "com.android.tools.build:gradle"
: "com.android.tools.build:gradle:${androidPluginVersion}",
"org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}",
]
if (autodetectReactNativeVersion || enableNewArchitecture) {
dependencies << "com.facebook.react:react-native-gradle-plugin"
dependencies << "de.undercouch:gradle-download-task:5.6.0"
}
return dependencies
}
}