react-native-reanimated 2.10.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +3 -0
  2. package/Common/cpp/{headers/AnimatedSensor → AnimatedSensor}/AnimatedSensorModule.h +0 -0
  3. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +2 -0
  4. package/Common/cpp/{headers/LayoutAnimations → LayoutAnimations}/LayoutAnimationsProxy.h +0 -0
  5. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +2 -0
  6. package/Common/cpp/{headers/NativeModules → NativeModules}/NativeReanimatedModule.h +5 -0
  7. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +2 -0
  8. package/Common/cpp/{headers/NativeModules → NativeModules}/NativeReanimatedModuleSpec.h +1 -1
  9. package/Common/cpp/{headers/Registries → Registries}/EventHandlerRegistry.h +0 -0
  10. package/Common/cpp/Registries/MapperRegistry.cpp +3 -1
  11. package/Common/cpp/{headers/Registries → Registries}/MapperRegistry.h +0 -0
  12. package/Common/cpp/Registries/WorkletsCache.cpp +3 -0
  13. package/Common/cpp/{headers/Registries → Registries}/WorkletsCache.h +0 -0
  14. package/Common/cpp/{headers/SharedItems → SharedItems}/FrozenObject.h +0 -0
  15. package/Common/cpp/{headers/SharedItems → SharedItems}/HostFunctionHandler.h +0 -0
  16. package/Common/cpp/SharedItems/MutableValue.cpp +2 -0
  17. package/Common/cpp/{headers/SharedItems → SharedItems}/MutableValue.h +0 -0
  18. package/Common/cpp/{headers/SharedItems → SharedItems}/MutableValueSetterProxy.h +0 -0
  19. package/Common/cpp/{headers/SharedItems → SharedItems}/RemoteObject.h +0 -0
  20. package/Common/cpp/{headers/SharedItems → SharedItems}/RuntimeManager.h +0 -0
  21. package/Common/cpp/SharedItems/ShareableValue.cpp +7 -2
  22. package/Common/cpp/{headers/SharedItems → SharedItems}/ShareableValue.h +0 -0
  23. package/Common/cpp/{headers/SharedItems → SharedItems}/SharedParent.h +0 -0
  24. package/Common/cpp/{headers/SharedItems → SharedItems}/ValueWrapper.h +0 -0
  25. package/Common/cpp/{headers/SpecTools → SpecTools}/ErrorHandler.h +0 -0
  26. package/Common/cpp/{headers/Tools → Tools}/FeaturesConfig.h +0 -0
  27. package/Common/cpp/Tools/JSIStoreValueUser.cpp +2 -2
  28. package/Common/cpp/{headers/Tools → Tools}/JSIStoreValueUser.h +0 -0
  29. package/Common/cpp/{headers/Tools → Tools}/Mapper.h +0 -0
  30. package/Common/cpp/{headers/Tools → Tools}/PlatformDepMethodsHolder.h +0 -0
  31. package/Common/cpp/{headers/Tools → Tools}/ReanimatedHiddenHeaders.h +1 -1
  32. package/Common/cpp/{headers/Tools → Tools}/RuntimeDecorator.h +0 -0
  33. package/Common/cpp/{headers/Tools → Tools}/Scheduler.h +0 -0
  34. package/Common/cpp/Tools/SingleInstanceChecker.h +58 -0
  35. package/Common/cpp/{headers/Tools → Tools}/WorkletEventHandler.h +0 -0
  36. package/RNReanimated.podspec +14 -73
  37. package/android/.gradle/7.5.1/checksums/checksums.lock +0 -0
  38. package/android/.gradle/7.5.1/checksums/md5-checksums.bin +0 -0
  39. package/android/.gradle/7.5.1/checksums/sha1-checksums.bin +0 -0
  40. package/android/.gradle/7.5.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  41. package/android/.gradle/{7.2 → 7.5.1}/dependencies-accessors/gc.properties +0 -0
  42. package/android/.gradle/7.5.1/executionHistory/executionHistory.bin +0 -0
  43. package/android/.gradle/7.5.1/executionHistory/executionHistory.lock +0 -0
  44. package/android/.gradle/{7.2 → 7.5.1}/fileChanges/last-build.bin +0 -0
  45. package/android/.gradle/7.5.1/fileHashes/fileHashes.bin +0 -0
  46. package/android/.gradle/7.5.1/fileHashes/fileHashes.lock +0 -0
  47. package/android/.gradle/{7.2 → 7.5.1}/fileHashes/resourceHashesCache.bin +0 -0
  48. package/android/.gradle/{7.2 → 7.5.1}/gc.properties +0 -0
  49. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  50. package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
  51. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  52. package/android/.gradle/file-system.probe +0 -0
  53. package/android/CMakeLists.txt +56 -65
  54. package/android/build.gradle +377 -103
  55. package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
  56. package/android/react-native-reanimated-66-hermes.aar +0 -0
  57. package/android/react-native-reanimated-66-jsc.aar +0 -0
  58. package/android/react-native-reanimated-67-hermes.aar +0 -0
  59. package/android/react-native-reanimated-67-jsc.aar +0 -0
  60. package/android/react-native-reanimated-68-hermes.aar +0 -0
  61. package/android/react-native-reanimated-68-jsc.aar +0 -0
  62. package/android/react-native-reanimated-69-hermes.aar +0 -0
  63. package/android/react-native-reanimated-69-jsc.aar +0 -0
  64. package/android/react-native-reanimated-70-hermes.aar +0 -0
  65. package/android/react-native-reanimated-70-jsc.aar +0 -0
  66. package/android/src/main/cpp/AndroidErrorHandler.cpp +3 -4
  67. package/android/src/main/cpp/{headers/AndroidErrorHandler.h → AndroidErrorHandler.h} +1 -4
  68. package/android/src/main/cpp/AndroidLogger.cpp +4 -1
  69. package/android/src/main/cpp/{headers/AndroidLogger.h → AndroidLogger.h} +0 -0
  70. package/android/src/main/cpp/{headers/AndroidScheduler.h → AndroidScheduler.h} +0 -0
  71. package/android/src/main/cpp/{headers/JNIHelper.h → JNIHelper.h} +0 -0
  72. package/android/src/main/cpp/{headers/LayoutAnimations.h → LayoutAnimations.h} +0 -0
  73. package/android/src/main/cpp/NativeProxy.cpp +6 -8
  74. package/android/src/main/cpp/{headers/NativeProxy.h → NativeProxy.h} +0 -0
  75. package/android/src/main/cpp/{headers/TurboModule.h → TurboModule.h} +0 -0
  76. package/android/src/main/java/com/swmansion/reanimated/NativeProxy.java +4 -5
  77. package/android/src/main/java/com/swmansion/reanimated/keyboardObserver/ReanimatedKeyboardEventListener.java +2 -1
  78. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +2 -2
  79. package/ios/{REAModule.m → REAModule.mm} +12 -0
  80. package/ios/native/NativeProxy.mm +4 -2
  81. package/ios/native/REAInitializer.h +2 -2
  82. package/ios/native/REAInitializer.mm +2 -2
  83. package/ios/native/UIResponder+Reanimated.mm +1 -1
  84. package/lib/index.web.js +2 -0
  85. package/lib/reanimated2/NativeMethods.js +33 -19
  86. package/lib/reanimated2/frameCallback/FrameCallbackRegistryJS.js +4 -4
  87. package/lib/reanimated2/frameCallback/FrameCallbackRegistryUI.js +47 -18
  88. package/lib/reanimated2/globals.d.ts +2 -2
  89. package/lib/reanimated2/hook/index.js +1 -0
  90. package/lib/reanimated2/hook/useScrollViewOffset.js +26 -0
  91. package/lib/reanimated2/utils.js +10 -3
  92. package/lib/types/index.web.d.ts +1 -0
  93. package/lib/types/reanimated2/NativeMethods.d.ts +3 -10
  94. package/lib/types/reanimated2/commonTypes.d.ts +8 -0
  95. package/lib/types/reanimated2/frameCallback/FrameCallbackRegistryJS.d.ts +4 -3
  96. package/lib/types/reanimated2/frameCallback/FrameCallbackRegistryUI.d.ts +5 -9
  97. package/lib/types/reanimated2/hook/index.d.ts +1 -0
  98. package/lib/types/reanimated2/hook/useAnimatedScrollHandler.d.ts +1 -2
  99. package/lib/types/reanimated2/hook/useFrameCallback.d.ts +2 -1
  100. package/lib/types/reanimated2/hook/useScrollViewOffset.d.ts +4 -0
  101. package/lib/types/reanimated2/utils.d.ts +5 -1
  102. package/package.json +5 -4
  103. package/plugin.js +1 -1
  104. package/react-native-reanimated.d.ts +13 -9
  105. package/scripts/reanimated_utils.rb +65 -0
  106. package/src/index.web.ts +2 -0
  107. package/src/reanimated2/NativeMethods.ts +44 -32
  108. package/src/reanimated2/commonTypes.ts +9 -0
  109. package/src/reanimated2/frameCallback/FrameCallbackRegistryJS.ts +6 -9
  110. package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +78 -27
  111. package/src/reanimated2/globals.d.ts +2 -2
  112. package/src/reanimated2/hook/index.ts +1 -0
  113. package/src/reanimated2/hook/useAnimatedScrollHandler.ts +3 -1
  114. package/src/reanimated2/hook/useFrameCallback.ts +2 -1
  115. package/src/reanimated2/hook/useScrollViewOffset.ts +36 -0
  116. package/src/reanimated2/utils.ts +12 -5
  117. package/android/.gradle/7.2/dependencies-accessors/dependencies-accessors.lock +0 -0
  118. package/android/.gradle/7.2/executionHistory/executionHistory.bin +0 -0
  119. package/android/.gradle/7.2/executionHistory/executionHistory.lock +0 -0
  120. package/android/.gradle/7.2/fileHashes/fileHashes.bin +0 -0
  121. package/android/.gradle/7.2/fileHashes/fileHashes.lock +0 -0
  122. package/android/.gradle/checksums/checksums.lock +0 -0
  123. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  124. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  125. package/android/src/main/java/com/swmansion/reanimated/AndroidErrorHandler.java +0 -8
  126. package/lib/reanimated2/__mocks__/NativeReanimated.native.js +0 -20
  127. package/lib/types/reanimated2/__mocks__/NativeReanimated.native.d.ts +0 -13
