react-native-reanimated 2.10.0 → 2.12.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 (146) 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 +19 -75
  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 +422 -120
  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/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +1 -1
  80. package/android/{rnVersionPatch/62 → src/reactNativeVersionPatch/UIImplementation/64/com/swmansion/reanimated}/layoutReanimation/ReanimatedUIImplementation.java +0 -0
  81. package/android/src/{main/java → reactNativeVersionPatch/UIImplementation/latest}/com/swmansion/reanimated/layoutReanimation/ReanimatedUIImplementation.java +0 -0
  82. package/android/src/reactNativeVersionPatch/messageQueueThread/67/com/swmansion/reanimated/ReanimatedMessageQueueThread.java +12 -0
  83. package/android/src/reactNativeVersionPatch/messageQueueThread/latest/com/swmansion/reanimated/ReanimatedMessageQueueThread.java +12 -0
  84. package/android/{rnVersionPatch/62 → src/reactNativeVersionPatch/nativeHierarchyManager/62/com/swmansion/reanimated}/layoutReanimation/ReanimatedNativeHierarchyManager.java +0 -0
  85. package/android/src/{main/java → reactNativeVersionPatch/nativeHierarchyManager/latest}/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +0 -0
  86. package/ios/{REAModule.m → REAModule.mm} +29 -0
  87. package/ios/keyboardObserver/REAKeyboardEventObserver.m +1 -1
  88. package/ios/native/NativeProxy.mm +4 -2
  89. package/ios/native/REAInitializer.h +2 -2
  90. package/ios/native/REAInitializer.mm +2 -2
  91. package/ios/native/UIResponder+Reanimated.mm +1 -1
  92. package/lib/createAnimatedComponent.js +3 -4
  93. package/lib/index.web.js +2 -0
  94. package/lib/reanimated2/NativeMethods.js +79 -30
  95. package/lib/reanimated2/frameCallback/FrameCallbackRegistryJS.js +4 -4
  96. package/lib/reanimated2/frameCallback/FrameCallbackRegistryUI.js +47 -18
  97. package/lib/reanimated2/globals.d.ts +38 -12
  98. package/lib/reanimated2/hook/index.js +1 -0
  99. package/lib/reanimated2/hook/useScrollViewOffset.js +27 -0
  100. package/lib/reanimated2/utils.js +10 -3
  101. package/lib/types/index.web.d.ts +1 -0
  102. package/lib/types/reanimated2/NativeMethods.d.ts +4 -11
  103. package/lib/types/reanimated2/commonTypes.d.ts +8 -0
  104. package/lib/types/reanimated2/frameCallback/FrameCallbackRegistryJS.d.ts +4 -3
  105. package/lib/types/reanimated2/frameCallback/FrameCallbackRegistryUI.d.ts +17 -7
  106. package/lib/types/reanimated2/hook/index.d.ts +1 -0
  107. package/lib/types/reanimated2/hook/useAnimatedScrollHandler.d.ts +1 -2
  108. package/lib/types/reanimated2/hook/useFrameCallback.d.ts +2 -1
  109. package/lib/types/reanimated2/hook/useScrollViewOffset.d.ts +4 -0
  110. package/lib/types/reanimated2/utils.d.ts +5 -1
  111. package/package.json +8 -6
  112. package/plugin.js +1 -1
  113. package/react-native-reanimated.d.ts +13 -9
  114. package/scripts/reanimated_utils.rb +77 -0
  115. package/src/createAnimatedComponent.tsx +2 -3
  116. package/src/index.web.ts +2 -0
  117. package/src/reanimated2/NativeMethods.ts +104 -48
  118. package/src/reanimated2/commonTypes.ts +9 -0
  119. package/src/reanimated2/frameCallback/FrameCallbackRegistryJS.ts +6 -9
  120. package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +78 -27
  121. package/src/reanimated2/globals.d.ts +38 -12
  122. package/src/reanimated2/hook/index.ts +1 -0
  123. package/src/reanimated2/hook/useAnimatedScrollHandler.ts +3 -1
  124. package/src/reanimated2/hook/useFrameCallback.ts +2 -1
  125. package/src/reanimated2/hook/useScrollViewOffset.ts +37 -0
  126. package/src/reanimated2/utils.ts +12 -5
  127. package/android/.gradle/7.2/dependencies-accessors/dependencies-accessors.lock +0 -0
  128. package/android/.gradle/7.2/executionHistory/executionHistory.bin +0 -0
  129. package/android/.gradle/7.2/executionHistory/executionHistory.lock +0 -0
  130. package/android/.gradle/7.2/fileHashes/fileHashes.bin +0 -0
  131. package/android/.gradle/7.2/fileHashes/fileHashes.lock +0 -0
  132. package/android/.gradle/checksums/checksums.lock +0 -0
  133. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  134. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  135. package/android/rnVersionPatch/63/layoutReanimation/ReanimatedUIImplementation.java +0 -68
  136. package/android/rnVersionPatch/64/layoutReanimation/ReanimatedUIImplementation.java +0 -68
  137. package/android/rnVersionPatch/65/.gitkeep +0 -0
  138. package/android/rnVersionPatch/66/.gitkeep +0 -0
  139. package/android/rnVersionPatch/67/.gitkeep +0 -0
  140. package/android/rnVersionPatch/68/.gitkeep +0 -0
  141. package/android/rnVersionPatch/69/.gitkeep +0 -0
  142. package/android/rnVersionPatch/70/.gitkeep +0 -0
  143. package/android/rnVersionPatch/backup/.gitkeep +0 -0
  144. package/android/src/main/java/com/swmansion/reanimated/AndroidErrorHandler.java +0 -8
  145. package/lib/reanimated2/__mocks__/NativeReanimated.native.js +0 -20
  146. package/lib/types/reanimated2/__mocks__/NativeReanimated.native.d.ts +0 -13
@@ -1,11 +1,7 @@
1
1
  import com.android.Version
2
-
3
- import java.nio.file.Files
4
- import java.nio.file.Paths
5
- import java.nio.file.Path
6
2
  import org.apache.tools.ant.filters.ReplaceTokens
