react-native-reanimated 2.3.3 → 2.5.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 (249) hide show
  1. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +72 -0
  2. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +30 -1
  3. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +64 -39
  4. package/Common/cpp/Tools/RuntimeDecorator.cpp +2 -0
  5. package/Common/cpp/headers/AnimatedSensor/AnimatedSensorModule.h +41 -0
  6. package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +14 -0
  7. package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +14 -0
  8. package/Common/cpp/headers/SharedItems/MutableValue.h +4 -1
  9. package/Common/cpp/headers/SharedItems/ShareableValue.h +3 -0
  10. package/Common/cpp/headers/SharedItems/ValueWrapper.h +3 -0
  11. package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +11 -0
  12. package/Common/cpp/headers/Tools/RuntimeDecorator.h +2 -0
  13. package/LICENSE +1 -1
  14. package/README.md +2 -2
  15. package/android/.gradle/7.2/dependencies-accessors/dependencies-accessors.lock +0 -0
  16. package/android/.gradle/7.2/dependencies-accessors/gc.properties +0 -0
  17. package/android/.gradle/7.2/executionHistory/executionHistory.bin +0 -0
  18. package/android/.gradle/7.2/executionHistory/executionHistory.lock +0 -0
  19. package/android/.gradle/7.2/fileChanges/last-build.bin +0 -0
  20. package/android/.gradle/7.2/fileHashes/fileHashes.bin +0 -0
  21. package/android/.gradle/7.2/fileHashes/fileHashes.lock +0 -0
  22. package/android/.gradle/7.2/fileHashes/resourceHashesCache.bin +0 -0
  23. package/android/.gradle/7.2/gc.properties +0 -0
  24. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  25. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  26. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  27. package/android/.gradle/checksums/checksums.lock +0 -0
  28. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  29. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  30. package/android/.gradle/vcs-1/gc.properties +0 -0
  31. package/android/CMakeLists.txt +198 -0
  32. package/android/README.md +15 -0
  33. package/android/build.gradle +686 -73
  34. package/android/empty.cpp +1 -0
  35. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  36. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  37. package/android/gradle.properties +25 -0
  38. package/android/gradlew +234 -0
  39. package/android/gradlew.bat +89 -0
  40. package/android/react-native-reanimated-64-hermes.aar +0 -0
  41. package/android/react-native-reanimated-64-jsc.aar +0 -0
  42. package/android/react-native-reanimated-65-hermes.aar +0 -0
  43. package/android/react-native-reanimated-65-jsc.aar +0 -0
  44. package/android/react-native-reanimated-66-hermes.aar +0 -0
  45. package/android/react-native-reanimated-66-jsc.aar +0 -0
  46. package/android/react-native-reanimated-67-hermes.aar +0 -0
  47. package/android/react-native-reanimated-67-jsc.aar +0 -0
  48. package/android/react-native-reanimated-68-hermes.aar +0 -0
  49. package/android/react-native-reanimated-68-jsc.aar +0 -0
  50. package/android/rnVersionPatch/62/layoutReanimation/ReanimatedNativeHierarchyManager.java +412 -0
  51. package/android/rnVersionPatch/62/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  52. package/android/rnVersionPatch/63/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  53. package/android/rnVersionPatch/64/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  54. package/android/rnVersionPatch/65/.gitkeep +0 -0
  55. package/android/rnVersionPatch/66/.gitkeep +0 -0
  56. package/android/rnVersionPatch/67/.gitkeep +0 -0
  57. package/android/rnVersionPatch/68/.gitkeep +0 -0
  58. package/android/rnVersionPatch/backup/.gitkeep +0 -0
  59. package/android/settings.gradle +1 -0
  60. package/android/spotless.gradle +9 -0
  61. package/android/src/{AndroidManifest.xml → main/AndroidManifest.xml} +0 -0
  62. package/android/src/main/cpp/AndroidErrorHandler.cpp +42 -0
  63. package/android/src/main/cpp/AndroidLogger.cpp +27 -0
  64. package/android/src/main/cpp/AndroidScheduler.cpp +59 -0
  65. package/android/src/main/cpp/JNIHelper.cpp +59 -0
  66. package/android/src/main/cpp/LayoutAnimations.cpp +103 -0
  67. package/android/src/main/cpp/NativeProxy.cpp +327 -0
  68. package/android/src/main/cpp/OnLoad.cpp +17 -0
  69. package/android/src/main/cpp/TurboModule.cpp +44 -0
  70. package/android/src/main/cpp/headers/AndroidErrorHandler.h +30 -0
  71. package/android/src/main/cpp/headers/AndroidLogger.h +16 -0
  72. package/android/src/main/cpp/headers/AndroidScheduler.h +41 -0
  73. package/android/src/main/cpp/headers/JNIHelper.h +30 -0
  74. package/android/src/main/cpp/headers/LayoutAnimations.h +42 -0
  75. package/android/src/main/cpp/headers/NativeProxy.h +170 -0
  76. package/android/src/main/cpp/headers/TurboModule.h +70 -0
  77. package/android/src/main/java/com/facebook/react/uimanager/UIManagerReanimatedHelper.java +15 -0
  78. package/android/src/main/java/com/swmansion/common/GestureHandlerStateManager.java +5 -0
  79. package/android/src/main/java/com/swmansion/reanimated/AndroidErrorHandler.java +8 -0
  80. package/android/src/main/java/com/swmansion/reanimated/CopiedEvent.java +43 -0
  81. package/android/src/main/java/com/swmansion/reanimated/MapUtils.java +26 -0
  82. package/android/src/main/java/com/swmansion/reanimated/NativeMethodsHelper.java +117 -0
  83. package/android/src/main/java/com/swmansion/reanimated/NativeProxy.java +285 -0
  84. package/android/src/main/java/com/swmansion/reanimated/NodesManager.java +682 -0
  85. package/android/src/main/java/com/swmansion/reanimated/ReanimatedJSIModulePackage.java +29 -0
  86. package/android/src/main/java/com/swmansion/reanimated/ReanimatedModule.java +251 -0
  87. package/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java +96 -0
  88. package/android/src/main/java/com/swmansion/reanimated/Scheduler.java +51 -0
  89. package/android/src/main/java/com/swmansion/reanimated/UpdateContext.java +11 -0
  90. package/android/src/main/java/com/swmansion/reanimated/Utils.java +32 -0
  91. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +517 -0
  92. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/LayoutAnimations.java +56 -0
  93. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/NativeMethodsHolder.java +11 -0
  94. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +410 -0
  95. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIImplementation.java +68 -0
  96. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +292 -0
  97. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/Snapshot.java +121 -0
  98. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ViewHierarchyObserver.java +12 -0
  99. package/android/src/main/java/com/swmansion/reanimated/nodes/AlwaysNode.java +29 -0
  100. package/android/src/main/java/com/swmansion/reanimated/nodes/BezierNode.java +87 -0
  101. package/android/src/main/java/com/swmansion/reanimated/nodes/BlockNode.java +24 -0
  102. package/android/src/main/java/com/swmansion/reanimated/nodes/CallFuncNode.java +49 -0
  103. package/android/src/main/java/com/swmansion/reanimated/nodes/ClockNode.java +38 -0
  104. package/android/src/main/java/com/swmansion/reanimated/nodes/ClockOpNode.java +73 -0
  105. package/android/src/main/java/com/swmansion/reanimated/nodes/ConcatNode.java +36 -0
  106. package/android/src/main/java/com/swmansion/reanimated/nodes/CondNode.java +41 -0
  107. package/android/src/main/java/com/swmansion/reanimated/nodes/DebugNode.java +33 -0
  108. package/android/src/main/java/com/swmansion/reanimated/nodes/EventNode.java +83 -0
  109. package/android/src/main/java/com/swmansion/reanimated/nodes/FinalNode.java +5 -0
  110. package/android/src/main/java/com/swmansion/reanimated/nodes/FunctionNode.java +20 -0
  111. package/android/src/main/java/com/swmansion/reanimated/nodes/JSCallNode.java +41 -0
  112. package/android/src/main/java/com/swmansion/reanimated/nodes/Node.java +139 -0
  113. package/android/src/main/java/com/swmansion/reanimated/nodes/NoopNode.java +37 -0
  114. package/android/src/main/java/com/swmansion/reanimated/nodes/OperatorNode.java +377 -0
  115. package/android/src/main/java/com/swmansion/reanimated/nodes/ParamNode.java +71 -0
  116. package/android/src/main/java/com/swmansion/reanimated/nodes/PropsNode.java +153 -0
  117. package/android/src/main/java/com/swmansion/reanimated/nodes/SetNode.java +32 -0
  118. package/android/src/main/java/com/swmansion/reanimated/nodes/StyleNode.java +40 -0
  119. package/android/src/main/java/com/swmansion/reanimated/nodes/TransformNode.java +84 -0
  120. package/android/src/main/java/com/swmansion/reanimated/nodes/ValueNode.java +40 -0
  121. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensor.java +41 -0
  122. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorContainer.java +40 -0
  123. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java +31 -0
  124. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorType.java +35 -0
  125. package/android/src/main/java/com/swmansion/reanimated/transitions/ChangeTransition.java +84 -0
  126. package/android/src/main/java/com/swmansion/reanimated/transitions/SaneSidePropagation.java +25 -0
  127. package/android/src/main/java/com/swmansion/reanimated/transitions/Scale.java +86 -0
  128. package/android/src/main/java/com/swmansion/reanimated/transitions/TransitionModule.java +41 -0
  129. package/android/src/main/java/com/swmansion/reanimated/transitions/TransitionUtils.java +161 -0
  130. package/ios/LayoutReanimation/REAAnimationsManager.h +1 -1
  131. package/ios/LayoutReanimation/REAAnimationsManager.m +18 -4
  132. package/ios/REAModule.m +8 -9
  133. package/ios/REANodesManager.h +4 -1
  134. package/ios/REANodesManager.m +75 -3
  135. package/ios/native/NativeMethods.h +1 -1
  136. package/ios/native/NativeProxy.mm +85 -5
  137. package/ios/sensor/ReanimatedSensor.h +21 -0
  138. package/ios/sensor/ReanimatedSensor.m +169 -0
  139. package/ios/sensor/ReanimatedSensorContainer.h +13 -0
  140. package/ios/sensor/ReanimatedSensorContainer.m +41 -0
  141. package/ios/sensor/ReanimatedSensorType.h +7 -0
  142. package/lib/ConfigHelper.js +2 -2
  143. package/lib/createAnimatedComponent.js +3 -4
  144. package/lib/reanimated1/core/AnimatedFunction.js +1 -1
  145. package/lib/reanimated1/derived/interpolate.js +2 -4
  146. package/lib/reanimated2/Colors.js +3 -98
  147. package/lib/reanimated2/Easing.js +5 -0
  148. package/lib/reanimated2/NativeMethods.js +15 -5
  149. package/lib/reanimated2/NativeReanimated/NativeReanimated.js +25 -12
  150. package/lib/reanimated2/NativeReanimated/index.js +2 -6
  151. package/lib/reanimated2/ViewDescriptorsSet.js +2 -2
  152. package/lib/reanimated2/animation/styleAnimation.js +2 -1
  153. package/lib/reanimated2/core.js +30 -24
  154. package/lib/reanimated2/globals.d.ts +6 -0
  155. package/lib/reanimated2/hook/index.js +1 -0
  156. package/lib/reanimated2/hook/useAnimatedGestureHandler.js +1 -2
  157. package/lib/reanimated2/hook/useAnimatedSensor.js +66 -0
  158. package/lib/reanimated2/hook/useAnimatedStyle.js +31 -14
  159. package/lib/reanimated2/hook/utils.js +14 -11
  160. package/lib/reanimated2/index.js +2 -0
  161. package/lib/reanimated2/interpolateColor.js +98 -0
  162. package/lib/reanimated2/interpolation.js +1 -1
  163. package/lib/reanimated2/jestUtils.js +9 -4
  164. package/lib/reanimated2/js-reanimated/JSReanimated.js +24 -3
  165. package/lib/reanimated2/js-reanimated/commonTypes.js +1 -0
  166. package/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +8 -0
  167. package/lib/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +2 -1
  168. package/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +32 -42
  169. package/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.js +20 -38
  170. package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +32 -44
  171. package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -16
  172. package/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +6 -10
  173. package/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -12
  174. package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +20 -36
  175. package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +16 -20
  176. package/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +8 -12
  177. package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +32 -48
  178. package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +22 -18
  179. package/lib/reanimated2/mock.js +3 -2
  180. package/mock.js +6 -4
  181. package/package.json +44 -36
  182. package/plugin.js +3 -0
  183. package/react-native-reanimated.d.ts +102 -15
  184. package/src/ConfigHelper.ts +4 -4
  185. package/src/createAnimatedComponent.tsx +3 -3
  186. package/src/reanimated1/core/AnimatedFunction.js +1 -1
  187. package/src/reanimated1/derived/interpolate.js +2 -4
  188. package/src/reanimated2/Colors.ts +8 -151
  189. package/src/reanimated2/Easing.ts +11 -0
  190. package/src/reanimated2/NativeMethods.ts +19 -6
  191. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +42 -14
  192. package/src/reanimated2/NativeReanimated/index.ts +2 -8
  193. package/src/reanimated2/ViewDescriptorsSet.ts +2 -3
  194. package/src/reanimated2/animation/commonTypes.ts +44 -40
  195. package/src/reanimated2/animation/decay.ts +1 -1
  196. package/src/reanimated2/animation/delay.ts +2 -16
  197. package/src/reanimated2/animation/index.ts +8 -8
  198. package/src/reanimated2/animation/repeat.ts +2 -12
  199. package/src/reanimated2/animation/sequence.ts +3 -10
  200. package/src/reanimated2/animation/spring.ts +1 -1
  201. package/src/reanimated2/animation/styleAnimation.ts +11 -25
  202. package/src/reanimated2/animation/timing.ts +4 -2
  203. package/src/reanimated2/animation/util.ts +22 -20
  204. package/src/reanimated2/commonTypes.ts +68 -1
  205. package/src/reanimated2/component/FlatList.tsx +2 -1
  206. package/src/reanimated2/core.ts +35 -29
  207. package/src/reanimated2/globals.d.ts +6 -0
  208. package/src/reanimated2/hook/commonTypes.ts +5 -0
  209. package/src/reanimated2/hook/index.ts +1 -0
  210. package/src/reanimated2/hook/useAnimatedGestureHandler.ts +1 -2
  211. package/src/reanimated2/hook/useAnimatedRef.ts +1 -5
  212. package/src/reanimated2/hook/useAnimatedSensor.ts +91 -0
  213. package/src/reanimated2/hook/useAnimatedStyle.ts +35 -16
  214. package/src/reanimated2/hook/utils.ts +20 -18
  215. package/src/reanimated2/index.ts +2 -0
  216. package/src/reanimated2/interpolateColor.ts +178 -0
  217. package/src/reanimated2/interpolation.ts +2 -6
  218. package/src/reanimated2/jestUtils.ts +9 -4
  219. package/src/reanimated2/js-reanimated/JSReanimated.ts +28 -6
  220. package/src/reanimated2/js-reanimated/Mapper.ts +1 -1
  221. package/src/reanimated2/js-reanimated/MapperRegistry.ts +1 -1
  222. package/src/reanimated2/js-reanimated/commonTypes.ts +51 -0
  223. package/src/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.ts +13 -0
  224. package/src/reanimated2/layoutReanimation/animationBuilder/Keyframe.ts +2 -3
  225. package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +51 -21
  226. package/src/reanimated2/layoutReanimation/defaultAnimations/Fade.ts +40 -10
  227. package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +48 -12
  228. package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +16 -4
  229. package/src/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.ts +8 -2
  230. package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +16 -4
  231. package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +32 -8
  232. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +32 -10
  233. package/src/reanimated2/layoutReanimation/defaultAnimations/Stretch.ts +16 -4
  234. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +64 -16
  235. package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +2 -1
  236. package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +32 -21
  237. package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +2 -1
  238. package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +2 -1
  239. package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +2 -1
  240. package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +2 -1
  241. package/src/reanimated2/mock.ts +3 -2
  242. package/src/reanimated2/utils.ts +1 -1
  243. package/android/react-native-reanimated-63-hermes.aar +0 -0
  244. package/android/react-native-reanimated-63-jsc.aar +0 -0
  245. package/android/src/main/java/com/swmansion/reanimated/ReanimatedProxyPackage.java +0 -15
  246. package/libSo/fbjni/jni/arm64-v8a/libfbjni.so +0 -0
  247. package/libSo/fbjni/jni/armeabi-v7a/libfbjni.so +0 -0
  248. package/libSo/fbjni/jni/x86/libfbjni.so +0 -0
  249. package/libSo/fbjni/jni/x86_64/libfbjni.so +0 -0