@@ -1,11 +1,7 @@
1
1
  import com.android.Version
2
+ import org.apache.tools.ant.filters.ReplaceTokens
2
3
 
3
- import java.nio.file.Files
4
4
  import java.nio.file.Paths
5
- import java.nio.file.Path
6
- import org.apache.tools.ant.filters.ReplaceTokens
7
- import groovy.json.JsonSlurper
8
- import java.util.stream.Stream
9
5
 
10
6
  /**
11
7
  * Finds the path of the installed npm package with the given name using Node's
@@ -46,14 +42,21 @@ def safeExtGet(prop, fallback) {
46
42
  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
47
43
  }
48
44
 
45
+ def safeAppExtGet(prop, fallback) {
46
+ def appProject = null
47
+ try {
48
+ appProject = project(":app")
49
+ } catch(Exception e) {
50
+ return fallback
51
+ }
52
+ appProject?.ext?.has(prop) ? appProject.ext.get(prop) : fallback
53
+ }
54
+
49
55
  def resolveBuildType() {
50
- def buildType = "debug"
51
- tasks.all({ task ->
52
- if (task.name == "buildCMakeRelease") {
53
- buildType = "release"
54
- }
55
- })
56
- return buildType
56
+ Gradle gradle = getGradle()
57
+ String tskReqStr = gradle.getStartParameter().getTaskRequests()['args'].toString()
58
+
59
+ return tskReqStr.contains('Release') ? 'release' : 'debug'
57
60
  }
58
61
 
59
62
  def resolveClientSideBuild() {
@@ -75,7 +78,7 @@ def resolveClientSideBuild() {
75
78
 
76
79
  def isDeveloperMode() {
77
80
  // developer mode, to run Example app
78
- return file("$projectDir/../node_modules/react-native/package.json").exists()
81
+ return safeAppExtGet("isReanimatedExampleApp", false) || System.getenv("REANIMATED_PACKAGE_BUILD") == "1"
79
82
  }
80
83
 
81
84
  def isNewArchitectureEnabled() {
@@ -87,10 +90,32 @@ def isNewArchitectureEnabled() {
87
90
  }
88
91
 
89
92
  def resolveReactNativeDirectory() {
93
+ def reactNativeLocation = safeAppExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
94
+ if (reactNativeLocation != null) {
95
+ return file(reactNativeLocation)
96
+ }
97
+
90
98
  if (isDeveloperMode()) {
91
99
  return file("$projectDir/../${getPlaygroundAppName()}/node_modules/react-native")
92
100
  }
93
- return file("$projectDir/../../react-native")
101
+
102
+ // monorepo workaround
103
+ // react-native can be hoisted or in project's own node_modules
104
+ def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native")
105
+ if (reactNativeFromProjectNodeModules.exists()) {
106
+ return reactNativeFromProjectNodeModules
107
+ }
108
+
109
+ def reactNativeFromNodeModulesWithReanimated = file("${projectDir}/../../react-native")
110
+ if (reactNativeFromNodeModulesWithReanimated.exists()) {
111
+ return reactNativeFromNodeModulesWithReanimated
112
+ }
113
+
114
+ throw new Exception(
115
+ "[Reanimated] Unable to resolve react-native location in " +
116
+ "node_modules. You should project extension property (in app/build.gradle) " +
117
+ "`REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
118
+ )
94
119
  }
95
120
 
96
121
  def getPlaygroundAppName() { // only for the development
@@ -109,66 +134,81 @@ def getPlaygroundAppName() { // only for the development
109
134
  return playgroundAppName
110
135
  }
111
136
 
112
- boolean CLIENT_SIDE_BUILD = resolveClientSideBuild()
113
- if (CLIENT_SIDE_BUILD) {
114
- configurations.maybeCreate("default")
137
+ def shouldAssertNoMultipleInstances() {
138
+ if (rootProject.hasProperty("disableMultipleInstancesCheck")) {
139
+ return rootProject.property("disableMultipleInstancesCheck") != "true"
140
+ } else {
141
+ return true
142
+ }
143
+ }
115
144
 
116
- List<Path> paths = Files.find(
117
- Paths.get(rootDir.parent),
118
- Integer.MAX_VALUE,
119
- {path, fileAttributes -> path.toString().endsWith("/react-native-reanimated/package.json") }
120
- ).toArray()
145
+ def findReanimatedInstancesForPath(String path) {
146
+ return fileTree(path) {
147
+ include "**/react-native-reanimated/package.json"
148
+ exclude "**/.yarn/**"
149
+ exclude {{ file, attr -> attr.isSymbolicLink() }}
150
+ }.files
151
+ }
121
152
 