7
3
  import groovy.json.JsonSlurper
8
- import java.util.stream.Stream
4
+ import java.nio.file.Paths
9
5
 
10
6
  /**
11
7
  * Finds the path of the installed npm package with the given name using Node's
@@ -46,14 +42,19 @@ 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
+ if (findProject(':app') == null) {
47
+ return fallback
48
+ }
49
+ def appProject = project(':app')
50
+ appProject?.ext?.has(prop) ? appProject.ext.get(prop) : fallback
51
+ }
52
+
49
53
  def resolveBuildType() {
50
- def buildType = "debug"
51
- tasks.all({ task ->
52
- if (task.name == "buildCMakeRelease") {
53
- buildType = "release"
54
- }
55
- })
56
- return buildType
54
+ Gradle gradle = getGradle()
55
+ String tskReqStr = gradle.getStartParameter().getTaskRequests()['args'].toString()
56
+
57
+ return tskReqStr.contains('Release') ? 'release' : 'debug'
57
58
  }
58
59
 
59
60
  def resolveClientSideBuild() {
@@ -75,7 +76,7 @@ def resolveClientSideBuild() {
75
76
 
76
77
  def isDeveloperMode() {
77
78
  // developer mode, to run Example app
78
- return file("$projectDir/../node_modules/react-native/package.json").exists()
79
+ return safeAppExtGet("isReanimatedExampleApp", false) || System.getenv("REANIMATED_PACKAGE_BUILD") == "1"
79
80
  }
80
81
 
81
82
  def isNewArchitectureEnabled() {
@@ -87,10 +88,32 @@ def isNewArchitectureEnabled() {
87
88
  }
88
89
 
89
90
  def resolveReactNativeDirectory() {
91
+ def reactNativeLocation = safeAppExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
92
+ if (reactNativeLocation != null) {
93
+ return file(reactNativeLocation)
94
+ }
95
+
90
96
  if (isDeveloperMode()) {
91
97
  return file("$projectDir/../${getPlaygroundAppName()}/node_modules/react-native")
92
98
  }
93
- return file("$projectDir/../../react-native")
99
+
100
+ // monorepo workaround
101
+ // react-native can be hoisted or in project's own node_modules
102
+ def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native")
103
+ if (reactNativeFromProjectNodeModules.exists()) {
104
+ return reactNativeFromProjectNodeModules
105
+ }
106
+
107
+ def reactNativeFromNodeModulesWithReanimated = file("${projectDir}/../../react-native")
108
+ if (reactNativeFromNodeModulesWithReanimated.exists()) {
109
+ return reactNativeFromNodeModulesWithReanimated
110
+ }
111
+
112
+ throw new Exception(
113
+ "[Reanimated] Unable to resolve react-native location in " +
114
+ "node_modules. You should project extension property (in app/build.gradle) " +
115
+ "`REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
116
+ )
94
117
  }
95
118
 
96
119
  def getPlaygroundAppName() { // only for the development
@@ -109,66 +132,90 @@ def getPlaygroundAppName() { // only for the development
109
132
  return playgroundAppName
110
133
  }
111
134
 
112
- boolean CLIENT_SIDE_BUILD = resolveClientSideBuild()
113
- if (CLIENT_SIDE_BUILD) {
114
- configurations.maybeCreate("default")
135
+ def shouldAssertNoMultipleInstances() {
136
+ if (rootProject.hasProperty("disableMultipleInstancesCheck")) {
137
+ return rootProject.property("disableMultipleInstancesCheck") != "true"
138
+ } else {
139
+ return true
140
+ }
141
+ }
115
142
 
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()
143
+ def findReanimatedInstancesForPath(String path) {
144
+ return fileTree(path) {
145
+ include "**/react-native-reanimated/package.json"
146
+ exclude "**/.yarn/**"
147
+ exclude {{ file, attr -> attr.isSymbolicLink() }}
148
+ }.files
149
+ }
121
150
 