@@ -1,26 +1,137 @@
1
- import groovy.json.JsonSlurper
1
+ import java.nio.file.Paths
2
+ import org.apache.tools.ant.filters.ReplaceTokens
3
+
2
4
  import java.util.regex.Matcher
3
5
  import java.util.regex.Pattern
4
- configurations.maybeCreate("default")
6
+ import groovy.json.JsonSlurper
7
+ import java.util.zip.ZipFile
5
8
 
6
- def inputFile = new File(projectDir, '../../react-native/package.json')
7
- def json = new JsonSlurper().parseText(inputFile.text)
8
- def reactNativeVersion = json.version as String
9
- def (major, minor, patch) = reactNativeVersion.tokenize('.')
9
+ /**
10
+ * Finds the path of the installed npm package with the given name using Node's
11
+ * module resolution algorithm, which searches "node_modules" directories up to
12
+ * the file system root. This handles various cases, including:
13
+ *
14
+ * - Working in the open-source RN repo:
15
+ * Gradle: /path/to/react-native/ReactAndroid
16
+ * Node module: /path/to/react-native/node_modules/[package]
17
+ *
18
+ * - Installing RN as a dependency of an app and searching for hoisted
19
+ * dependencies:
20
+ * Gradle: /path/to/app/node_modules/react-native/ReactAndroid
21
+ * Node module: /path/to/app/node_modules/[package]
22
+ *
23
+ * - Working in a larger repo (e.g., Facebook) that contains RN:
24
+ * Gradle: /path/to/repo/path/to/react-native/ReactAndroid
25
+ * Node module: /path/to/repo/node_modules/[package]
26
+ *
27
+ * The search begins at the given base directory (a File object). The returned
28
+ * path is a string.
29
+ */
30
+ static def findNodeModulePath(baseDir, packageName) {
31
+ def basePath = baseDir.toPath().normalize()
32
+ // Node's module resolution algorithm searches up to the root directory,
33
+ // after which the base path will be null
34
+ while (basePath) {
35
+ def candidatePath = Paths.get(basePath.toString(), "node_modules", packageName)
36
+ if (candidatePath.toFile().exists()) {
37
+ return candidatePath.toString()
38
+ }
39
+ basePath = basePath.getParent()
40
+ }
41
+ return null
42
+ }
10
43
 