122
- String parsedLocation = ""
123
- def libInstancesCount = 0
124
- for (def path in paths) {
125
- parsedLocation += "- " + path.toString().replace("/package.json", "\n")
126
- libInstancesCount++
127
- }
128
- if (libInstancesCount > 1) {
129
- String exceptionMessage = "\nMultiple versions of Reanimated were detected. Only one instance of react-native-reanimated can be installed in a project. You need to resolve the conflict manually. Check out the documentation: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/troubleshooting#multiple-versions-of-reanimated-were-detected \n\nConflict between: \n" + parsedLocation + "\n";
153
+ def assertNoMultipleInstances() {
154
+ // Assert there are no multiple installations of Reanimated
155
+ Set<File> files
156
+ if (projectDir.path.contains(rootDir.parent)) {
157
+ // standard app
158
+ files = findReanimatedInstancesForPath(rootDir.parent + "/node_modules")
159
+ } else {
160
+ // monorepo
161
+ files = findReanimatedInstancesForPath(rootDir.parent + "/node_modules")
162
+ files.addAll(
163
+ findReanimatedInstancesForPath(file(projectDir.parent).parent)
164
+ )
165
+ }
166
+ if (files.size() > 1) {
167
+ String parsedLocation = files.stream().map({
168
+ File file -> "- " + file.toString().replace("/package.json", "")
169
+ }).collect().join("\n")
170
+ String exceptionMessage = "\nMultiple versions of Reanimated were detected. Only one " +
171
+ "instance of react-native-reanimated can be installed in a project. You need to " +
172
+ "resolve the conflict manually. Check out the documentation: " +
173
+ "https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/" +
174
+ "troubleshooting#multiple-versions-of-reanimated-were-detected \n\nConflict " +
175
+ "between: \n" + parsedLocation + "\n";
130
176
  throw new Exception(exceptionMessage)
131
177
  }
132
178
  }
133
- def reactNative = resolveReactNativeDirectory()
134
- def reactNativeManifest = file("$reactNative/package.json")
135
- def reactNativeManifestAsJson = new JsonSlurper().parseText(reactNativeManifest.text)
136
- def reactNativeVersion = reactNativeManifestAsJson.version as String
137
- def (major, minor, patch) = reactNativeVersion.tokenize('.')
138
- def rnMinorVersion = Integer.parseInt(minor)
139
179
 
140
- def localProps = new Properties()
141
- def localPropertiesFile = file("local.properties")
142
- if (localPropertiesFile.exists()) {
143
- localProps.load(new InputStreamReader(new FileInputStream(localPropertiesFile), "UTF-8"))
180
+ boolean CLIENT_SIDE_BUILD = resolveClientSideBuild()
181
+ if (CLIENT_SIDE_BUILD) {
182
+ configurations.maybeCreate("default")
144
183
  }
145
184
 
146
- def debugNativeLibraries = localProps.getProperty('NATIVE_DEBUG_ON', 'FALSE').toBoolean()
185
+ def reactNativeRootDir = resolveReactNativeDirectory()
186
+
147
187
  def reactProperties = new Properties()
148
- file("$reactNative/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
188
+ file("$reactNativeRootDir/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
149
189
 
150
190
  def BOOST_VERSION = reactProperties.getProperty("BOOST_VERSION")
151
191
  def DOUBLE_CONVERSION_VERSION = reactProperties.getProperty("DOUBLE_CONVERSION_VERSION")
152
192
  def FOLLY_VERSION = reactProperties.getProperty("FOLLY_VERSION")
153
193
  def GLOG_VERSION = reactProperties.getProperty("GLOG_VERSION")
154
- def REACT_VERSION = reactProperties.getProperty("VERSION_NAME").split("\\.")[1].toInteger()
194
+ def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
195
+ def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
155
196
  def FBJNI_VERSION = "0.3.0"
197
+ def REANIMATED_PACKAGE_BUILD = System.getenv("REANIMATED_PACKAGE_BUILD")
156
198
 
157
199
  // We download various C++ open-source dependencies into downloads.
158
200
  // We then copy both the downloaded code and our custom makefiles and headers into third-party-ndk.
159
201
  // After that we build native code from src/main/jni with module path pointing at third-party-ndk.
160
202
 
161
- def downloadsDir = new File("$buildDir/downloads")
203
+ def customDownloadsDir = System.getenv("REACT_NATIVE_DOWNLOADS_DIR")
204
+ def downloadsDir = customDownloadsDir ? new File(customDownloadsDir) : new File("$buildDir/downloads")
162
205
  def thirdPartyNdkDir = new File("$buildDir/third-party-ndk")
163
206
 
164
- def reactNativeThirdParty = new File("$reactNative/ReactAndroid/src/main/jni/third-party")
207
+ def reactNativeThirdParty = new File("$reactNativeRootDir/ReactAndroid/src/main/jni/third-party")
208
+ def reactNativeAndroidDownloadDir = new File("$reactNativeRootDir/ReactAndroid/build/downloads")
165
209
 
166
210
  def _stackProtectorFlag = true
167
211
 
168
- def CMAKE_NODE_MODULES_DIR = CLIENT_SIDE_BUILD
169
- ? project.getProjectDir().getParentFile().getParent()
170
- : Paths.get(project.getProjectDir().getParent(), getPlaygroundAppName(), "node_modules").toString()
171
-
172
212
  def JS_RUNTIME = {
173
213
  // Returns the js runtime explicitly requested in the environment variable
174
214
  if (System.getenv("JS_RUNTIME")) {
@@ -187,15 +227,15 @@ def JS_RUNTIME = {
187
227
 
188
228
  def jsRuntimeDir = {
189
229
  if (JS_RUNTIME == "hermes") {
190
- if (rnMinorVersion >= 69) {
191
- return Paths.get(CMAKE_NODE_MODULES_DIR, "react-native", "sdks", "hermes")
230
+ if (REACT_NATIVE_MINOR_VERSION >= 69) {
231
+ return Paths.get(reactNativeRootDir.path, "sdks", "hermes")
192
232
  } else {
193
- return Paths.get(CMAKE_NODE_MODULES_DIR, "hermes-engine")
233
+ return Paths.get(reactNativeRootDir.path, "..", "hermes-engine")
194
234
  }
195
235
  } else if (JS_RUNTIME == "v8") {
196
236
  return findProject(":react-native-v8").getProjectDir().getParent()
197
237
  } else {
198
- return Paths.get(CMAKE_NODE_MODULES_DIR, "react-native", "ReactCommon", "jsi")
238
+ return Paths.get(reactNativeRootDir.path, "ReactCommon", "jsi")
199
239
  }
200
240
  }.call()
201
241
 
@@ -204,6 +244,145 @@ def reactNativeArchitectures() {
204
244
  return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
205
245
  }
206
246
 
247
+ def detectAAR(Integer rnMinorVersion, String engine) { // Reanimated2 only
248
+ def rnMinorVersionCopy = rnMinorVersion
249
+ def aar = file("react-native-reanimated-${rnMinorVersionCopy}-${engine}.aar")
250
+
251
+ if (aar.exists()) {
252
+ println "AAR for react-native-reanimated has been found\n$aar"
253
+ return aar
254
+ } else {
255
+ while (!aar.exists() && rnMinorVersionCopy >= 63) {
256
+ rnMinorVersionCopy -= 1
257
+ aar = file("react-native-reanimated-${rnMinorVersionCopy}-${engine}.aar")
258
+ }
259
+
260
+ if (rnMinorVersionCopy < 63) {
261
+ println "No AAR for react-native-reanimated found. Attempting to build from source."
262
+ } else { // aar exists, but was build for lower react-native version
263
+ println "\n\n\n"
264
+ println "****************************************************************************************"
265
+ println "\n\n\n"
266
+ println "WARNING reanimated - no version-specific reanimated AAR for react-native version $minor found."
267
+ println "Falling back to AAR for react-native version $rnMinorVersionCopy."
268
+ println "The react-native JSI interface is not ABI-safe yet, this may result in crashes."
269
+ println "Please post a pull request to implement support for react-native version $minor to the reanimated repo."
270
+ println "Thanks!"
271
+ println "\n\n\n"
272
+ println "****************************************************************************************"
273
+
274
+ return aar
275
+ }
276
+ }
277
+ return null
278
+ }
279
+
280
+ def isUserDemandToBuildFromSource() { // Reanimated2 only
281
+ def buildFromSourceConf = false
282
+ rootProject.getSubprojects().forEach({project ->
283
+ if (project.plugins.hasPlugin("com.android.application")) {
284
+ if (
285
+ project.ext.has("reanimated")
286
+ && project.ext.reanimated.buildFromSource
287
+ ) {
288
+ buildFromSourceConf = true
289
+ }
290
+ }
291
+ })
292
+ return buildFromSourceConf
293
+ }
294
+
295
+ def shouldBuildFromSource(aar, jsRuntimeName) { // Reanimated2 only
296
+ if (jsRuntimeName == "v8") {
297
+ return true
298
+ }
299
+ else if (isDeveloperMode()) {
300
+ // Example app
301
+ return true
302
+ }
303
+ else if (isUserDemandToBuildFromSource()) {
304
+ // on user demand
305
+ return true
306
+ }
307
+ else if (aar != null) {
308
+ // when binary exist
309
+ return false
310
+ }
311
+ // when binary is not found
312
+ return true
313
+ }
314
+
315
+ def getTaskByPath(
316
+ project,
317
+ String appName,
318
+ String secondPart,
319
+ String flavorString,
320
+ String lastPart
321
+ ) { // Reanimated2 only
322
+ String pathName = "${appName}:${secondPart}${flavorString}${lastPart}"
323
+ Task task = project.getTasks().findByPath(pathName)
324
+ if (task != null) {
325
+ return task
326
+ }
327
+ pathName = "${appName}:${secondPart}${flavorString.capitalize()}${lastPart}"
328
+ return project.getTasks().findByPath(pathName)
329
+ }
330
+
331
+ def aar = detectAAR(REACT_NATIVE_MINOR_VERSION, JS_RUNTIME)
332
+ boolean BUILD_FROM_SOURCE = shouldBuildFromSource(aar, JS_RUNTIME)
333
+
334
+ if (!BUILD_FROM_SOURCE && !isNewArchitectureEnabled()) { // Reanimated2 only
335
+ if (REACT_NATIVE_MINOR_VERSION < 65) {
336
+ tasks.register("replaceSoTaskDebug", replaceSoTask)
337
+ tasks.register("replaceSoTaskRelease", replaceSoTask)
338
+ Task replaceSoTaskDebug = project.getTasks().findByPath(":react-native-reanimated:replaceSoTaskDebug")
339
+ Task replaceSoTaskRelease = project.getTasks().findByPath(":react-native-reanimated:replaceSoTaskRelease")
340
+
341
+ if (replaceSoTaskDebug != null && replaceSoTaskRelease != null) {
342
+ rootProject.getSubprojects().forEach({project ->
343
+ if (project.plugins.hasPlugin("com.android.application") && project.getProperties().get("android")) {
344
+ def projectProperties = project.getProperties()
345
+ def flavorString = getCurrentFlavor()
346
+ def reanimatedConf = projectProperties.get("reanimated")
347
+
348
+ if (
349
+ flavorString != "NOT-FOUND"
350
+ && (!reanimatedConf || (reanimatedConf && !reanimatedConf.get("enablePackagingOptions")))
351
+ ) {
352
+ replaceSoTask.appName = projectProperties.path
353
+ replaceSoTask.buildDir = projectProperties.buildDir
354
+ def appName = projectProperties.path
355
+
356
+ Task debugNativeLibsTask = getTaskByPath(project, appName, "merge", flavorString, "DebugNativeLibs")
357
+ Task debugDebugSymbolsTask = getTaskByPath(project, appName, "strip", flavorString, "DebugDebugSymbols")
358
+ Task releaseNativeLibsTask = getTaskByPath(project, appName, "merge", flavorString, "ReleaseNativeLibs")
359
+ Task releaseDebugSymbolsTask = getTaskByPath(project, appName, "strip", flavorString, "ReleaseDebugSymbols")
360
+ Task debugTask = getTaskByPath(project, appName, "package", flavorString, "Debug")
361
+ Task releaseTask = getTaskByPath(project, appName, "package", flavorString, "Release")
362
+
363
+ if (
364
+ debugNativeLibsTask != null && debugDebugSymbolsTask != null
365
+ && releaseNativeLibsTask != null && releaseDebugSymbolsTask != null
366
+ && debugTask != null && releaseTask != null
367
+ ) {
368
+ replaceSoTaskDebug.dependsOn(debugNativeLibsTask, debugDebugSymbolsTask)
369
+ debugTask.dependsOn(replaceSoTaskDebug)
370
+ replaceSoTaskRelease.dependsOn(releaseNativeLibsTask, releaseDebugSymbolsTask)
371
+ releaseTask.dependsOn(replaceSoTaskRelease)
372
+ }
373
+ }
374
+ }
375
+ })
376
+ }
377
+ }
378
+
379
+ artifacts.add("default", aar)
380
+ }
381
+
382
+ // end if already loaded aar
383
+ if (!BUILD_FROM_SOURCE) {
384
+ return
385
+ }
207
386
  // You need to have following folders in this directory:
208
387
  // - boost_1_63_0
209
388
  // - double-conversion-1.1.6
@@ -233,9 +412,9 @@ buildscript {
233
412
  }
234
413
  }
235
414
  dependencies {
236
- classpath "com.android.tools.build:gradle:4.2.2"
237
- classpath "de.undercouch:gradle-download-task:4.1.2"
238
- classpath "com.diffplug.spotless:spotless-plugin-gradle:5.15.0"
415
+ classpath "com.android.tools.build:gradle:7.3.0"
416
+ classpath "de.undercouch:gradle-download-task:5.0.1"
417
+ classpath "com.diffplug.spotless:spotless-plugin-gradle:6.11.0"
239
418
  }
240
419
  }
241
420
 
@@ -258,17 +437,16 @@ android {
258
437
  externalNativeBuild {
259
438
  cmake {
260
439
  arguments "-DANDROID_STL=c++_shared",
261
- "-DNATIVE_DEBUG=${debugNativeLibraries}",
262
- "-DREACT_NATIVE_TARGET_VERSION=${REACT_VERSION}",
440
+ "-DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}",
263
441
  "-DANDROID_TOOLCHAIN=clang",
264
442
  "-DBOOST_VERSION=${BOOST_VERSION}",
265
- "-DNODE_MODULES_DIR=${CMAKE_NODE_MODULES_DIR}",
443
+ "-DREACT_NATIVE_DIR=${reactNativeRootDir.path}",
266
444
  "-DJS_RUNTIME=${JS_RUNTIME}",
267
445
  "-DJS_RUNTIME_DIR=${jsRuntimeDir}",
268
446
  "-DCLIENT_SIDE_BUILD=${CLIENT_SIDE_BUILD}",
269
447
  "-DIS_NEW_ARCHITECTURE_ENABLED=${isNewArchitectureEnabled()}",
270
448
  "-DPLAYGROUND_APP_NAME=${getPlaygroundAppName()}",
271
- "-DRNVERSION=${rnMinorVersion}"
449
+ "-DREANIMATED_PACKAGE_BUILD=${REANIMATED_PACKAGE_BUILD}"
272
450
  abiFilters (*reactNativeArchitectures())
273
451
  _stackProtectorFlag ? (cppFlags("-fstack-protector-all")) : null
274
452
  }
@@ -276,21 +454,41 @@ android {
276
454
 
277
455
  buildConfigField("boolean", "IS_INTERNAL_BUILD", "false")
278
456
  buildConfigField("int", "EXOPACKAGE_FLAGS", "0")
279
- buildConfigField("int", "REACT_NATIVE_VERSION", rnMinorVersion.toString())
457
+ buildConfigField("int", "REACT_NATIVE_MINOR_VERSION", REACT_NATIVE_MINOR_VERSION.toString())
280
458
  }
281
459
  externalNativeBuild {
282
460
  cmake {
283
461
  path "CMakeLists.txt"
284
- version "3.18.1"
462
+ }
463
+ }
464
+ buildTypes {
465
+ debug {
466
+ externalNativeBuild {
467
+ cmake {
468
+ if (JS_RUNTIME == "hermes") {
469
+ arguments "-DHERMES_ENABLE_DEBUGGER=1"
470
+ } else {
471
+ arguments "-DHERMES_ENABLE_DEBUGGER=0"
472
+ }
473
+ }
474
+ }
475
+ }
476
+ release {
477
+ externalNativeBuild {
478
+ cmake {
479
+ arguments "-DHERMES_ENABLE_DEBUGGER=0"
480
+ }
481
+ }
285
482
  }
286
483
  }
287
484
  lintOptions {
288
485
  abortOnError false
289
486
  }
290
487
  packagingOptions {
291
- println "Native libs debug enabled: ${debugNativeLibraries}"
292
- doNotStrip debugNativeLibraries ? "**/**/*.so" : ''
488
+ doNotStrip resolveBuildType() == 'debug' ? "**/**/*.so" : ''
293
489
  excludes = [
490
+ "META-INF",
491
+ "META-INF/**",
294
492
  "**/libc++_shared.so",
295
493
  "**/libfbjni.so",
296
494
  "**/libjsi.so",
@@ -298,6 +496,7 @@ android {
298
496
  "**/libfolly_runtime.so",
299
497
  "**/libglog.so",
300
498
  "**/libhermes.so",
499
+ "**/libhermes-executor-debug.so",
301
500
  "**/libreactnativejni.so",
302
501
  "**/libjscexecutor.so",
303
502
  "**/libv8executor.so",
@@ -338,6 +537,17 @@ android {
338
537
  }
339
538
  }
340
539
 
540
+ def assertionTask = task assertNoMultipleInstancesTask {
541
+ onlyIf { shouldAssertNoMultipleInstances() && CLIENT_SIDE_BUILD }
542
+ doFirst {
543
+ assertNoMultipleInstances()
544
+ }
545
+ }
546
+
547
+ tasks.preBuild {
548
+ dependsOn assertionTask
549
+ }
550
+
341
551
  task cleanCmakeCache() {
342
552
  tasks.getByName("clean").dependsOn(cleanCmakeCache)
343
553
  doFirst {
@@ -355,7 +565,7 @@ task Log {
355
565
  }
356
566
 
357
567
  task applyJavaPatches(type: Copy) {
358
- def patchDirectory = file("${projectDir}/rnVersionPatch/${rnMinorVersion}")
568
+ def patchDirectory = file("${projectDir}/rnVersionPatch/${REACT_NATIVE_MINOR_VERSION}")
359
569
  if (patchDirectory.exists()) {
360
570
  from ("${patchDirectory}") {
361
571
  include "**/*.java"
@@ -369,16 +579,70 @@ task createNativeDepsDirectories(dependsOn: applyJavaPatches) {
369
579
  thirdPartyNdkDir.mkdirs()
370
580
  }
371
581
 
372
- task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) {
582
+ def resolveTaskFactory(String taskName, String artifactLocalName, File reactNativeAndroidDownloadDir, File reanimatedDownloadDir) {
583
+ return tasks.create(name: taskName, dependsOn: createNativeDepsDirectories, type: Copy) {
584
+ from reactNativeAndroidDownloadDir
585
+ include artifactLocalName
586
+ into reanimatedDownloadDir
587
+
588
+ onlyIf {
589
+ // First we check whether the file is already in our download directory
590
+ if (file("$reanimatedDownloadDir/$artifactLocalName").isFile()) {
591
+ return false
592
+ }
593
+
594
+ // If it is not the case we check whether it was downloaded by ReactAndroid project
595
+ if (file("$reactNativeAndroidDownloadDir/$artifactLocalName").isFile()) {
596
+ return true
597
+ }
598
+
599
+ return false
600
+ }
601
+ }
602
+ }
603
+
604
+ Task resolveBoost = resolveTaskFactory("resolveBoost", "boost_${BOOST_VERSION}.tar.gz", reactNativeAndroidDownloadDir, downloadsDir)
605
+ Task resolveDoubleConversion = resolveTaskFactory(
606
+ "resolveDoubleConversion",
607
+ "double-conversion-${DOUBLE_CONVERSION_VERSION}.tar.gz",
608
+ reactNativeAndroidDownloadDir,
609
+ downloadsDir
610
+ )
611
+ Task resolveFolly = resolveTaskFactory("resolveFolly", "folly-${FOLLY_VERSION}.tar.gz", reactNativeAndroidDownloadDir, downloadsDir)
612
+ Task resolveGlog = resolveTaskFactory("resolveGlog", "glog-${GLOG_VERSION}.tar.gz", reactNativeAndroidDownloadDir, downloadsDir)
613
+
614
+ if (isNewArchitectureEnabled()) {
615
+ def reactNativeAndroidProject = findProject(":ReactAndroid")
616
+ if (reactNativeAndroidProject != null) {
617
+ reactNativeAndroidProject.afterEvaluate {
618
+ def resolveTasks = [resolveBoost, resolveGlog, resolveDoubleConversion, resolveFolly]
619
+ resolveTasks.forEach({ task ->
620
+ String reactAndroidDownloadTaskName = "download" + task.name.replace("resolve", "")
621
+ def reactAndroidDownloadTask = reactNativeAndroidProject.getTasks().findByName(reactAndroidDownloadTaskName)
622
+ if (reactAndroidDownloadTask != null) {
623
+ task.dependsOn(reactAndroidDownloadTask)
624
+ } else {
625
+ logger.warn("[Reanimated] Failed to find task named `$reactAndroidDownloadTaskName` in `:ReactAndroid` project." +
626
+ " Explicit dependency between it and $task.name task can not be set.")
627
+ }
628
+ })
629
+ }
630
+ } else {
631
+ throw new GradleScriptException("[Reanimated] Failed to find `:ReactAndroid` project. Explicit dependency between download tasks can not be set.")
632
+ }
633
+ }
634
+
635
+ task downloadBoost(dependsOn: resolveBoost, type: Download) {
373
636
  def transformedVersion = BOOST_VERSION.replace("_", ".")
637
+ def artifactLocalName = "boost_${BOOST_VERSION}.tar.gz"
374
638
  def srcUrl = "https://boostorg.jfrog.io/artifactory/main/release/${transformedVersion}/source/boost_${BOOST_VERSION}.tar.gz"
375
- if (rnMinorVersion < 69) {
639
+ if (REACT_NATIVE_MINOR_VERSION < 69) {
376
640
  srcUrl = "https://github.com/react-native-community/boost-for-react-native/releases/download/v${transformedVersion}-0/boost_${BOOST_VERSION}.tar.gz"
377
641
  }
378
642
  src(srcUrl)
379
643
  onlyIfNewer(true)
380
644
  overwrite(false)
381
- dest(new File(downloadsDir, "boost_${BOOST_VERSION}.tar.gz"))
645
+ dest(new File(downloadsDir, artifactLocalName))
382
646
  }
383
647
 
384
648
  task prepareBoost(dependsOn: boostPath ? [] : [downloadBoost], type: Copy) {
@@ -392,7 +656,7 @@ task prepareBoost(dependsOn: boostPath ? [] : [downloadBoost], type: Copy) {
392
656
  }
393
657
  }
394
658
 
395
- task downloadDoubleConversion(dependsOn: createNativeDepsDirectories, type: Download) {
659
+ task downloadDoubleConversion(dependsOn: resolveDoubleConversion, type: Download) {
396
660
  src("https://github.com/google/double-conversion/archive/v${DOUBLE_CONVERSION_VERSION}.tar.gz")
397
661
  onlyIfNewer(true)
398
662
  overwrite(false)
@@ -408,7 +672,7 @@ task prepareDoubleConversion(dependsOn: dependenciesPath ? [] : [downloadDoubleC
408
672
  into("$thirdPartyNdkDir/double-conversion")
409
673
  }
410
674
 
411
- task downloadFolly(dependsOn: createNativeDepsDirectories, type: Download) {
675
+ task downloadFolly(dependsOn: resolveFolly, type: Download) {
412
676
  src("https://github.com/facebook/folly/archive/v${FOLLY_VERSION}.tar.gz")
413
677
  onlyIfNewer(true)
414
678
  overwrite(false)
@@ -427,7 +691,7 @@ task prepareFolly(dependsOn: dependenciesPath ? [] : [downloadFolly], type: Copy
427
691
  into("$thirdPartyNdkDir/folly")
428
692
  }
429
693
 
430
- task downloadGlog(dependsOn: createNativeDepsDirectories, type: Download) {
694
+ task downloadGlog(dependsOn: resolveGlog, type: Download) {
431
695
  src("https://github.com/google/glog/archive/v${GLOG_VERSION}.tar.gz")
432
696
  onlyIfNewer(true)
433
697
  overwrite(false)
@@ -483,12 +747,10 @@ as well as unzip Hermes AAR in order to obtain `libhermes.so` shared library.
483
747
  For more details, see https://reactnative.dev/architecture/bundled-hermes
484
748
  or https://github.com/reactwg/react-native-new-architecture/discussions/4
485
749
  */
486
- if (rnMinorVersion >= 69 && !isNewArchitectureEnabled()) {
750
+ if (REACT_NATIVE_MINOR_VERSION >= 69 && !isNewArchitectureEnabled()) {
487
751
  // copied from `react-native/ReactAndroid/hermes-engine/build.gradle`
488
752
 
489
- def reactNativeRootDir = resolveReactNativeDirectory()
490
- def customDownloadDir = System.getenv("REACT_NATIVE_DOWNLOADS_DIR")
491
- def downloadDir = customDownloadDir ? new File(customDownloadDir) : new File(reactNativeRootDir, "sdks/download")
753
+ def downloadDir = customDownloadsDir ? new File(customDownloadsDir) : new File(reactNativeRootDir, "sdks/download")
492
754
 
493
755
  // By default we are going to download and unzip hermes inside the /sdks/hermes folder
494
756
  // but you can provide an override for where the hermes source code is located.
@@ -513,7 +775,7 @@ if (rnMinorVersion >= 69 && !isNewArchitectureEnabled()) {
513
775
  // We flatten the unzip as the tarball contains a `facebook-hermes-<SHA>`
514
776
  // folder at the top level.
515
777
  if (file.relativePath.segments.size() > 1) {
516
- file.relativePath = new org.gradle.api.file.RelativePath(!file.isDirectory(), file.relativePath.segments.drop(1))
778
+ file.relativePath = new RelativePath(!file.isDirectory(), file.relativePath.segments.drop(1))
517
779
  }
518
780
  }
519
781
  }
@@ -522,13 +784,18 @@ if (rnMinorVersion >= 69 && !isNewArchitectureEnabled()) {
522
784
  }
523
785
 
524
786
  task prepareHermes() {
525
- if (rnMinorVersion >= 69) {
787
+ if (REACT_NATIVE_MINOR_VERSION >= 69) {
526
788
  if (!isNewArchitectureEnabled()) {
527
789
  dependsOn(unzipHermes)
528
790
  }
529
791
 
530
792
  doLast {
531
- def hermesAAR = file("$reactNative/android/com/facebook/react/hermes-engine/$reactNativeVersion/hermes-engine-$reactNativeVersion-${resolveBuildType()}.aar") // e.g. hermes-engine-0.70.0-rc.1-debug.aar
793
+ // e.g. hermes-engine-0.70.0-rc.1-debug.aar
794
+ def hermesAAR = file(
795
+ "$reactNativeRootDir/android/com/facebook/react/hermes-engine/" +
796
+ "${REACT_NATIVE_VERSION}/hermes-engine-${REACT_NATIVE_VERSION}-" +
797
+ "${resolveBuildType()}.aar"
798
+ )
532
799
  if (!hermesAAR.exists()) {
533
800
  throw new GradleScriptException("Could not find hermes-engine AAR", null)
534
801
  }
@@ -537,7 +804,7 @@ task prepareHermes() {
537
804
 
538
805
  copy {
539
806
  from soFiles
540
- from "$reactNative/ReactAndroid/src/main/jni/first-party/hermes/Android.mk"
807
+ from "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/hermes/Android.mk"
541
808
  into "$thirdPartyNdkDir/hermes"
542
809
  }
543
810
  }
@@ -548,16 +815,16 @@ task prepareHermes() {
548
815
  throw new GradleScriptException("Could not find the hermes-engine npm package", null)
549
816
  }
550
817
 
551
- def hermesAAR = file("$hermesPackagePath/android/hermes-debug.aar")
818
+ def hermesAAR = file("$hermesPackagePath/android/hermes-${resolveBuildType()}.aar") // e.g. hermes-debug.aar
552
819
  if (!hermesAAR.exists()) {
553
- throw new GradleScriptException("The hermes-engine npm package is missing \"android/hermes-debug.aar\"", null)
820
+ throw new GradleScriptException("The hermes-engine npm package is missing \"android/hermes-${resolveBuildType()}.aar\"", null)
554
821
  }
555
822
 
556
823
  def soFiles = zipTree(hermesAAR).matching({ it.include "**/*.so" })
557
824
 
558
825
  copy {
559
826
  from soFiles
560
- from "$reactNative/ReactAndroid/src/main/jni/first-party/hermes/Android.mk"
827
+ from "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/hermes/Android.mk"
561
828
  into "$thirdPartyNdkDir/hermes"
562
829
  }
563
830
  }
@@ -584,7 +851,7 @@ task prepareJSC {
584
851
  copy {
585
852
  from(soFiles)
586
853
  from(headerFiles)
587
- from("$reactNative/ReactAndroid/src/main/jni/third-party/jsc/Android.mk")
854
+ from("$reactNativeRootDir/ReactAndroid/src/main/jni/third-party/jsc/Android.mk")
588
855
 
589
856
  filesMatching("**/*.h", { it.path = "JavaScriptCore/${it.name}" })
590
857
 
@@ -601,7 +868,7 @@ task extractAARHeaders {
601
868
  def packageName = file.name.tokenize('-')[0]
602
869
  copy {
603
870
  from zipTree(file)
604
- into "$reactNative/ReactAndroid/src/main/jni/first-party/$packageName/headers"
871
+ into "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/$packageName/headers"
605
872
  include "**/*.h"
606
873
  }
607
874
  }
@@ -615,7 +882,7 @@ task extractSOFiles {
615
882
  def packageName = file.name.tokenize('-')[0]
616
883
  copy {
617
884
  from zipTree(file)
618
- into "$reactNative/ReactAndroid/src/main/jni/first-party/$packageName/"
885
+ into "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/$packageName/"
619
886
  include "jni/**/*.so"
620
887
  }
621
888
  }
@@ -625,7 +892,7 @@ task extractSOFiles {
625
892
  task packageNdkLibs(type: Copy) {
626
893
  from("$buildDir/reanimated-ndk/all")
627
894
  include("**/libreanimated.so")
628
- if(REACT_VERSION < 64) {
895
+ if(REACT_NATIVE_MINOR_VERSION < 64) {
629
896
  include("**/libturbomodulejsijni.so")
630
897
  }
631
898
  into("$projectDir/src/main/jniLibs")
@@ -636,11 +903,11 @@ repositories {
636
903
  mavenLocal()
637
904
  maven {
638
905
  // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
639
- url "$reactNative/android"
906
+ url "$reactNativeRootDir/android"
640
907
  }
641
908
  maven {
642
909
  // Android JSC is installed from npm
643
- url "$reactNative/../jsc-android/dist"
910
+ url "$reactNativeRootDir/../jsc-android/dist"
644
911
  }
645
912
  google()
646
913
  }
@@ -656,31 +923,27 @@ dependencies {
656
923
  }
657
924
  implementation "com.facebook.react:react-native:+" // From node_modules
658
925
  implementation "androidx.transition:transition:1.1.0"
659
- if (rnMinorVersion > 66) {
660
- implementation "androidx.core:core:1.7.0"
661
- }
662
- else {
663
- implementation "androidx.core:core:1.6.0"
664
- }
926
+ implementation "androidx.core:core:1.6.0"
927
+
665
928
  extractHeaders("com.facebook.fbjni:fbjni:" + FBJNI_VERSION + ":headers")
666
929
  extractSO("com.facebook.fbjni:fbjni:" + FBJNI_VERSION)
667
930
 
668
- def jscAAR = fileTree("$reactNative/../jsc-android/dist/org/webkit/android-jsc").matching({ it.include "**/**/*.aar" }).singleFile
931
+ def jscAAR = fileTree("$reactNativeRootDir/../jsc-android/dist/org/webkit/android-jsc").matching({ it.include "**/**/*.aar" }).singleFile
669
932
  extractSO(files(jscAAR))
670
933
  }
671
934
 
672
935
  task unpackReactNativeAAR {
673
936
  def buildType = resolveBuildType()
674
937
  def rnAarMatcher = "**/react-native/**/*${buildType}.aar"
675
- if (rnMinorVersion < 69) {
938
+ if (REACT_NATIVE_MINOR_VERSION < 69) {
676
939
  rnAarMatcher = "**/**/*.aar"
677
940
  }
678
- def rnAAR = fileTree("$reactNative/android").matching({ it.include rnAarMatcher }).singleFile
941
+ def rnAAR = fileTree("$reactNativeRootDir/android").matching({ it.include rnAarMatcher }).singleFile
679
942
  def file = rnAAR.absoluteFile
680
943
  def packageName = file.name.tokenize('-')[0]
681
944
  copy {
682
945
  from zipTree(file)
683
- into "$reactNative/ReactAndroid/src/main/jni/first-party/$packageName/"
946
+ into "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/$packageName/"
684
947
  include "jni/**/*.so"
685
948
  }
686
949
  }
@@ -694,8 +957,14 @@ task downloadNdkBuildDependencies {
694
957
  dependsOn(downloadGlog)
695
958
  }
696
959
 
697
- task prepareThirdPartyNdkHeaders(dependsOn:[downloadNdkBuildDependencies, prepareBoost, prepareDoubleConversion, prepareFolly, prepareGlog, unpackReactNativeAAR]) {
698
- }
960
+ task prepareThirdPartyNdkHeaders(dependsOn:[
961
+ downloadNdkBuildDependencies,
962
+ prepareBoost,
963
+ prepareDoubleConversion,
964
+ prepareFolly,
965
+ prepareGlog,
966
+ unpackReactNativeAAR]
967
+ ) {}
699
968
 
700
969
  def nativeBuildDependsOn(dependsOnTask) {
701
970
  def buildTasks = tasks.findAll({ task ->
@@ -718,8 +987,8 @@ afterEvaluate {
718
987
  })
719
988
 
720
989
  if (JS_RUNTIME == "hermes") {
721
- extractAARHeaders.dependsOn(prepareHermes)
722
- extractSOFiles.dependsOn(prepareHermes)
990
+ extractAARHeaders.dependsOn(prepareHermes)
991
+ extractSOFiles.dependsOn(prepareHermes)
723
992
  } else if (JS_RUNTIME == "v8") {
724
993
  def buildTasks = tasks.findAll({ task ->
725
994
  !task.name.contains("Clean") && (task.name.contains("externalNative") || task.name.contains("CMake") || task.name.startsWith("generateJsonModel")) })
@@ -727,12 +996,17 @@ afterEvaluate {
727
996
  def buildType = task.name.endsWith('Debug') ? 'Debug' : 'Release'
728
997
  task.dependsOn(":react-native-v8:copy${buildType}JniLibsProjectOnly")
729
998
  }
999
+ } else if (JS_RUNTIME == "jsc") {
1000
+ extractAARHeaders.dependsOn(prepareJSC)
1001
+ extractSOFiles.dependsOn(prepareJSC)
1002
+ } else {
1003
+ throw GradleScriptException("Unknown JS runtime ${JS_RUNTIME}.")
730
1004
  }
731
1005
  }
732
1006
 
733
1007
  if (CLIENT_SIDE_BUILD) {
734
1008
  def aarDir = "${buildDir}/outputs"
735
- def aar = file("${aarDir}/android-debug.aar")
1009
+ aar = file("${aarDir}/android-${resolveBuildType()}.aar") // e.g. android-debug.aar
736
1010
  if (aar == null) {
737
1011
  throw GradleScriptException("AAR build failed. No AAR found in ${aarDir}.")
738
1012
  }