Skip to content

Commit b262ccd

Browse files
authored
Merge pull request #3 from mrousavy/android
Try support android
2 parents 9974835 + f3191c9 commit b262ccd

26 files changed

+1023
-241
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,7 @@ android/keystores/debug.keystore
5959
# generated by bob
6060
lib/
6161

62-
6362
.cxx/
63+
.externalNativeBuild/
64+
native_prebuilt
65+
ndk-deps

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ console.log(`Fibonacci Result: ${result}`)
102102

103103
* You can run any JavaScript code you want in there.
104104
* You can use variables from "outside" (e.g. state), but those will be immutable/frozen.
105-
* You can use functions from "outside".
105+
* You can use functions from "outside".
106106
- Worklets (functions with the `'worklet'` directive) can be called directly on the separate thread
107107
- Normal JS functions (e.g. setState) can be called on the React-JS thread with `runOnJS`
108108
- Native JSI functions ("host functions") can be called synchronously (e.g. functions from [react-native-mmkv](https://github.com/mrousavy/react-native-mmkv#usage))
@@ -129,6 +129,10 @@ Be aware that there always will be a small overhead when calling `spawnThread`,
129129
## Credits
130130

131131
* [react-native-reanimated](http://github.com/software-mansion/react-native-reanimated) for Shared Value adapting, essentially allowing JSI multithreading
132+
* [**@karol-bisztyga**](https://github.com/karol-bisztyga) and [**@piaskowyk**](https://github.com/piaskowyk) for helping me understand a few parts of Reanimated better
133+
* [**@Szymon20000**](https://github.com/Szymon20000) for taking time to review and merge my Reanimated PRs
134+
* [JNI tips](https://developer.android.com/training/articles/perf-jni) and [fbjni](https://github.com/facebookincubator/fbjni) to make Android JNI interop easier
135+
* [**@iamyellow**](https://github.com/iamyellow) for being a huge help on the Android side
132136
* [Erik the Coder](https://www.erikthecoder.net/2019/03/30/async-does-not-imply-concurrent/) for the Icon
133137
* You, for appreciating my work
134138

android/CMakeLists.txt

Lines changed: 89 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,102 @@
11
cmake_minimum_required(VERSION 3.4.1)
22

33
set (CMAKE_VERBOSE_MAKEFILE ON)
4-
set (CMAKE_CXX_STANDARD 11)
4+
set (CMAKE_CXX_STANDARD 14)
5+
set (CMAKE_CXX_FLAGS "-DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_HAVE_MEMRCHR=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_MOBILE=1 -DON_ANDROID")
56

6-
add_library(rnmultithreading
7-
SHARED
8-
# ../cpp/RNMultithreadingInstaller.cpp
9-
cpp-adapter.cpp
10-
../../react-native/ReactCommon/jsi/jsi/jsi.cpp
11-
# ../../react-native-reanimated/android/src/main/cpp/AndroidErrorHandler.cpp
12-
# ../../react-native-reanimated/android/src/main/cpp/AndroidScheduler.cpp
7+
set (PACKAGE_NAME "rnmultithreading")
8+
set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
9+
10+
# rnmultithreading shared
11+
12+
add_library(
13+
${PACKAGE_NAME}
14+
SHARED
15+
src/main/cpp/cpp-adapter.cpp
16+
../cpp/RNMultithreadingInstaller.cpp
17+
../cpp/ThreadPool.cpp
1318
)
1419

15-
# Specifies a path to native header files.
16-
include_directories(
17-
../cpp
18-
../../react-native/React
19-
../../react-native/React/Base
20-
../../react-native/ReactCommon/jsi
21-
# ../../react-native-reanimated/android/src/main/cpp/headers
22-
# ../../react-native-reanimated/Common/cpp/headers
23-
# ../../react-native-reanimated/Common/cpp/hidden_headers
20+
# includes
21+
22+
file (GLOB LIBFBJNI_INCLUDE_DIR "${BUILD_DIR}/fbjni-*-headers.jar/")
23+
24+
target_include_directories(
25+
${PACKAGE_NAME}
26+
PRIVATE
27+
${LIBFBJNI_INCLUDE_DIR}
28+
${BUILD_DIR}/third-party-ndk/boost
29+
${BUILD_DIR}/third-party-ndk/double-conversion
30+
${BUILD_DIR}/third-party-ndk/folly
31+
${BUILD_DIR}/third-party-ndk/glog
32+
"${NODE_MODULES_DIR}/react-native/React"
33+
"${NODE_MODULES_DIR}/react-native/React/Base"
34+
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni"
35+
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni"
36+
"${NODE_MODULES_DIR}/react-native/ReactCommon"
37+
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
38+
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
39+
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
40+
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/Tools"
41+
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/SpecTools"
42+
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/SharedItems"
43+
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/Registries"
44+
"${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/hidden_headers"
45+
"../cpp"
2446
)
2547

48+
# find libraries
49+
50+
file (GLOB LIBRN_DIR "${BUILD_DIR}/react-native-0*/jni/${ANDROID_ABI}")
51+
file (GLOB LIBJSC_DIR "${BUILD_DIR}/android-jsc*.aar/jni/${ANDROID_ABI}")
52+
file (GLOB LIBREANIMATED_DIR "${BUILD_DIR}/react-native-reanimated-*.aar/jni/${ANDROID_ABI}")
53+
54+
2655
find_library(
27-
log-lib
56+
LOG_LIB
2857
log
2958
)
59+
find_library(
60+
FBJNI_LIB
61+
fbjni
62+
PATHS ${LIBRN_DIR}
63+
NO_CMAKE_FIND_ROOT_PATH
64+
)
65+
find_library(
66+
JSEXECUTOR_LIB
67+
jscexecutor
68+
PATHS ${LIBRN_DIR}
69+
NO_CMAKE_FIND_ROOT_PATH
70+
)
71+
find_library(
72+
JSC_LIB
73+
jsc
74+
PATHS ${LIBJSC_DIR}
75+
NO_CMAKE_FIND_ROOT_PATH
76+
)
77+
find_library(
78+
REANIMATED_LIB
79+
reanimated
80+
PATHS ${LIBREANIMATED_DIR}
81+
NO_CMAKE_FIND_ROOT_PATH
82+
)
3083

31-
target_link_libraries(rnmultithreading
32-
${log-lib}
33-
android
84+
# linking
85+
86+
find_library(
87+
FBJNI_LIBRARY fbjni
88+
PATHS ${libfbjni_link_DIRS}
89+
NO_CMAKE_FIND_ROOT_PATH
3490
)
91+
92+
# build shared lib
93+
94+
target_link_libraries(
95+
${PACKAGE_NAME}
96+
${LOG_LIB}
97+
${REANIMATED_LIB}
98+
${JSC_LIB}
99+
${JSEXECUTOR_LIB}
100+
${FBJNI_LIB}
101+
android
102+
)

0 commit comments

Comments
 (0)