11
- def engine = "jsc"
44
+ def safeExtGet(prop, fallback) {
45
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
46
+ }
47
+
48
+ def getCurrentFlavor() {
49
+ String taskRequestName = getGradle().getStartParameter().getTaskRequests().toString()
50
+ Pattern pattern = Pattern.compile("(assemble|bundle|install|generate)(\\w*)(Release|Debug)")
51
+ Matcher matcher = pattern.matcher(taskRequestName)
52
+
53
+ if (matcher.find()) {
54
+ return matcher.group(2)
55
+ }
56
+
57
+ return "NOT-FOUND"
58
+ }
59
+
60
+ def resolveBuildType() {
61
+ def buildType = System.getenv("CLIENT_SIDE_BUILD")
62
+ if (buildType != null) {
63
+ return buildType == "True"
64
+ }
65
+
66
+ if (hasProperty("clientSideBuild")) {
67
+ return property("clientSideBuild") == "true"
68
+ }
69
+
70
+ if (isDeveloperMode()) {
71
+ return false
72
+ }
73
+
74
+ return true
75
+ }
76
+
77
+ def resolveExpoLinkingGradle() {
78
+ def gradleScript = file("./expo/linking.gradle")
79
+ if (gradleScript.exists()) {
80
+ return "./expo/linking.gradle"
81
+ } else {
82
+ return "../android-npm/expo/linking.gradle"
83
+ }
84
+ }
85
+
86
+ def isDeveloperMode() {
87
+ // developer mode, to run Example app
88
+ return file("$projectDir/../node_modules/react-native/package.json").exists()
89
+ }
90
+
91
+ def resolveReactNativeDirectory() {
92
+ if (isDeveloperMode()) {
93
+ return file("$projectDir/../node_modules/react-native")
94
+ }
95
+ return file("$projectDir/../../react-native")
96
+ }
12
97
 