122
- String parsedLocation = ""
123
- def libInstancesCount = 0
124
- for (def path in paths) {
125
- parsedLocation += "- " + path.toString().replace("/package.json", "\n")
126
- libInstancesCount++
151
+ def checkNoMultipleInstances() {
152
+ // Assert there are no multiple installations of Reanimated
153
+ Set<File> files
154
+ if (projectDir.path.contains(rootDir.parent)) {
155
+ // standard app
156
+ files = findReanimatedInstancesForPath(rootDir.parent + "/node_modules")
157
+ } else {
158
+ // monorepo
159
+ files = findReanimatedInstancesForPath(rootDir.parent + "/node_modules")
160
+ files.addAll(
161
+ findReanimatedInstancesForPath(file(projectDir.parent).parent)
162
+ )
127
163
  }
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";
164
+ if (files.size() > 1) {
165
+ String parsedLocation = files.stream().map({
166
+ File file -> "- " + file.toString().replace("/package.json", "")
167
+ }).collect().join("\n")
168
+ String exceptionMessage = "\n[react-native-reanimated] Multiple versions of Reanimated " +
169
+ "were detected. Only one instance of react-native-reanimated can be installed in a " +
170
+ "project. You need to resolve the conflict manually. Check out the documentation: " +
171
+ "https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/" +
172
+ "troubleshooting#multiple-versions-of-reanimated-were-detected \n\nConflict " +
173
+ "between: \n" + parsedLocation + "\n";
130
174
  throw new Exception(exceptionMessage)
131
175
  }
132
176
  }
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
177
 
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"))
178
+ def getReanimatedVersion() {
179
+ def inputFile = file(projectDir.path + '/../package.json')
180
+ def json = new JsonSlurper().parseText(inputFile.text)
181
+ String reanimatedVersion = json.version
182
+ def (major, minor, patch) = reanimatedVersion.tokenize('.')
183
+ return major.toInteger()
144
184
  }
145
185
 
146
- def debugNativeLibraries = localProps.getProperty('NATIVE_DEBUG_ON', 'FALSE').toBoolean()
186
+ boolean CLIENT_SIDE_BUILD = resolveClientSideBuild()
187
+ if (CLIENT_SIDE_BUILD) {
188
+ configurations.maybeCreate("default")
189
+ }
190
+
191
+ def reactNativeRootDir = resolveReactNativeDirectory()
192
+
147
193
  def reactProperties = new Properties()
148
- file("$reactNative/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
194
+ file("$reactNativeRootDir/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
149
195
 
150
196
  def BOOST_VERSION = reactProperties.getProperty("BOOST_VERSION")
151
197
  def DOUBLE_CONVERSION_VERSION = reactProperties.getProperty("DOUBLE_CONVERSION_VERSION")
152
198
  def FOLLY_VERSION = reactProperties.getProperty("FOLLY_VERSION")
153
199
  def GLOG_VERSION = reactProperties.getProperty("GLOG_VERSION")
154
- def REACT_VERSION = reactProperties.getProperty("VERSION_NAME").split("\\.")[1].toInteger()
200
+ def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
201
+ def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
155
202
  def FBJNI_VERSION = "0.3.0"
203
+ def REANIMATED_PACKAGE_BUILD = System.getenv("REANIMATED_PACKAGE_BUILD")
204
+ def REANIMATED_MAJOR_VERSION = getReanimatedVersion()
156
205
 
157
206
  // We download various C++ open-source dependencies into downloads.
158
207
  // We then copy both the downloaded code and our custom makefiles and headers into third-party-ndk.
159
208
  // After that we build native code from src/main/jni with module path pointing at third-party-ndk.
160
209
 
161
- def downloadsDir = new File("$buildDir/downloads")
210
+ def customDownloadsDir = System.getenv("REACT_NATIVE_DOWNLOADS_DIR")
211
+ def downloadsDir = customDownloadsDir ? new File(customDownloadsDir) : new File("$buildDir/downloads")
162
212
  def thirdPartyNdkDir = new File("$buildDir/third-party-ndk")
163
213
 
164
- def reactNativeThirdParty = new File("$reactNative/ReactAndroid/src/main/jni/third-party")
214
+ def reactNativeThirdParty = new File("$reactNativeRootDir/ReactAndroid/src/main/jni/third-party")
215
+ def reactNativeAndroidDownloadDir = new File("$reactNativeRootDir/ReactAndroid/build/downloads")
165
216
 
166
217
  def _stackProtectorFlag = true
167
218
 
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
219
  def JS_RUNTIME = {
173
220
  // Returns the js runtime explicitly requested in the environment variable
174
221
  if (System.getenv("JS_RUNTIME")) {
@@ -187,15 +234,15 @@ def JS_RUNTIME = {
187
234
 
188
235
  def jsRuntimeDir = {
189
236
  if (JS_RUNTIME == "hermes") {
190
- if (rnMinorVersion >= 69) {
191
- return Paths.get(CMAKE_NODE_MODULES_DIR, "react-native", "sdks", "hermes")
237
+ if (REACT_NATIVE_MINOR_VERSION >= 69) {
238
+ return Paths.get(reactNativeRootDir.path, "sdks", "hermes")
192
239
  } else {
193
- return Paths.get(CMAKE_NODE_MODULES_DIR, "hermes-engine")
240
+ return Paths.get(reactNativeRootDir.path, "..", "hermes-engine")
194
241
  }
195
242
  } else if (JS_RUNTIME == "v8") {
196
243
  return findProject(":react-native-v8").getProjectDir().getParent()
197
244
  } else {
198
- return Paths.get(CMAKE_NODE_MODULES_DIR, "react-native", "ReactCommon", "jsi")
245
+ return Paths.get(reactNativeRootDir.path, "ReactCommon", "jsi")
199
246
  }
200
247
  }.call()
201
248
 
@@ -204,6 +251,145 @@ def reactNativeArchitectures() {
204
251
  return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
205
252
  }
206
253
 
254
+ def detectAAR(Integer rnMinorVersion, String engine) { // Reanimated2 only
255
+ def rnMinorVersionCopy = rnMinorVersion
256
+ def aar = file("react-native-reanimated-${rnMinorVersionCopy}-${engine}.aar")
257
+
258
+ if (aar.exists()) {
259
+ println "AAR for react-native-reanimated has been found\n$aar"
260
+ return aar
261
+ } else {
262
+ while (!aar.exists() && rnMinorVersionCopy >= 63) {
263
+ rnMinorVersionCopy -= 1
264
+ aar = file("react-native-reanimated-${rnMinorVersionCopy}-${engine}.aar")
265
+ }
266
+
267
+ if (rnMinorVersionCopy < 63) {
268
+ println "No AAR for react-native-reanimated found. Attempting to build from source."
269
+ } else { // aar exists, but was build for lower react-native version
270
+ println "\n\n\n"
271
+ println "****************************************************************************************"
272
+ println "\n\n\n"
273
+ println "WARNING reanimated - no version-specific reanimated AAR for react-native version $minor found."
274
+ println "Falling back to AAR for react-native version $rnMinorVersionCopy."
275
+ println "The react-native JSI interface is not ABI-safe yet, this may result in crashes."
276
+ println "Please post a pull request to implement support for react-native version $minor to the reanimated repo."
277
+ println "Thanks!"
278
+ println "\n\n\n"
279
+ println "****************************************************************************************"
280
+
281
+ return aar
282
+ }
283
+ }
284
+ return null
285
+ }
286
+
287
+ def isUserDemandToBuildFromSource() { // Reanimated2 only
288
+ def buildFromSourceConf = false
289
+ rootProject.getSubprojects().forEach({project ->
290
+ if (project.plugins.hasPlugin("com.android.application")) {
291
+ if (
292
+ project.ext.has("reanimated")
293
+ && project.ext.reanimated.buildFromSource
294
+ ) {
295
+ buildFromSourceConf = true
296
+ }
297
+ }
298
+ })
299
+ return buildFromSourceConf
300
+ }
301
+
302
+ def shouldBuildFromSource(aar, jsRuntimeName) { // Reanimated2 only
303
+ if (jsRuntimeName == "v8") {
304
+ return true
305
+ }
306
+ else if (isDeveloperMode()) {
307
+ // Example app
308
+ return true
309
+ }
310
+ else if (isUserDemandToBuildFromSource()) {
311
+ // on user demand
312
+ return true
313
+ }
314
+ else if (aar != null) {
315
+ // when binary exist
316
+ return false
317
+ }
318
+ // when binary is not found
319
+ return true
320
+ }
321
+
322
+ def getTaskByPath(
323
+ project,
324
+ String appName,
325
+ String secondPart,
326
+ String flavorString,
327
+ String lastPart
328
+ ) { // Reanimated2 only
329
+ String pathName = "${appName}:${secondPart}${flavorString}${lastPart}"
330
+ Task task = project.getTasks().findByPath(pathName)
331
+ if (task != null) {
332
+ return task
333
+ }
334
+ pathName = "${appName}:${secondPart}${flavorString.capitalize()}${lastPart}"
335
+ return project.getTasks().findByPath(pathName)
336
+ }
337
+
338
+ def aar = detectAAR(REACT_NATIVE_MINOR_VERSION, JS_RUNTIME)
339
+ boolean BUILD_FROM_SOURCE = shouldBuildFromSource(aar, JS_RUNTIME)
340
+
341
+ if (!BUILD_FROM_SOURCE && !isNewArchitectureEnabled()) { // Reanimated2 only
342
+ if (REACT_NATIVE_MINOR_VERSION < 65) {
343
+ tasks.register("replaceSoTaskDebug", replaceSoTask)
344
+ tasks.register("replaceSoTaskRelease", replaceSoTask)
345
+ Task replaceSoTaskDebug = project.getTasks().findByPath(":react-native-reanimated:replaceSoTaskDebug")
346
+ Task replaceSoTaskRelease = project.getTasks().findByPath(":react-native-reanimated:replaceSoTaskRelease")
347
+
348
+ if (replaceSoTaskDebug != null && replaceSoTaskRelease != null) {
349
+ rootProject.getSubprojects().forEach({project ->
350
+ if (project.plugins.hasPlugin("com.android.application") && project.getProperties().get("android")) {
351
+ def projectProperties = project.getProperties()
352
+ def flavorString = getCurrentFlavor()
353
+ def reanimatedConf = projectProperties.get("reanimated")
354
+
355
+ if (
356
+ flavorString != "NOT-FOUND"
357
+ && (!reanimatedConf || (reanimatedConf && !reanimatedConf.get("enablePackagingOptions")))
358
+ ) {
359
+ replaceSoTask.appName = projectProperties.path
360
+ replaceSoTask.buildDir = projectProperties.buildDir
361
+ def appName = projectProperties.path
362
+
363
+ Task debugNativeLibsTask = getTaskByPath(project, appName, "merge", flavorString, "DebugNativeLibs")
364
+ Task debugDebugSymbolsTask = getTaskByPath(project, appName, "strip", flavorString, "DebugDebugSymbols")
365
+ Task releaseNativeLibsTask = getTaskByPath(project, appName, "merge", flavorString, "ReleaseNativeLibs")
366
+ Task releaseDebugSymbolsTask = getTaskByPath(project, appName, "strip", flavorString, "ReleaseDebugSymbols")
367
+ Task debugTask = getTaskByPath(project, appName, "package", flavorString, "Debug")
368
+ Task releaseTask = getTaskByPath(project, appName, "package", flavorString, "Release")
369
+
370
+ if (
371
+ debugNativeLibsTask != null && debugDebugSymbolsTask != null
372
+ && releaseNativeLibsTask != null && releaseDebugSymbolsTask != null
373
+ && debugTask != null && releaseTask != null
374
+ ) {
375
+ replaceSoTaskDebug.dependsOn(debugNativeLibsTask, debugDebugSymbolsTask)
376
+ debugTask.dependsOn(replaceSoTaskDebug)
377
+ replaceSoTaskRelease.dependsOn(releaseNativeLibsTask, releaseDebugSymbolsTask)
378
+ releaseTask.dependsOn(replaceSoTaskRelease)
379
+ }
380
+ }
381
+ }
382
+ })
383
+ }
384
+ }
385
+
386
+ artifacts.add("default", aar)
387
+ }
388
+
389
+ // end if already loaded aar
390
+ if (!BUILD_FROM_SOURCE) {
391
+ return
392
+ }
207
393
  // You need to have following folders in this directory:
208
394
  // - boost_1_63_0
209
395
  // - double-conversion-1.1.6
@@ -233,9 +419,9 @@ buildscript {
233
419
  }
234
420
  }
235
421
  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"
422
+ classpath "com.android.tools.build:gradle:7.3.0"
423
+ classpath "de.undercouch:gradle-download-task:5.0.1"
424
+ classpath "com.diffplug.spotless:spotless-plugin-gradle:6.11.0"
239
425
  }
240
426
  }
241
427
 
@@ -258,17 +444,16 @@ android {
258
444
  externalNativeBuild {
259
445
  cmake {
260
446
  arguments "-DANDROID_STL=c++_shared",
261
- "-DNATIVE_DEBUG=${debugNativeLibraries}",
262
- "-DREACT_NATIVE_TARGET_VERSION=${REACT_VERSION}",
447
+ "-DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}",
263
448
  "-DANDROID_TOOLCHAIN=clang",
264
449
  "-DBOOST_VERSION=${BOOST_VERSION}",
265
- "-DNODE_MODULES_DIR=${CMAKE_NODE_MODULES_DIR}",
450
+ "-DREACT_NATIVE_DIR=${reactNativeRootDir.path}",
266
451
  "-DJS_RUNTIME=${JS_RUNTIME}",
267
452
  "-DJS_RUNTIME_DIR=${jsRuntimeDir}",
268
453
  "-DCLIENT_SIDE_BUILD=${CLIENT_SIDE_BUILD}",
269
454
  "-DIS_NEW_ARCHITECTURE_ENABLED=${isNewArchitectureEnabled()}",
270
455
  "-DPLAYGROUND_APP_NAME=${getPlaygroundAppName()}",
271
- "-DRNVERSION=${rnMinorVersion}"
456
+ "-DREANIMATED_PACKAGE_BUILD=${REANIMATED_PACKAGE_BUILD}"
272
457
  abiFilters (*reactNativeArchitectures())
273
458
  _stackProtectorFlag ? (cppFlags("-fstack-protector-all")) : null
274
459
  }
@@ -276,21 +461,41 @@ android {
276
461
 
277
462
  buildConfigField("boolean", "IS_INTERNAL_BUILD", "false")
278
463
  buildConfigField("int", "EXOPACKAGE_FLAGS", "0")
279
- buildConfigField("int", "REACT_NATIVE_VERSION", rnMinorVersion.toString())
464
+ buildConfigField("int", "REACT_NATIVE_MINOR_VERSION", REACT_NATIVE_MINOR_VERSION.toString())
280
465
  }
281
466
  externalNativeBuild {
282
467
  cmake {
283
468
  path "CMakeLists.txt"
284
- version "3.18.1"
469
+ }
470
+ }
471
+ buildTypes {
472
+ debug {
473
+ externalNativeBuild {
474
+ cmake {
475
+ if (JS_RUNTIME == "hermes") {
476
+ arguments "-DHERMES_ENABLE_DEBUGGER=1"
477
+ } else {
478
+ arguments "-DHERMES_ENABLE_DEBUGGER=0"
479
+ }
480
+ }
481
+ }
482
+ }
483
+ release {
484
+ externalNativeBuild {
485
+ cmake {
486
+ arguments "-DHERMES_ENABLE_DEBUGGER=0"
487
+ }
488
+ }
285
489
  }
286
490
  }
287
491
  lintOptions {
288
492
  abortOnError false
289
493
  }
290
494
  packagingOptions {
291
- println "Native libs debug enabled: ${debugNativeLibraries}"
292
- doNotStrip debugNativeLibraries ? "**/**/*.so" : ''
495
+ doNotStrip resolveBuildType() == 'debug' ? "**/**/*.so" : ''
293
496
  excludes = [
497
+ "META-INF",
498
+ "META-INF/**",
294
499
  "**/libc++_shared.so",
295
500
  "**/libfbjni.so",
296
501
  "**/libjsi.so",
@@ -298,6 +503,7 @@ android {
298
503
  "**/libfolly_runtime.so",
299
504
  "**/libglog.so",
300
505
  "**/libhermes.so",
506
+ "**/libhermes-executor-debug.so",
301
507
  "**/libreactnativejni.so",
302
508
  "**/libjscexecutor.so",
303
509
  "**/libv8executor.so",
@@ -326,18 +532,59 @@ android {
326
532
  sourceSets.main {
327
533
  java {
328
534
  if (isNewArchitectureEnabled()) {
329
- srcDirs += [
330
- "src/fabric/java",
331
- ]
535
+ srcDirs += "src/fabric/java"
332
536
  } else {
333
- srcDirs += [
334
- "src/paper/java",
335
- ]
537
+ srcDirs += "src/paper/java"
538
+ }
539
+
540
+ // messageQueueThread
541
+ if (REANIMATED_MAJOR_VERSION > 2) {
542
+ if (REACT_NATIVE_MINOR_VERSION <= 67) {
543
+ srcDirs += "src/reactNativeVersionPatch/messageQueueThread/67"
544
+ } else {
545
+ srcDirs += "src/reactNativeVersionPatch/messageQueueThread/latest"
546
+ }
547
+ }
548
+
549
+ // UIImplementation
550
+ if (REACT_NATIVE_MINOR_VERSION <= 64) {
551
+ srcDirs += "src/reactNativeVersionPatch/UIImplementation/64"
552
+ } else {
553
+ srcDirs += "src/reactNativeVersionPatch/UIImplementation/latest"
554
+ }
555
+
556
+ // nativeHierarchyManager
557
+ if (REACT_NATIVE_MINOR_VERSION <= 62) {
558
+ srcDirs += "src/reactNativeVersionPatch/nativeHierarchyManager/62"
559
+ } else {
560
+ srcDirs += "src/reactNativeVersionPatch/nativeHierarchyManager/latest"
336
561
  }
337
562
  }
338
563
  }
339
564
  }
340
565
 
566
+ def assertNoMultipleInstances = task assertNoMultipleInstancesTask {
567
+ onlyIf { shouldAssertNoMultipleInstances() && CLIENT_SIDE_BUILD }
568
+ doFirst {
569
+ checkNoMultipleInstances()
570
+ }
571
+ }
572
+
573
+ def assertNoReanimated2WithNewArchitecture = task assertNoReanimated2WithNewArchitectureTask {
574
+ onlyIf { isNewArchitectureEnabled() && REANIMATED_MAJOR_VERSION == 2 }
575
+ doFirst {
576
+ throw new Exception(
577
+ "\n[react-native-reanimated] Reanimated 2.x does not support Fabric. " +
578
+ "Please upgrade to 3.x to use Reanimated with the New Architecture. " +
579
+ "For details, see https://blog.swmansion.com/announcing-reanimated-3-16167428c5f7"
580
+ )
581
+ }
582
+ }
583
+
584
+ tasks.preBuild {
585
+ dependsOn assertNoMultipleInstances, assertNoReanimated2WithNewArchitecture
586
+ }
587
+
341
588
  task cleanCmakeCache() {
342
589
  tasks.getByName("clean").dependsOn(cleanCmakeCache)
343
590
  doFirst {
@@ -350,35 +597,75 @@ task printVersions {
350
597
  println "Gradle: ${project.gradle.gradleVersion}"
351
598
  }
352
599
 
353
- task Log {
354
- println("building Reanimated2")
600
+ task createNativeDepsDirectories() {
601
+ downloadsDir.mkdirs()
602
+ thirdPartyNdkDir.mkdirs()
355
603
  }
356
604
 
357
- task applyJavaPatches(type: Copy) {
358
- def patchDirectory = file("${projectDir}/rnVersionPatch/${rnMinorVersion}")
359
- if (patchDirectory.exists()) {
360
- from ("${patchDirectory}") {
361
- include "**/*.java"
605
+ def resolveTaskFactory(String taskName, String artifactLocalName, File reactNativeAndroidDownloadDir, File reanimatedDownloadDir) {
606
+ return tasks.create(name: taskName, dependsOn: createNativeDepsDirectories, type: Copy) {
607
+ from reactNativeAndroidDownloadDir
608
+ include artifactLocalName
609
+ into reanimatedDownloadDir
610
+
611
+ onlyIf {
612
+ // First we check whether the file is already in our download directory
613
+ if (file("$reanimatedDownloadDir/$artifactLocalName").isFile()) {
614
+ return false
615
+ }
616
+
617
+ // If it is not the case we check whether it was downloaded by ReactAndroid project
618
+ if (file("$reactNativeAndroidDownloadDir/$artifactLocalName").isFile()) {
619
+ return true
620
+ }
621
+
622
+ return false
362
623
  }
363
- into ("${projectDir}/src/main/java/com/swmansion/reanimated")
364
624
  }
365
625
  }
366
626
 
367
- task createNativeDepsDirectories(dependsOn: applyJavaPatches) {
368
- downloadsDir.mkdirs()
369
- thirdPartyNdkDir.mkdirs()
627
+ Task resolveBoost = resolveTaskFactory("resolveBoost", "boost_${BOOST_VERSION}.tar.gz", reactNativeAndroidDownloadDir, downloadsDir)
628
+ Task resolveDoubleConversion = resolveTaskFactory(
629
+ "resolveDoubleConversion",
630
+ "double-conversion-${DOUBLE_CONVERSION_VERSION}.tar.gz",
631
+ reactNativeAndroidDownloadDir,
632
+ downloadsDir
633
+ )
634
+ Task resolveFolly = resolveTaskFactory("resolveFolly", "folly-${FOLLY_VERSION}.tar.gz", reactNativeAndroidDownloadDir, downloadsDir)
635
+ Task resolveGlog = resolveTaskFactory("resolveGlog", "glog-${GLOG_VERSION}.tar.gz", reactNativeAndroidDownloadDir, downloadsDir)
636
+
637
+ if (isNewArchitectureEnabled()) {
638
+ def reactNativeAndroidProject = findProject(":ReactAndroid")
639
+ if (reactNativeAndroidProject != null) {
640
+ reactNativeAndroidProject.afterEvaluate {
641
+ def resolveTasks = [resolveBoost, resolveGlog, resolveDoubleConversion, resolveFolly]
642
+ resolveTasks.forEach({ task ->
643
+ String reactAndroidDownloadTaskName = "download" + task.name.replace("resolve", "")
644
+ def reactAndroidDownloadTask = reactNativeAndroidProject.getTasks().findByName(reactAndroidDownloadTaskName)
645
+ if (reactAndroidDownloadTask != null) {
646
+ task.dependsOn(reactAndroidDownloadTask)
647
+ } else {
648
+ logger.warn("[Reanimated] Failed to find task named `$reactAndroidDownloadTaskName` in `:ReactAndroid` project." +
649
+ " Explicit dependency between it and $task.name task can not be set.")
650
+ }
651
+ })
652
+ }
653
+ } else {
654
+ throw new GradleScriptException("[Reanimated] Failed to find `:ReactAndroid` project. Explicit dependency between download tasks can not be set.")
655
+ }
370
656
  }
371
657
 
372
- task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) {
658
+ task downloadBoost(dependsOn: resolveBoost, type: Download) {
373
659
  def transformedVersion = BOOST_VERSION.replace("_", ".")
660
+ def artifactLocalName = "boost_${BOOST_VERSION}.tar.gz"
374
661
  def srcUrl = "https://boostorg.jfrog.io/artifactory/main/release/${transformedVersion}/source/boost_${BOOST_VERSION}.tar.gz"
375
- if (rnMinorVersion < 69) {
662
+ if (REACT_NATIVE_MINOR_VERSION < 69) {
376
663
  srcUrl = "https://github.com/react-native-community/boost-for-react-native/releases/download/v${transformedVersion}-0/boost_${BOOST_VERSION}.tar.gz"
377
664
  }
378
665
  src(srcUrl)
379
666
  onlyIfNewer(true)
380
667
  overwrite(false)
381
- dest(new File(downloadsDir, "boost_${BOOST_VERSION}.tar.gz"))
668
+ dest(new File(downloadsDir, artifactLocalName))
382
669
  }
383
670
 
384
671
  task prepareBoost(dependsOn: boostPath ? [] : [downloadBoost], type: Copy) {
@@ -392,7 +679,7 @@ task prepareBoost(dependsOn: boostPath ? [] : [downloadBoost], type: Copy) {
392
679
  }
393
680
  }
394
681
 
395
- task downloadDoubleConversion(dependsOn: createNativeDepsDirectories, type: Download) {
682
+ task downloadDoubleConversion(dependsOn: resolveDoubleConversion, type: Download) {
396
683
  src("https://github.com/google/double-conversion/archive/v${DOUBLE_CONVERSION_VERSION}.tar.gz")
397
684
  onlyIfNewer(true)
398
685
  overwrite(false)
@@ -408,7 +695,7 @@ task prepareDoubleConversion(dependsOn: dependenciesPath ? [] : [downloadDoubleC
408
695
  into("$thirdPartyNdkDir/double-conversion")
409
696
  }
410
697
 
411
- task downloadFolly(dependsOn: createNativeDepsDirectories, type: Download) {
698
+ task downloadFolly(dependsOn: resolveFolly, type: Download) {
412
699
  src("https://github.com/facebook/folly/archive/v${FOLLY_VERSION}.tar.gz")
413
700
  onlyIfNewer(true)
414
701
  overwrite(false)
@@ -427,7 +714,7 @@ task prepareFolly(dependsOn: dependenciesPath ? [] : [downloadFolly], type: Copy
427
714
  into("$thirdPartyNdkDir/folly")
428
715
  }
429
716
 
430
- task downloadGlog(dependsOn: createNativeDepsDirectories, type: Download) {
717
+ task downloadGlog(dependsOn: resolveGlog, type: Download) {
431
718
  src("https://github.com/google/glog/archive/v${GLOG_VERSION}.tar.gz")
432
719
  onlyIfNewer(true)
433
720
  overwrite(false)
@@ -483,12 +770,10 @@ as well as unzip Hermes AAR in order to obtain `libhermes.so` shared library.
483
770
  For more details, see https://reactnative.dev/architecture/bundled-hermes
484
771
  or https://github.com/reactwg/react-native-new-architecture/discussions/4
485
772
  */
486
- if (rnMinorVersion >= 69 && !isNewArchitectureEnabled()) {
773
+ if (REACT_NATIVE_MINOR_VERSION >= 69 && !isNewArchitectureEnabled()) {
487
774
  // copied from `react-native/ReactAndroid/hermes-engine/build.gradle`
488
775
 
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")
776
+ def downloadDir = customDownloadsDir ? new File(customDownloadsDir) : new File(reactNativeRootDir, "sdks/download")
492
777
 
493
778
  // By default we are going to download and unzip hermes inside the /sdks/hermes folder
494
779
  // but you can provide an override for where the hermes source code is located.
@@ -513,7 +798,7 @@ if (rnMinorVersion >= 69 && !isNewArchitectureEnabled()) {
513
798
  // We flatten the unzip as the tarball contains a `facebook-hermes-<SHA>`
514
799
  // folder at the top level.
515
800
  if (file.relativePath.segments.size() > 1) {
516
- file.relativePath = new org.gradle.api.file.RelativePath(!file.isDirectory(), file.relativePath.segments.drop(1))
801
+ file.relativePath = new RelativePath(!file.isDirectory(), file.relativePath.segments.drop(1))
517
802
  }
518
803
  }
519
804
  }
@@ -522,13 +807,18 @@ if (rnMinorVersion >= 69 && !isNewArchitectureEnabled()) {
522
807
  }
523
808
 
524
809
  task prepareHermes() {
525
- if (rnMinorVersion >= 69) {
810
+ if (REACT_NATIVE_MINOR_VERSION >= 69) {
526
811
  if (!isNewArchitectureEnabled()) {
527
812
  dependsOn(unzipHermes)
528
813
  }
529
814
 
530
815
  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
816
+ // e.g. hermes-engine-0.70.0-rc.1-debug.aar
817
+ def hermesAAR = file(
818
+ "$reactNativeRootDir/android/com/facebook/react/hermes-engine/" +
819
+ "${REACT_NATIVE_VERSION}/hermes-engine-${REACT_NATIVE_VERSION}-" +
820
+ "${resolveBuildType()}.aar"
821
+ )
532
822
  if (!hermesAAR.exists()) {
533
823
  throw new GradleScriptException("Could not find hermes-engine AAR", null)
534
824
  }
@@ -537,7 +827,7 @@ task prepareHermes() {
537
827
 
538
828
  copy {
539
829
  from soFiles
540
- from "$reactNative/ReactAndroid/src/main/jni/first-party/hermes/Android.mk"
830
+ from "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/hermes/Android.mk"
541
831
  into "$thirdPartyNdkDir/hermes"
542
832
  }
543
833
  }
@@ -548,16 +838,16 @@ task prepareHermes() {
548
838
  throw new GradleScriptException("Could not find the hermes-engine npm package", null)
549
839
  }
550
840
 
551
- def hermesAAR = file("$hermesPackagePath/android/hermes-debug.aar")
841
+ def hermesAAR = file("$hermesPackagePath/android/hermes-${resolveBuildType()}.aar") // e.g. hermes-debug.aar
552
842
  if (!hermesAAR.exists()) {
553
- throw new GradleScriptException("The hermes-engine npm package is missing \"android/hermes-debug.aar\"", null)
843
+ throw new GradleScriptException("The hermes-engine npm package is missing \"android/hermes-${resolveBuildType()}.aar\"", null)
554
844
  }
555
845
 
556
846
  def soFiles = zipTree(hermesAAR).matching({ it.include "**/*.so" })
557
847
 
558
848
  copy {
559
849
  from soFiles
560
- from "$reactNative/ReactAndroid/src/main/jni/first-party/hermes/Android.mk"
850
+ from "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/hermes/Android.mk"
561
851
  into "$thirdPartyNdkDir/hermes"
562
852
  }
563
853
  }
@@ -584,7 +874,7 @@ task prepareJSC {
584
874
  copy {
585
875
  from(soFiles)
586
876
  from(headerFiles)
587
- from("$reactNative/ReactAndroid/src/main/jni/third-party/jsc/Android.mk")
877
+ from("$reactNativeRootDir/ReactAndroid/src/main/jni/third-party/jsc/Android.mk")
588
878
 
589
879
  filesMatching("**/*.h", { it.path = "JavaScriptCore/${it.name}" })
590
880
 
@@ -601,7 +891,7 @@ task extractAARHeaders {
601
891
  def packageName = file.name.tokenize('-')[0]
602
892
  copy {
603
893
  from zipTree(file)
604
- into "$reactNative/ReactAndroid/src/main/jni/first-party/$packageName/headers"
894
+ into "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/$packageName/headers"
605
895
  include "**/*.h"
606
896
  }
607
897
  }
@@ -615,7 +905,7 @@ task extractSOFiles {
615
905
  def packageName = file.name.tokenize('-')[0]
616
906
  copy {
617
907
  from zipTree(file)
618
- into "$reactNative/ReactAndroid/src/main/jni/first-party/$packageName/"
908
+ into "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/$packageName/"
619
909
  include "jni/**/*.so"
620
910
  }
621
911
  }
@@ -625,7 +915,7 @@ task extractSOFiles {
625
915
  task packageNdkLibs(type: Copy) {
626
916
  from("$buildDir/reanimated-ndk/all")
627
917
  include("**/libreanimated.so")
628
- if(REACT_VERSION < 64) {
918
+ if(REACT_NATIVE_MINOR_VERSION < 64) {
629
919
  include("**/libturbomodulejsijni.so")
630
920
  }
631
921
  into("$projectDir/src/main/jniLibs")
@@ -636,11 +926,11 @@ repositories {
636
926
  mavenLocal()
637
927
  maven {
638
928
  // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
639
- url "$reactNative/android"
929
+ url "$reactNativeRootDir/android"
640
930
  }
641
931
  maven {
642
932
  // Android JSC is installed from npm
643
- url "$reactNative/../jsc-android/dist"
933
+ url "$reactNativeRootDir/../jsc-android/dist"
644
934
  }
645
935
  google()
646
936
  }
@@ -656,31 +946,27 @@ dependencies {
656
946
  }
657
947
  implementation "com.facebook.react:react-native:+" // From node_modules
658
948
  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
- }
949
+ implementation "androidx.core:core:1.6.0"
950
+
665
951
  extractHeaders("com.facebook.fbjni:fbjni:" + FBJNI_VERSION + ":headers")
666
952
  extractSO("com.facebook.fbjni:fbjni:" + FBJNI_VERSION)
667
953
 
668
- def jscAAR = fileTree("$reactNative/../jsc-android/dist/org/webkit/android-jsc").matching({ it.include "**/**/*.aar" }).singleFile
954
+ def jscAAR = fileTree("$reactNativeRootDir/../jsc-android/dist/org/webkit/android-jsc").matching({ it.include "**/**/*.aar" }).singleFile
669
955
  extractSO(files(jscAAR))
670
956
  }
671
957
 
672
958
  task unpackReactNativeAAR {
673
959
  def buildType = resolveBuildType()
674
960
  def rnAarMatcher = "**/react-native/**/*${buildType}.aar"
675
- if (rnMinorVersion < 69) {
961
+ if (REACT_NATIVE_MINOR_VERSION < 69) {
676
962
  rnAarMatcher = "**/**/*.aar"
677
963
  }
678
- def rnAAR = fileTree("$reactNative/android").matching({ it.include rnAarMatcher }).singleFile
964
+ def rnAAR = fileTree("$reactNativeRootDir/android").matching({ it.include rnAarMatcher }).singleFile
679
965
  def file = rnAAR.absoluteFile
680
966
  def packageName = file.name.tokenize('-')[0]
681
967
  copy {
682
968
  from zipTree(file)
683
- into "$reactNative/ReactAndroid/src/main/jni/first-party/$packageName/"
969
+ into "$reactNativeRootDir/ReactAndroid/src/main/jni/first-party/$packageName/"
684
970
  include "jni/**/*.so"
685
971
  }
686
972
  }
@@ -694,12 +980,23 @@ task downloadNdkBuildDependencies {
694
980
  dependsOn(downloadGlog)
695
981
  }
696
982
 
697
- task prepareThirdPartyNdkHeaders(dependsOn:[downloadNdkBuildDependencies, prepareBoost, prepareDoubleConversion, prepareFolly, prepareGlog, unpackReactNativeAAR]) {
698
- }
983
+ task prepareThirdPartyNdkHeaders(dependsOn:[
984
+ downloadNdkBuildDependencies,
985
+ prepareBoost,
986
+ prepareDoubleConversion,
987
+ prepareFolly,
988
+ prepareGlog,
989
+ unpackReactNativeAAR]
990
+ ) {}
699
991
 
700
992
  def nativeBuildDependsOn(dependsOnTask) {
701
- def buildTasks = tasks.findAll({ task ->
702
- !task.name.contains("Clean") && (task.name.contains("externalNative") || task.name.contains("CMake")) })
993
+ def buildTasks = tasks.findAll({ task -> (
994
+ !task.name.contains("Clean")
995
+ && (task.name.contains("externalNative")
996
+ || task.name.contains("CMake")
997
+ || task.name.contains("generateJsonModel")
998
+ )
999
+ ) })
703
1000
  buildTasks.forEach { task -> task.dependsOn(dependsOnTask) }
704
1001
  }
705
1002
 
@@ -718,8 +1015,8 @@ afterEvaluate {
718
1015
  })
719
1016
 
720
1017
  if (JS_RUNTIME == "hermes") {
721
- extractAARHeaders.dependsOn(prepareHermes)
722
- extractSOFiles.dependsOn(prepareHermes)
1018
+ extractAARHeaders.dependsOn(prepareHermes)
1019
+ extractSOFiles.dependsOn(prepareHermes)
723
1020
  } else if (JS_RUNTIME == "v8") {
724
1021
  def buildTasks = tasks.findAll({ task ->
725
1022
  !task.name.contains("Clean") && (task.name.contains("externalNative") || task.name.contains("CMake") || task.name.startsWith("generateJsonModel")) })
@@ -727,12 +1024,17 @@ afterEvaluate {
727
1024
  def buildType = task.name.endsWith('Debug') ? 'Debug' : 'Release'
728
1025
  task.dependsOn(":react-native-v8:copy${buildType}JniLibsProjectOnly")
729
1026
  }
1027
+ } else if (JS_RUNTIME == "jsc") {
1028
+ extractAARHeaders.dependsOn(prepareJSC)
1029
+ extractSOFiles.dependsOn(prepareJSC)
1030
+ } else {
1031
+ throw GradleScriptException("Unknown JS runtime ${JS_RUNTIME}.")
730
1032
  }
731
1033
  }
732
1034
 
733
1035
  if (CLIENT_SIDE_BUILD) {
734
1036
  def aarDir = "${buildDir}/outputs"
735
- def aar = file("${aarDir}/android-debug.aar")
1037
+ aar = file("${aarDir}/android-${resolveBuildType()}.aar") // e.g. android-debug.aar
736
1038
  if (aar == null) {
737
1039
  throw GradleScriptException("AAR build failed. No AAR found in ${aarDir}.")
738
1040
  }