forked from expo/expo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
327 lines (273 loc) · 10.3 KB
/
build.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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
import groovy.json.JsonSlurper
import java.util.regex.Matcher
import java.util.regex.Pattern
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'maven-publish'
group = 'host.exp.exponent'
version = '1.2.1'
// reanimated v2
def reactNativeFilePath = ["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()
def inputFile = new File(reactNativeFilePath)
def json = new JsonSlurper().parseText(inputFile.text)
def reactNativeVersion = json.version as String
def (major, minor, patch) = reactNativeVersion.tokenize('.')
def engine = "jsc"
// If the user has the reanimated 2.2.1 or above installed, we don't have to swap JNI implementation.
def shouldSwapJNI() {
try {
def reanimatedVersion = ["node", "--print", "require('react-native-reanimated/package.json').version"].execute(null, rootDir).text.trim()
if (reanimatedVersion == "undefined") {
return true
}
def (int major, int minor, int patch) = reanimatedVersion.tokenize('.').collect { it.toInteger() }
if (major < 2 || (major == 2 && minor <= 1) || (major == 2 && minor == 2 && patch == 0)) {
return true
}
return !rootProject.findProject(":react-native-reanimated")
} catch (ignored) {
return true
}
}
abstract class replaceSoTask extends DefaultTask {
public static String appName = ":app"
public static String buildDir = "../../../android/app/build"
@TaskAction
def run() {
for (def abiVersion in ["x86", "x86_64", "armeabi-v7a", "arm64-v8a"]) {
ant.sequential {
copy(
tofile: "${buildDir}/intermediates/merged_native_libs/debug/out/lib/${abiVersion}/libfbjni.so",
file: "../vendored/react-native-reanimated/libSo/fbjni/jni/${abiVersion}/libfbjni.so",
overwrite: true
)
}
}
}
}
def getCurrentFlavor() {
Gradle gradle = getGradle()
String taskRequestName = gradle.getStartParameter().getTaskRequests().toString()
Pattern pattern
if (taskRequestName.contains("assemble")) {
pattern = Pattern.compile("assemble(\\w+)(Release|Debug)")
} else if (taskRequestName.contains("bundle")) {
pattern = Pattern.compile("bundle(\\w+)(Release|Debug)")
} else {
pattern = Pattern.compile("generate(\\w+)(Release|Debug)")
}
Matcher matcher = pattern.matcher(taskRequestName)
if (matcher.find()) {
return matcher.group(1)
}
return ""
}
def replaceSoTaskDebug
def replaceSoTaskReleaseWithDevMenu
if (Integer.parseInt(minor) < 65 && shouldSwapJNI()) {
println("DevMenu will replace JNI library.")
tasks.register("replaceSoTaskDebug", replaceSoTask)
tasks.register("replaceSoTaskReleaseWithDevMenu", replaceSoTask)
replaceSoTaskDebug = project.getTasks().getByPath(":expo-dev-menu:replaceSoTaskDebug")
replaceSoTaskReleaseWithDevMenu = project.getTasks().getByPath(":expo-dev-menu:replaceSoTaskReleaseWithDevMenu")
}
rootProject.getSubprojects().forEach({ project ->
if (project.plugins.hasPlugin("com.android.application")) {
if (project.ext.has("react") && project.ext.react.enableHermes) {
engine = "hermes"
}
if (project.getProperties().get("android") && Integer.parseInt(minor) < 65 && shouldSwapJNI()) {
def projectProperties = project.getProperties()
if (!projectProperties.get("reanimated")
|| (projectProperties.get("reanimated") && projectProperties.get("reanimated").get("enablePackagingOptions"))
) {
def flavorNameCapitalized = getCurrentFlavor()
replaceSoTask.appName = project.getProperties().path
replaceSoTask.buildDir = project.getProperties().buildDir
def appName = project.getProperties().path
def tasks = project.getTasks()
replaceSoTaskDebug.dependsOn(
tasks.getByPath("${appName}:merge${flavorNameCapitalized}DebugNativeLibs"),
tasks.getByPath("${appName}:strip${flavorNameCapitalized}DebugDebugSymbols")
)
tasks.getByPath("${appName}:package${flavorNameCapitalized}Debug").dependsOn(replaceSoTaskDebug)
if (tasks.findByPath("${appName}:merge${flavorNameCapitalized}ReleaseWithDevMenuNativeLibs")
&& tasks.findByPath("${appName}:strip${flavorNameCapitalized}ReleaseWithDevMenuDebugSymbols")
&& tasks.findByPath("${appName}:package${flavorNameCapitalized}ReleaseWithDevMenu")) {
replaceSoTaskReleaseWithDevMenu.dependsOn(
task.getByPath("${appName}:merge${flavorNameCapitalized}ReleaseWithDevMenuNativeLibs"),
task.getByPath("${appName}:strip${flavorNameCapitalized}ReleaseWithDevMenuDebugSymbols")
)
tasks.getByPath("${appName}:package${flavorNameCapitalized}ReleaseWithDevMenu").dependsOn(replaceSoTaskReleaseWithDevMenu)
}
}
}
}
})
def reanimatedPath = "../vendored/react-native-reanimated/android"
def minorCopy = Integer.parseInt(minor)
def reanimatedFolder = file("${reanimatedPath}/${minorCopy}-${engine}")
while (!reanimatedFolder.exists()) {
minorCopy -= 1
reanimatedFolder = file("${reanimatedPath}/${minorCopy}-${engine}")
if (minorCopy < 62) {
throw new GradleException('No matching aar for react-native-reanimated found. Upgrade react-native to 0.63.x or later in order to use the expo-dev-menu package.')
}
}
def reanimatedVersion = minorCopy
// end of reanimated v2
buildscript {
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
if (expoModulesCorePlugin.exists()) {
apply from: expoModulesCorePlugin
applyKotlinExpoModulesCorePlugin()
}
// Simple helper that allows the root project to override versions declared by this library.
ext.safeExtGet = { prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
// Ensures backward compatibility
ext.getKotlinVersion = {
if (ext.has("kotlinVersion")) {
ext.kotlinVersion()
} else {
ext.safeExtGet("kotlinVersion", "1.6.10")
}
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
}
}
// Creating sources with comments
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release
// Add additional sourcesJar to artifacts
artifact(androidSourcesJar)
}
}
repositories {
maven {
url = mavenLocal().url
}
}
}
}
android {
compileSdkVersion safeExtGet("compileSdkVersion", 31)
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.majorVersion
}
defaultConfig {
minSdkVersion safeExtGet("minSdkVersion", 21)
targetSdkVersion safeExtGet("targetSdkVersion", 31)
versionCode 10
versionName '1.2.1'
}
lintOptions {
abortOnError false
}
buildTypes {
releaseWithDevMenu {
initWith release
matchingFallbacks = ['release', 'debug']
}
}
sourceSets {
debug {
jniLibs.srcDir "$reanimatedPath/$reanimatedVersion-$engine/jni"
java {
srcDirs += ['../vendored/react-native-gesture-handler/android/']
srcDirs += ['../vendored/react-native-safe-area-context/android/']
def expoPackageVersion = getExpoPackageVersion()
if (expoPackageVersion >= versionToNumber(45, 0, 0)) {
srcDirs += "src/expo-45"
} else {
srcDirs += "src/expo-44"
}
}
}
releaseWithDevMenu {
setRoot 'src/debug'
}
}
}
task copyAssets(type: Copy) {
from('../assets') {
exclude "*.ios.*"
}
into 'src/main/assets'
}
project.afterEvaluate {
packageDebugAssets.dependsOn copyAssets
packageReleaseWithDevMenuAssets.dependsOn copyAssets
}
repositories {
// ref: https://www.baeldung.com/maven-local-repository
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
// Android JSC is installed from npm
url "$rootDir/../node_modules/jsc-android/dist"
}
}
dependencies {
implementation project(':expo-modules-core')
implementation project(":expo-manifests")
debugImplementation files("${reanimatedPath}/${minorCopy}-${engine}/classes.jar")
releaseWithDevMenuImplementation files("${reanimatedPath}/${minorCopy}-${engine}/classes.jar")
implementation project(":expo-dev-menu-interface")
implementation 'com.squareup.okhttp3:okhttp:3.14.9'
implementation 'com.google.code.gson:gson:2.8.6'
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+'
implementation "androidx.transition:transition:1.1.0" // use by react-native-reanimated
// Fixes
// Cannot access 'androidx....' which is a supertype of 'expo.modules.devmenu.DevMenuActivity'.
// Check your module classpath for missing or conflicting dependencies
api "androidx.appcompat:appcompat:1.1.0"
api "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.5'
// Needed by gesture handler
implementation "androidx.core:core-ktx:1.6.0"
api "androidx.browser:browser:1.2.0"
testImplementation "com.google.truth:truth:1.1.2"
testImplementation "org.robolectric:robolectric:4.3.1"
testImplementation 'com.squareup.okhttp3:mockwebserver:4.3.1'
testImplementation 'androidx.test:core:1.4.0'
}
def versionToNumber(major, minor, patch) {
return patch * 100 + minor * 10000 + major * 1000000
}
def getNodeModulesPackageVersion(packageName, overridePropName) {
def nodeModulesVersion = ["node", "-e", "console.log(require('$packageName/package.json').version);"].execute([], projectDir).text.trim()
def version = safeExtGet(overridePropName, nodeModulesVersion)
def coreVersion = version.split("-")[0]
def (major, minor, patch) = coreVersion.tokenize('.').collect { it.toInteger() }
return versionToNumber(
major,
minor,
patch
)
}
def getExpoPackageVersion() {
return getNodeModulesPackageVersion("expo", "expoPackageVersion")
}