13
98
  abstract class replaceSoTask extends DefaultTask {
14
99
  public static String appName = ":app"
15
100
  public static String buildDir = "../../../android/app/build"
101
+ public static String fbjniVersion = "0.3.0"
16
102
 
17
103
  @TaskAction
18
104
  def run() {
105
+ def libSoDir = new File("${buildDir}/tmp/libSo")
106
+ if (!libSoDir.exists()) {
107
+ libSoDir.mkdirs()
108
+ def fbjniUrl = "https://repo1.maven.org/maven2/com/facebook/fbjni/fbjni/${fbjniVersion}/fbjni-${fbjniVersion}.aar"
109
+ def aarFile = new File("${libSoDir.path}/fbjni-${fbjniVersion}.aar")
110
+ aarFile.createNewFile()
111
+ aarFile.withOutputStream { out ->
112
+ def url = new URL(fbjniUrl).openConnection()
113
+ out << url.inputStream
114
+ }
115
+ if (!aarFile.exists()) {
116
+ println("Unable to find ${libSoDir.path}/fbjni-${fbjniVersion}.aar")
117
+ return
118
+ }
119
+ def zipFile = new ZipFile(new File("${libSoDir.path}/fbjni-${fbjniVersion}.aar"))
120
+ zipFile.entries().each {
121
+ def zipIt = it
122
+ if (zipIt.name.contains("libfbjni.so")) {
123
+ new File("${libSoDir.path}/" + zipIt.name.replace("/libfbjni.so", "")).mkdirs()
124
+ new File("${libSoDir.path}/" + zipIt.name).withOutputStream{
125
+ it << zipFile.getInputStream(zipIt)
126
+ }
127
+ }
128
+ }
129
+ }
19
130
  for(def abiVersion in ["x86", "x86_64", "armeabi-v7a", "arm64-v8a"]) {
20
131
  ant.sequential {
21
132
  copy(
22
133
  tofile: "${buildDir}/intermediates/merged_native_libs/debug/out/lib/${abiVersion}/libfbjni.so",
23
- file: "../libSo/fbjni/jni/${abiVersion}/libfbjni.so",
134
+ file: "${buildDir}/tmp/libSo/jni/${abiVersion}/libfbjni.so",
24
135
  overwrite: true
25
136
  )
26
137
  }
@@ -28,84 +139,586 @@ abstract class replaceSoTask extends DefaultTask {
28
139
  }
29
140
  }
30
141
 
31
- def getCurrentFlavor() {
32
- Gradle gradle = getGradle()
33
- String taskRequestName = gradle.getStartParameter().getTaskRequests().toString()
34
- Pattern pattern = Pattern.compile("(assemble|bundle|install|generate)(\\w*)(Release|Debug)")
35
- Matcher matcher = pattern.matcher(taskRequestName)
142
+ def detectAAR(minor, engine) {
143
+ def rnMinorVersionCopy = Integer.parseInt(minor)
144
+ def aar = file("react-native-reanimated-${rnMinorVersionCopy}-${engine}.aar")
36
145
 
37
- if(matcher.find()) {
38
- return matcher.group(2)
146
+ if (aar.exists()) {
147
+ println "AAR for react-native-reanimated has been found\n$aar"
148
+ return aar
149
+ } else {
150
+ while (!aar.exists() && rnMinorVersionCopy >= 63) {
151
+ rnMinorVersionCopy -= 1
152
+ aar = file("react-native-reanimated-${rnMinorVersionCopy}-${engine}.aar")
153
+ }
154
+
155
+ if (rnMinorVersionCopy < 63) {
156
+ println "No AAR for react-native-reanimated found. Attempting to build from source."
157
+ } else { // aar exists, but was build for lower react-native version
158
+ println "\n\n\n"
159
+ println "****************************************************************************************"
160
+ println "\n\n\n"
161
+ println "WARNING reanimated - no version-specific reanimated AAR for react-native version $rnMinorVersion found."
162
+ println "Falling back to AAR for react-native version $rnMinorVersionCopy."
163
+ println "The react-native JSI interface is not ABI-safe yet, this may result in crashes."
164
+ println "Please post a pull request to implement support for react-native version $rnMinorVersion to the reanimated repo."
165
+ println "Thanks!"
166
+ println "\n\n\n"
167
+ println "****************************************************************************************"
168
+
169
+ return aar
170
+ }
39
171
  }
172
+ return null
173
+ }
40
174
 
41
- return "NOT-FOUND"
175
+ def detectJsRuntime() {
176
+ def runtimeType = "jsc"
177
+ rootProject.getSubprojects().forEach({project ->
178
+ if (project.plugins.hasPlugin("com.android.application")) {
179
+ if (project.ext.react.enableHermes) {
180
+ runtimeType = "hermes"
181
+ }
182
+ }
183
+ })
184
+ return runtimeType
185
+ }
186
+
187
+ def detectReanimatedConfig() {
188
+ def buildFromSourceConf = false
189
+ rootProject.getSubprojects().forEach({project ->
190
+ if (project.plugins.hasPlugin("com.android.application")) {
191
+ if (
192
+ project.ext.has("reanimated")
193
+ && project.ext.reanimated.buildFromSource
194
+ ) {
195
+ buildFromSourceConf = true
196
+ }
197
+ }
198
+ })
199
+ return buildFromSourceConf
200
+ }
201
+
202
+ def shouldBuildFromSource(aar) {
203
+ if (isDeveloperMode()) {
204
+ // Example app
205
+ return true
206
+ }
207
+ else if (detectReanimatedConfig()) {
208
+ // on user demand
209
+ return true
210
+ }
211
+ else if (aar != null) {
212
+ // when binary exist
213
+ return false
214
+ }
215
+ // when binary is not found
216
+ return true
42
217
  }
43
218
 
44
- def replaceSoTaskDebug
45
- def replaceSoTaskRelease
46
- if(Integer.parseInt(minor) < 65) {
47
- tasks.register("replaceSoTaskDebug", replaceSoTask)
48
- tasks.register("replaceSoTaskRelease", replaceSoTask)
49
- replaceSoTaskDebug = project.getTasks().getByPath(":react-native-reanimated:replaceSoTaskDebug")
50
- replaceSoTaskRelease = project.getTasks().getByPath(":react-native-reanimated:replaceSoTaskRelease")
219
+ boolean CLIENT_SIDE_BUILD = resolveBuildType()
220
+ if (CLIENT_SIDE_BUILD) {
221
+ configurations.maybeCreate("default")
51
222
  }
223
+ def reactNative = resolveReactNativeDirectory()
224
+ def reactNativeManifest = file("$reactNative/package.json")
225
+ def reactNativeManifestAsJson = new JsonSlurper().parseText(reactNativeManifest.text)
226
+ def reactNativeVersion = reactNativeManifestAsJson.version as String
227
+ def (major, minor, patch) = reactNativeVersion.tokenize('.')
228
+ def rnMinorVersion = Integer.parseInt(minor)
229
+ def engine = detectJsRuntime()
230
+ def aar = detectAAR(minor, engine)
231
+ boolean BUILD_FROM_SOURCE = shouldBuildFromSource(aar)
232
+
233
+ def getTaskByPath(project, String appName, String secondPart, String flavorString, String lastPart) {
234
+ String pathName = "${appName}:${secondPart}${flavorString}${lastPart}"
235
+ Task task = project.getTasks().findByPath(pathName)
236
+ if (task != null) {
237
+ return task
238
+ }
239
+ pathName = "${appName}:${secondPart}${flavorString.capitalize()}${lastPart}"
240
+ return project.getTasks().findByPath(pathName)
241
+ }
242
+
243
+ if (!BUILD_FROM_SOURCE) {
244
+ if (rnMinorVersion < 65) {
245
+ tasks.register("replaceSoTaskDebug", replaceSoTask)
246
+ tasks.register("replaceSoTaskRelease", replaceSoTask)
247
+ Task replaceSoTaskDebug = project.getTasks().findByPath(":react-native-reanimated:replaceSoTaskDebug")
248
+ Task replaceSoTaskRelease = project.getTasks().findByPath(":react-native-reanimated:replaceSoTaskRelease")
249
+
250
+ if (replaceSoTaskDebug != null && replaceSoTaskRelease != null) {
251
+ rootProject.getSubprojects().forEach({project ->
252
+ if (project.plugins.hasPlugin("com.android.application") && project.getProperties().get("android")) {
253
+ def projectProperties = project.getProperties()
254
+ def flavorString = getCurrentFlavor()
255
+ def reanimatedConf = projectProperties.get("reanimated")
52
256
 
53
- rootProject.getSubprojects().forEach({project ->
54
- if (project.plugins.hasPlugin("com.android.application")) {
55
- if(project.ext.react.enableHermes) {
56
- engine = "hermes"
257
+ if (
258
+ flavorString != "NOT-FOUND"
259
+ && (!reanimatedConf || (reanimatedConf && !reanimatedConf.get("enablePackagingOptions")))
260
+ ) {
261
+ replaceSoTask.appName = projectProperties.path
262
+ replaceSoTask.buildDir = projectProperties.buildDir
263
+ def appName = projectProperties.path
264
+
265
+ Task debugNativeLibsTask = getTaskByPath(project, appName, "merge", flavorString, "DebugNativeLibs")
266
+ Task debugDebugSymbolsTask = getTaskByPath(project, appName, "strip", flavorString, "DebugDebugSymbols")
267
+ Task releaseNativeLibsTask = getTaskByPath(project, appName, "merge", flavorString, "ReleaseNativeLibs")
268
+ Task releaseDebugSymbolsTask = getTaskByPath(project, appName, "strip", flavorString, "ReleaseDebugSymbols")
269
+ Task debugTask = getTaskByPath(project, appName, "package", flavorString, "Debug")
270
+ Task releaseTask = getTaskByPath(project, appName, "package", flavorString, "Release")
271
+
272
+ if (
273
+ debugNativeLibsTask != null && debugDebugSymbolsTask != null
274
+ && releaseNativeLibsTask != null && releaseDebugSymbolsTask != null
275
+ && debugTask != null && releaseTask != null
276
+ ) {
277
+ replaceSoTaskDebug.dependsOn(debugNativeLibsTask, debugDebugSymbolsTask)
278
+ debugTask.dependsOn(replaceSoTaskDebug)
279
+ replaceSoTaskRelease.dependsOn(releaseNativeLibsTask, releaseDebugSymbolsTask)
280
+ releaseTask.dependsOn(replaceSoTaskRelease)
281
+ }
282
+ }
283
+ }
284
+ })
57
285
  }
286
+ }
58
287
 
59
- if(project.getProperties().get("android") && Integer.parseInt(minor) < 65) {
60
- def projectProperties = project.getProperties()
61
- final NOTFOUND = "NOT-FOUND"
62
- if(!NOTFOUND.equals(getCurrentFlavor()) && (!projectProperties.get("reanimated")
63
- || (projectProperties.get("reanimated") && projectProperties.get("reanimated").get("enablePackagingOptions")))
64
- ) {
65
- def flavorString = getCurrentFlavor()
66
- replaceSoTask.appName = project.getProperties().path
67
- replaceSoTask.buildDir = project.getProperties().buildDir
68
- def appName = project.getProperties().path
69
-
70
- replaceSoTaskDebug.dependsOn(
71
- project.getTasks().getByPath("${appName}:merge${flavorString}DebugNativeLibs"),
72
- project.getTasks().getByPath("${appName}:strip${flavorString}DebugDebugSymbols")
73
- )
74
- project.getTasks().getByPath("${appName}:package${flavorString}Debug").dependsOn(replaceSoTaskDebug)
288
+ artifacts.add("default", aar)
289
+ }
75
290
 
76
- replaceSoTaskRelease.dependsOn(
77
- project.getTasks().getByPath("${appName}:merge${flavorString}ReleaseNativeLibs"),
78
- project.getTasks().getByPath("${appName}:strip${flavorString}ReleaseDebugSymbols")
79
- )
80
- project.getTasks().getByPath("${appName}:package${flavorString}Release").dependsOn(replaceSoTaskRelease)
291
+ // end if already loaded aar
292
+ if (!BUILD_FROM_SOURCE) return
293
+
294
+ // apply expo config
295
+ apply from: resolveExpoLinkingGradle()
296
+
297
+ def localProps = new Properties()
298
+ def localPropertiesFile = file("local.properties")
299
+ if (localPropertiesFile.exists()) {
300
+ localProps.load(new InputStreamReader(new FileInputStream(localPropertiesFile), "UTF-8"))
301
+ }
302
+
303
+ def debugNativeLibraries = localProps.getProperty('NATIVE_DEBUG_ON', 'FALSE').toBoolean()
304
+ def reactProperties = new Properties()
305
+ file("$reactNative/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
306
+
307
+ def BOOST_VERSION = reactProperties.getProperty("BOOST_VERSION")
308
+ def DOUBLE_CONVERSION_VERSION = reactProperties.getProperty("DOUBLE_CONVERSION_VERSION")
309
+ def FOLLY_VERSION = reactProperties.getProperty("FOLLY_VERSION")
310
+ def GLOG_VERSION = reactProperties.getProperty("GLOG_VERSION")
311
+ def REACT_VERSION = reactProperties.getProperty("VERSION_NAME").split("\\.")[1].toInteger()
312
+ def FBJNI_VERSION = "0.3.0"
313
+
314
+ // We download various C++ open-source dependencies into downloads.
315
+ // We then copy both the downloaded code and our custom makefiles and headers into third-party-ndk.
316
+ // After that we build native code from src/main/jni with module path pointing at third-party-ndk.
317
+
318
+ def downloadsDir = new File("$buildDir/downloads")
319
+ def thirdPartyNdkDir = new File("$buildDir/third-party-ndk")
320
+
321
+ def reactNativeThirdParty = new File("$reactNative/ReactAndroid/src/main/jni/third-party")
322
+
323
+ def _stackProtectorFlag = true
324
+ def FOR_HERMES = ""
325
+
326
+ if (findProject(":app")) {
327
+ FOR_HERMES = project(":app").ext.react.enableHermes;
328
+ } else {
329
+ FOR_HERMES = System.getenv("FOR_HERMES") == "True";
330
+ }
331
+
332
+ def reactNativeArchitectures() {
333
+ def value = project.getProperties().get("reactNativeArchitectures")
334
+ return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
335
+ }
336
+
337
+ // You need to have following folders in this directory:
338
+ // - boost_1_63_0
339
+ // - double-conversion-1.1.6
340
+ // - folly-deprecate-dynamic-initializer
341
+ // - glog-0.3.5
342
+ def dependenciesPath = System.getenv("REACT_NATIVE_DEPENDENCIES")
343
+
344
+ // The Boost library is a very large download (>100MB).
345
+ // If Boost is already present on your system, define the REACT_NATIVE_BOOST_PATH env variable
346
+ // and the build will use that.
347
+ def boostPath = dependenciesPath ?: System.getenv("REACT_NATIVE_BOOST_PATH")
348
+
349
+ def follyReplaceContent = '''
350
+ ssize_t r;
351
+ do {
352
+ r = open(name, flags, mode);
353
+ } while (r == -1 && errno == EINTR);
354
+ return r;
355
+ '''
356
+
357
+ buildscript {
358
+ repositories {
359
+ google()
360
+ mavenCentral()
361
+ maven {
362
+ url "https://plugins.gradle.org/m2/"
363
+ }
364
+ }
365
+ dependencies {
366
+ classpath "com.android.tools.build:gradle:4.2.2"
367
+ classpath "de.undercouch:gradle-download-task:4.1.2"
368
+ classpath "com.diffplug.spotless:spotless-plugin-gradle:5.15.0"
369
+ }
370
+ }
371
+
372
+ if (project == rootProject) {
373
+ apply from: "spotless.gradle"
374
+ }
375
+
376
+ apply plugin: "com.android.library"
377
+ apply plugin: "maven-publish"
378
+ apply plugin: "de.undercouch.download"
379
+
380
+ android {
381
+ compileSdkVersion safeExtGet("compileSdkVersion", 30)
382
+ defaultConfig {
383
+ minSdkVersion safeExtGet("minSdkVersion", 16)
384
+ targetSdkVersion safeExtGet("targetSdkVersion", 30)
385
+ versionCode 1
386
+ versionName "1.0"
387
+ externalNativeBuild {
388
+ cmake {
389
+ arguments "-DANDROID_STL=c++_shared",
390
+ "-DNATIVE_DEBUG=${debugNativeLibraries}",
391
+ "-DREACT_NATIVE_TARGET_VERSION=${REACT_VERSION}",
392
+ "-DANDROID_TOOLCHAIN=clang",
393
+ "-DBOOST_VERSION=${BOOST_VERSION}",
394
+ "-DBUILD_DIR=${buildDir}",
395
+ "-DFOR_HERMES=${FOR_HERMES}",
396
+ "-DCLIENT_SIDE_BUILD=${CLIENT_SIDE_BUILD}",
397
+ "--clean-first"
398
+ abiFilters (*reactNativeArchitectures())
399
+ _stackProtectorFlag ? (cppFlags("-fstack-protector-all")) : null
81
400
  }
82
401
  }
402
+
403
+ buildConfigField("boolean", "IS_INTERNAL_BUILD", "false")
404
+ buildConfigField("int", "EXOPACKAGE_FLAGS", "0")
405
+ }
406
+ externalNativeBuild {
407
+ cmake {
408
+ path "CMakeLists.txt"
409
+ }
410
+ }
411
+ lintOptions {
412
+ abortOnError false
413
+ }
414
+ packagingOptions {
415
+ println "Native libs debug enabled: ${debugNativeLibraries}"
416
+ doNotStrip debugNativeLibraries ? "**/**/*.so" : ''
417
+ excludes = [
418
+ "**/libc++_shared.so",
419
+ "**/libfbjni.so",
420
+ "**/libjsi.so",
421
+ "**/libfolly_json.so",
422
+ "**/libglog.so",
423
+ "**/libhermes.so",
424
+ "**/libreactnativejni.so",
425
+ "**/libjscexecutor.so",
426
+ ]
427
+ }
428
+ tasks.withType(JavaCompile) {
429
+ compileTask ->
430
+ compileTask.dependsOn(packageNdkLibs)
431
+ }
432
+ configurations {
433
+ extractHeaders
434
+ extractSO
435
+ }
436
+ compileOptions {
437
+ sourceCompatibility JavaVersion.VERSION_1_8
438
+ targetCompatibility JavaVersion.VERSION_1_8
439
+ }
440
+ }
441
+
442
+ task cleanCmakeCache() {
443
+ tasks.getByName("clean").dependsOn(cleanCmakeCache)
444
+ doFirst {
445
+ delete "${projectDir}/.cxx"
83
446
  }
84
- })
447
+ }
448
+
449
+ task printVersions {
450
+ println "Android gradle plugin: ${com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION}"
451
+ println "Gradle: ${project.gradle.gradleVersion}"
452
+ }
85
453
 
86
- def minorCopy = Integer.parseInt(minor)
87
- def aar = file("react-native-reanimated-${minorCopy}-${engine}.aar")
454
+ task Log {
455
+ println("building Reanimated2")
456
+ }
88
457
 
89
- while (!aar.exists()) {
90
- minorCopy -= 1
91
- aar = file("react-native-reanimated-${minorCopy}-${engine}.aar")
92
- if (minorCopy < 63) {
93
- throw new GradleException('No aar for react-native-reanimated found.')
458
+ task applyJavaPatches(type: Copy) {
459
+ def patchDirectory = file("${projectDir}/rnVersionPatch/${rnMinorVersion}")
460
+ if (patchDirectory.exists()) {
461
+ from ("${patchDirectory}") {
462
+ include "**/*.java"
463
+ }
464
+ into ("${projectDir}/src/main/java/com/swmansion/reanimated")
94
465
  }
95
- if (aar.exists()) {
96
- println "\n\n\n"
97
- println "****************************************************************************************"
98
- println "\n\n\n"
99
- println "WARNING reanimated - no version-specific reanimated AAR for react-native version " . minor . " found."
100
- println "Falling back to AAR for react-native version " . minorCopy
101
- println "The react-native JSI interface is not ABI-safe yet, this may result in crashes."
102
- println "Please post a pull request to implement support for react-native version " . minor . " to the reanimated repo."
103
- println "Thanks!"
104
- println "\n\n\n"
105
- println "****************************************************************************************"
106
- }
107
- }
108
-
109
- artifacts.add("default", aar)
110
-
111
- apply from: './expo/linking.gradle'
466
+ }
467
+
468
+ task createNativeDepsDirectories(dependsOn: applyJavaPatches) {
469
+ downloadsDir.mkdirs()
470
+ thirdPartyNdkDir.mkdirs()
471
+ }
472
+
473
+ task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) {
474
+ src("https://github.com/react-native-community/boost-for-react-native/releases/download/v${BOOST_VERSION.replace("_", ".")}-0/boost_${BOOST_VERSION}.tar.gz")
475
+ onlyIfNewer(true)
476
+ overwrite(false)
477
+ dest(new File(downloadsDir, "boost_${BOOST_VERSION}.tar.gz"))
478
+ }
479
+
480
+ task prepareBoost(dependsOn: boostPath ? [] : [downloadBoost], type: Copy) {
481
+ from(boostPath ?: tarTree(resources.gzip(downloadBoost.dest)))
482
+ from("$reactNativeThirdParty/boost/Android.mk")
483
+ include("Android.mk", "boost_${BOOST_VERSION}/boost/**/*.hpp", "boost/boost/**/*.hpp")
484
+ includeEmptyDirs = false
485
+ into("$thirdPartyNdkDir/boost")
486
+ doLast {
487
+ file("$thirdPartyNdkDir/boost/boost").renameTo("$thirdPartyNdkDir/boost/boost_${BOOST_VERSION}")
488
+ }
489
+ }
490
+
491
+ task downloadDoubleConversion(dependsOn: createNativeDepsDirectories, type: Download) {
492
+ src("https://github.com/google/double-conversion/archive/v${DOUBLE_CONVERSION_VERSION}.tar.gz")
493
+ onlyIfNewer(true)
494
+ overwrite(false)
495
+ dest(new File(downloadsDir, "double-conversion-${DOUBLE_CONVERSION_VERSION}.tar.gz"))
496
+ }
497
+
498
+ task prepareDoubleConversion(dependsOn: dependenciesPath ? [] : [downloadDoubleConversion], type: Copy) {
499
+ from(dependenciesPath ?: tarTree(downloadDoubleConversion.dest))
500
+ from("$reactNativeThirdParty/double-conversion/Android.mk")
501
+ include("double-conversion-${DOUBLE_CONVERSION_VERSION}/src/**/*", "Android.mk")
502
+ filesMatching("*/src/**/*", { fname -> fname.path = "double-conversion/${fname.name}" })
503
+ includeEmptyDirs = false
504
+ into("$thirdPartyNdkDir/double-conversion")
505
+ }
506
+
507
+ task downloadFolly(dependsOn: createNativeDepsDirectories, type: Download) {
508
+ src("https://github.com/facebook/folly/archive/v${FOLLY_VERSION}.tar.gz")
509
+ onlyIfNewer(true)
510
+ overwrite(false)
511
+ dest(new File(downloadsDir, "folly-${FOLLY_VERSION}.tar.gz"))
512
+ }
513
+
514
+ task prepareFolly(dependsOn: dependenciesPath ? [] : [downloadFolly], type: Copy) {
515
+ from(dependenciesPath ?: tarTree(downloadFolly.dest))
516
+ from("$reactNativeThirdParty/folly/Android.mk")
517
+ include("folly-${FOLLY_VERSION}/folly/**/*", "Android.mk")
518
+ eachFile { fname -> fname.path = (fname.path - "folly-${FOLLY_VERSION}/") }
519
+ // Fixes problem with Folly failing to build on certain systems. See
520
+ // https://github.com/software-mansion/react-native-reanimated/issues/1024
521
+ filter { line -> line.replaceAll("return int\\(wrapNoInt\\(open, name, flags, mode\\)\\);", follyReplaceContent) }
522
+ includeEmptyDirs = false
523
+ into("$thirdPartyNdkDir/folly")
524
+ }
525
+
526
+ task downloadGlog(dependsOn: createNativeDepsDirectories, type: Download) {
527
+ src("https://github.com/google/glog/archive/v${GLOG_VERSION}.tar.gz")
528
+ onlyIfNewer(true)
529
+ overwrite(false)
530
+ dest(new File(downloadsDir, "glog-${GLOG_VERSION}.tar.gz"))
531
+ }
532
+
533
+ // Prepare glog sources to be compiled, this task will perform steps that normally should've been
534
+ // executed by automake. This way we can avoid dependencies on make/automake
535
+ task prepareGlog(dependsOn: dependenciesPath ? [] : [downloadGlog], type: Copy) {
536
+ duplicatesStrategy = "include"
537
+ from(dependenciesPath ?: tarTree(downloadGlog.dest))
538
+ from("$reactNativeThirdParty/glog/")
539
+ include("glog-${GLOG_VERSION}/src/**/*", "Android.mk", "config.h")
540
+ includeEmptyDirs = false
541
+ filesMatching("**/*.h.in") {
542
+ filter(ReplaceTokens, tokens: [
543
+ ac_cv_have_unistd_h : "1",
544
+ ac_cv_have_stdint_h : "1",
545
+ ac_cv_have_systypes_h : "1",
546
+ ac_cv_have_inttypes_h : "1",
547
+ ac_cv_have_libgflags : "0",
548
+ ac_google_start_namespace : "namespace google {",
549
+ ac_cv_have_uint16_t : "1",
550
+ ac_cv_have_u_int16_t : "1",
551
+ ac_cv_have___uint16 : "0",
552
+ ac_google_end_namespace : "}",
553
+ ac_cv_have___builtin_expect : "1",
554
+ ac_google_namespace : "google",
555
+ ac_cv___attribute___noinline : "__attribute__ ((noinline))",
556
+ ac_cv___attribute___noreturn : "__attribute__ ((noreturn))",
557
+ ac_cv___attribute___printf_4_5: "__attribute__((__format__ (__printf__, 4, 5)))"
558
+ ])
559
+ it.path = (it.name - ".in")
560
+ }
561
+ into("$thirdPartyNdkDir/glog")
562
+
563
+ doLast {
564
+ copy {
565
+ from(fileTree(dir: "$thirdPartyNdkDir/glog", includes: ["stl_logging.h", "logging.h", "raw_logging.h", "vlog_is_on.h", "**/src/glog/log_severity.h"]).files)
566
+ includeEmptyDirs = false
567
+ into("$thirdPartyNdkDir/glog/exported/glog")
568
+ }
569
+ }
570
+ }
571
+
572
+ task prepareHermes() {
573
+ def hermesPackagePath = findNodeModulePath(projectDir, "hermes-engine")
574
+ if (!hermesPackagePath) {
575
+ throw new GradleScriptException("Could not find the hermes-engine npm package", null)
576
+ }
577
+
578
+ def hermesAAR = file("$hermesPackagePath/android/hermes-debug.aar")
579
+ if (!hermesAAR.exists()) {
580
+ throw new GradleScriptException("The hermes-engine npm package is missing \"android/hermes-debug.aar\"", null)
581
+ }
582
+
583
+ def soFiles = zipTree(hermesAAR).matching({ it.include "**/*.so" })
584
+
585
+ copy {
586
+ from soFiles
587
+ from "$reactNative/ReactAndroid/src/main/jni/first-party/hermes/Android.mk"
588
+ into "$thirdPartyNdkDir/hermes"
589
+ }
590
+ }
591
+
592
+ task prepareJSC {
593
+ doLast {
594
+ def jscPackagePath = findNodeModulePath(projectDir, "jsc-android")
595
+ if (!jscPackagePath) {
596
+ throw new GradleScriptException("Could not find the jsc-android npm package", null)
597
+ }
598
+
599
+ def jscDist = file("$jscPackagePath/dist")
600
+ if (!jscDist.exists()) {
601
+ throw new GradleScriptException("The jsc-android npm package is missing its \"dist\" directory", null)
602
+ }
603
+
604
+ def jscAAR = fileTree(jscDist).matching({ it.include "**/android-jsc/**/*.aar" }).singleFile
605
+ def soFiles = zipTree(jscAAR).matching({ it.include "**/*.so" })
606
+
607
+ def headerFiles = fileTree(jscDist).matching({ it.include "**/include/*.h" })
608
+
609
+ copy {
610
+ from(soFiles)
611
+ from(headerFiles)
612
+ from("$reactNative/ReactAndroid/src/main/jni/third-party/jsc/Android.mk")
613
+
614
+ filesMatching("**/*.h", { it.path = "JavaScriptCore/${it.name}" })
615
+
616
+ includeEmptyDirs(false)
617
+ into("$thirdPartyNdkDir/jsc")
618
+ }
619
+ }
620
+ }
621
+
622
+ task extractAARHeaders {
623
+ doLast {
624
+ configurations.extractHeaders.files.each {
625
+ def file = it.absoluteFile
626
+ def packageName = file.name.tokenize('-')[0]
627
+ copy {
628
+ from zipTree(file)
629
+ into "$reactNative/ReactAndroid/src/main/jni/first-party/$packageName/headers"
630
+ include "**/*.h"
631
+ }
632
+ }
633
+ }
634
+ }
635
+
636
+ task extractSOFiles {
637
+ doLast {
638
+ configurations.extractSO.files.each {
639
+ def file = it.absoluteFile
640
+ def packageName = file.name.tokenize('-')[0]
641
+ copy {
642
+ from zipTree(file)
643
+ into "$reactNative/ReactAndroid/src/main/jni/first-party/$packageName/"
644
+ include "jni/**/*.so"
645
+ }
646
+ }
647
+ }
648
+ }
649
+
650
+ task packageNdkLibs(type: Copy) {
651
+ from("$buildDir/reanimated-ndk/all")
652
+ include("**/libreanimated.so")
653
+ if(REACT_VERSION < 64) {
654
+ include("**/libturbomodulejsijni.so")
655
+ }
656
+ into("$projectDir/src/main/jniLibs")
657
+ }
658
+
659
+ repositories {
660
+ mavenCentral()
661
+ mavenLocal()
662
+ maven {
663
+ // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
664
+ url "$reactNative/android"
665
+ }
666
+ maven {
667
+ // Android JSC is installed from npm
668
+ url "$reactNative/../jsc-android/dist"
669
+ }
670
+ google()
671
+ }
672
+
673
+ dependencies {
674
+ // noinspection GradleDynamicVersion
675
+ implementation "com.facebook.yoga:proguard-annotations:1.19.0"
676
+ if (isDeveloperMode()) {
677
+ implementation "com.facebook.fbjni:fbjni:" + FBJNI_VERSION
678
+ }
679
+ else {
680
+ implementation "com.facebook.fbjni:fbjni-java-only:" + FBJNI_VERSION
681
+ }
682
+ implementation "com.facebook.react:react-native:+" // From node_modules
683
+ implementation "androidx.transition:transition:1.1.0"
684
+ extractHeaders("com.facebook.fbjni:fbjni:" + FBJNI_VERSION + ":headers")
685
+ extractSO("com.facebook.fbjni:fbjni:" + FBJNI_VERSION)
686
+
687
+ def rnAAR = fileTree("$reactNative/android").matching({ it.include "**/**/*.aar" }).singleFile
688
+ def jscAAR = fileTree("$reactNative/../jsc-android/dist/org/webkit/android-jsc").matching({ it.include "**/**/*.aar" }).singleFile
689
+ extractSO(files(rnAAR, jscAAR))
690
+ }
691
+
692
+ task downloadNdkBuildDependencies {
693
+ if (!boostPath) {
694
+ dependsOn(downloadBoost)
695
+ }
696
+ dependsOn(downloadDoubleConversion)
697
+ dependsOn(downloadFolly)
698
+ dependsOn(downloadGlog)
699
+ }
700
+
701
+ task prepareThirdPartyNdkHeaders(dependsOn:[downloadNdkBuildDependencies, prepareBoost, prepareDoubleConversion, prepareFolly, prepareGlog]) {
702
+ }
703
+
704
+ tasks.whenTaskAdded { task ->
705
+ if (
706
+ task.name.contains("externalNativeBuild")
707
+ || task.name.contains("buildCMake")
708
+ ) {
709
+ task.dependsOn(prepareThirdPartyNdkHeaders)
710
+ extractAARHeaders.dependsOn(prepareThirdPartyNdkHeaders)
711
+ extractSOFiles.dependsOn(prepareThirdPartyNdkHeaders)
712
+ task.dependsOn(extractAARHeaders)
713
+ task.dependsOn(extractSOFiles)
714
+ }
715
+ }
716
+
717
+ if (CLIENT_SIDE_BUILD) {
718
+ def aarDir = "${buildDir}/outputs"
719
+ aar = file("${aarDir}/android-debug.aar")
720
+ if (aar == null) {
721
+ throw GradleScriptException("AAR build failed. No AAR found in ${aarDir}.")
722
+ }
723
+ artifacts.add("default", aar)
724
+ }