-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathbuild.gradle
More file actions
212 lines (178 loc) · 7.85 KB
/
build.gradle
File metadata and controls
212 lines (178 loc) · 7.85 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import groovy.json.JsonSlurper
import com.android.build.gradle.tasks.ExternalNativeBuildJsonTask
buildscript {
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['RNGH_kotlinVersion']
repositories {
mavenCentral()
google()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
classpath("com.android.tools.build:gradle:7.2.1")
classpath("com.diffplug.spotless:spotless-plugin-gradle:6.7.2")
}
}
def isNewArchitectureEnabled() {
// To opt-in for the New Architecture, you can either:
// - Set `newArchEnabled` to true inside the `gradle.properties` file
// - Invoke gradle with `-newArchEnabled=true`
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
def isGHExampleApp() {
return safeExtGet("isGHExampleApp", false)
}
def resolveReactNativeDirectory() {
def reactNativeLocation = safeExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
if (reactNativeLocation != null) {
return file(reactNativeLocation)
}
// Fallback to node resolver for custom directory structures like monorepos.
def reactNativePackage = file(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim())
if (reactNativePackage.exists()) {
return reactNativePackage.parentFile
}
throw new Exception(
"[react-native-gesture-handler] Unable to resolve react-native location in " +
"node_modules. You should add project extension property (in app/build.gradle) " +
"`REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
)
}
if (isNewArchitectureEnabled()) {
apply plugin: 'com.facebook.react'
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
if (project == rootProject) {
apply from: "spotless.gradle"
}
// Check whether Reanimated 2.3 or higher is installed alongside Gesture Handler
def shouldUseCommonInterfaceFromReanimated() {
def reanimated = rootProject.subprojects.find { it.name == 'react-native-reanimated' }
if (reanimated != null) {
def inputFile = new File(reanimated.projectDir, '../package.json')
def json = new JsonSlurper().parseText(inputFile.text)
def reanimatedVersion = json.version as String
def (major, minor, patch) = reanimatedVersion.tokenize('.')
return (Integer.parseInt(major) == 2 && Integer.parseInt(minor) >= 3) || Integer.parseInt(major) >= 3
} else {
return false
}
}
def reactNativeArchitectures() {
def value = project.getProperties().get("reactNativeArchitectures")
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}
def REACT_NATIVE_DIR = resolveReactNativeDirectory()
def reactProperties = new Properties()
file("$REACT_NATIVE_DIR/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.startsWith("0.0.0-") ? 1000 : REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
repositories {
mavenCentral()
}
android {
compileSdkVersion safeExtGet("compileSdkVersion", 33)
namespace "com.swmansion.gesturehandler"
buildFeatures {
buildConfig = true
prefab = true
}
// Used to override the NDK path/version on internal CI or by allowing
// users to customize the NDK path/version from their root project (e.g. for M1 support)
if (rootProject.hasProperty("ndkPath")) {
ndkPath rootProject.ext.ndkPath
}
if (rootProject.hasProperty("ndkVersion")) {
ndkVersion rootProject.ext.ndkVersion
}
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 21)
targetSdkVersion safeExtGet('targetSdkVersion', 33)
versionCode 1
versionName "1.0"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
buildConfigField "int", "REACT_NATIVE_MINOR_VERSION", REACT_NATIVE_MINOR_VERSION.toString()
if (isNewArchitectureEnabled()) {
var appProject = rootProject.allprojects.find {it.plugins.hasPlugin('com.android.application')}
externalNativeBuild {
cmake {
cppFlags "-O2", "-frtti", "-fexceptions", "-Wall", "-Werror", "-std=c++20", "-DANDROID"
arguments "-DREACT_NATIVE_DIR=${REACT_NATIVE_DIR}",
"-DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}",
"-DANDROID_STL=c++_shared"
abiFilters (*reactNativeArchitectures())
}
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
if (isNewArchitectureEnabled()) {
externalNativeBuild {
cmake {
path "src/main/jni/CMakeLists.txt"
}
}
}
packagingOptions {
// For some reason gradle only complains about the duplicated version of libreact_render libraries
// while there are more libraries copied in intermediates folder of the lib build directory, we exclude
// only the ones that make the build fail (ideally we should only include libgesturehandler but we
// are only allowed to specify exclude patterns)
exclude "**/libreact_render*.so"
exclude "**/libreactnative.so"
exclude "**/libjsi.so"
exclude "**/libc++_shared.so"
}
sourceSets.main {
java {
// Include "common/" only when it's not provided by Reanimated to mitigate
// multiple definitions of the same class preventing build
if (shouldUseCommonInterfaceFromReanimated()) {
srcDirs += 'reanimated/src/main/java'
} else {
srcDirs += 'common/src/main/java'
srcDirs += 'noreanimated/src/main/java'
}
if (REACT_NATIVE_MINOR_VERSION >= 77) {
// With RN 0.77, ViewManager related functions in the package has different signatures as they
// are no longer nullable
srcDirs += 'package77/src/main/java'
} else {
// It's safe to delete this block once we drop support for RN 0.76
srcDirs += 'packageDeprecated/src/main/java'
}
}
}
if (isGHExampleApp()) {
tasks.withType(ExternalNativeBuildJsonTask) {
compileTask ->
compileTask.doLast {
def rootDir = new File("${project.projectDir}/..")
def generated = new File("${compileTask.abi.getCxxBuildFolder()}/compile_commands.json")
def output = new File("${rootDir}/compile_commands.json")
output.text = generated.text
println("Generated clangd metadata.")
}
}
}
}
def kotlin_version = safeExtGet('kotlinVersion', project.properties['RNGH_kotlinVersion'])
dependencies {
implementation 'com.facebook.react:react-native:+' // from node_modules
if (shouldUseCommonInterfaceFromReanimated()) {
// Include Reanimated as dependency to load the common interface
implementation (rootProject.subprojects.find { it.name == 'react-native-reanimated' }) {
exclude group:'com.facebook.fbjni' // resolves "Duplicate class com.facebook.jni.CppException"
}
}
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation "androidx.core:core-ktx:1.6.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}