Skip to content

Commit 2f76010

Browse files
authored
Merge pull request #37 from MasonLe2497/feat/turbo_module
feat(all): add support new arch
2 parents 7aef34d + eeb7f84 commit 2f76010

File tree

86 files changed

+6599
-8730
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+6599
-8730
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jsconfig.json
1111

1212
# Xcode
1313
#
14+
.cxx/
1415
build/
1516
*.pbxuser
1617
!default.pbxuser
@@ -28,7 +29,7 @@ DerivedData
2829
*.ipa
2930
*.xcuserstate
3031
project.xcworkspace
31-
32+
ios/privateKey.m
3233
# Android/IJ
3334
#
3435
.idea
@@ -60,6 +61,5 @@ android/keystores/debug.keystore
6061

6162
# generated by bob
6263
lib/
63-
6464
**prebuild.log
6565
example/ios/tmp.xcconfig

README.md

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Keep in mind It's [basically impossible to prevent users from reverse engineerin
120120
Install the package:
121121

122122
```
123-
$ yarn add react-native-keys
123+
yarn add react-native-keys
124124
```
125125

126126
Link the library:
@@ -130,7 +130,7 @@ Link the library:
130130
or later. For earlier versions you need to manually link the module.)
131131

132132
```
133-
$ react-native link react-native-keys
133+
react-native link react-native-keys
134134
```
135135

136136
if cocoapods are used in the project then pod has to be installed as well:
@@ -145,12 +145,12 @@ if cocoapods are used in the project then pod has to be installed as well:
145145
146146
- Manual Link (iOS)
147147

148-
1. In XCode, in the project navigator, right click `Libraries``Add Files to [your project's name]`
149-
2. Go to `node_modules``react-native-keys` and add `Keys.xcodeproj`
150-
3. Expand the `Keys.xcodeproj``Products` folder
151-
4. In the project navigator, select your project. Add `Keys.a` to your project's `Build Phases``Link Binary With Libraries`
152-
5. And go the Build Settings tab. Make sure All is toggled on (instead of Basic)
153-
6. Look for Header Search Paths and add `$(SRCROOT)/../node_modules/react-native-keys/ios/**` as `non-recursive`
148+
1. In XCode, in the project navigator, right click `Libraries``Add Files to [your project's name]`
149+
2. Go to `node_modules``react-native-keys` and add `Keys.xcodeproj`
150+
3. Expand the `Keys.xcodeproj``Products` folder
151+
4. In the project navigator, select your project. Add `Keys.a` to your project's `Build Phases``Link Binary With Libraries`
152+
5. And go the Build Settings tab. Make sure All is toggled on (instead of Basic)
153+
6. Look for Header Search Paths and add `$(SRCROOT)/../node_modules/react-native-keys/ios/**` as `non-recursive`
154154

155155
- Manual Link (Android)
156156

@@ -165,8 +165,8 @@ if cocoapods are used in the project then pod has to be installed as well:
165165

166166
```diff
167167
dependencies {
168-
implementation "com.facebook.react:react-native:+" // From node_modules
169-
+ implementation project(':react-native-keys')
168+
implementation "com.facebook.react:react-native:+" // From node_modules
169+
+ implementation project(':react-native-keys')
170170
}
171171
```
172172

@@ -177,9 +177,9 @@ if cocoapods are used in the project then pod has to be installed as well:
177177

178178
@Override
179179
protected List<ReactPackage> getPackages() {
180-
return Arrays.asList(
181-
new MainReactPackage()
182-
+ new KeysPackage()
180+
return Arrays.asList(
181+
new MainReactPackage()
182+
+ new KeysPackage()
183183
);
184184
}
185185
```
@@ -196,7 +196,7 @@ you can only read jni key into java file.like this
196196
URL url = new URL(BuildConfig.API_URL); // https://example.com
197197
```
198198

199-
You can also read them from your Gradle configuration:
199+
You can also read them from your Gradle configuration(only public keys):
200200

201201
```groovy
202202
defaultConfig {
@@ -218,12 +218,24 @@ All variables are strings, so you may need to cast them. For instance, in Gradle
218218
versionCode project.keys.get("VERSION_CODE").toInteger()
219219
```
220220

221+
#### Advanced Android Setup
222+
223+
In `android/app/build.gradle`, if you use `applicationIdSuffix` or `applicationId` that is different from the package name indicated in `AndroidManifest.xml` in `<manifest package="...">` tag, for example, to support different build variants:
224+
Add this in `android/app/build.gradle`
225+
226+
```
227+
defaultConfig {
228+
...
229+
resValue "string", "build_config_package", "YOUR_PACKAGE_NAME_IN_ANDROIDMANIFEST_XML_OR_YOUR_NAME_SPACE"
230+
}
231+
```
232+
221233
#### Secure Keys (JNI)
222234

223235
```java
224236
import static com.reactnativekeysjsi.KeysModule.getSecureFor;
225237

226-
String secureValue=getSecureFor("BRANCH_KEY"); // key_test_omQ7YYKiq57vOqEJsdcsdfeEsiWkwxE
238+
String secureValue = getSecureFor("BRANCH_KEY"); // key_test_omQ7YYKiq57vOqEJsdcsdfeEsiWkwxE
227239
```
228240

229241
### iOS
@@ -286,10 +298,19 @@ ios/tmp.xcconfig
286298

287299
- Go to _Edit scheme..._ -> _Build_ -> _Pre-actions_, click _+_ and select _New Run Script Action_. Paste below code which will generate KEYS keys on native ios side (into node*modules) Make sure to select your target under \_Provide build settings from*, so `$SRCROOT` environment variables is available to the script.
288300

289-
```
301+
```sh
290302
"${SRCROOT}/../node_modules/react-native-keys/keysIOS.js"
291303
```
292304

305+
Alternatively, you can define a map in `Pre-actions` associating builds with env files:
306+
307+
```sh
308+
export KEYSFILE = "path_to_env"
309+
"${SRCROOT}/../node_modules/react-native-keys/keysIOS.js"
310+
```
311+
312+
call, and use build cases in lowercase, like:
313+
293314
### Different environments
294315

295316
Save config for different environments in different files: `keys.staging.json`, `keys.production.json`, etc.
@@ -299,9 +320,9 @@ By default react-native-keys will read from `keys.development.json`, but you can
299320
The simplest approach is to tell it what file to read with an environment variable, like:
300321

301322
```
302-
$ KEYSFILE=keys.staging.json react-native run-ios # bash
303-
$ SET KEYSFILE=keys.staging.json && react-native run-ios # windows
304-
$ env:KEYSFILE="keys.staging.json"; react-native run-ios # powershell
323+
KEYSFILE=keys.staging.json react-native run-ios # bash
324+
SET KEYSFILE=keys.staging.json && react-native run-ios # windows
325+
env:KEYSFILE="keys.staging.json"; react-native run-ios # powershell
305326
```
306327

307328
This also works for `run-android`. Alternatively, there are platform-specific options below.
@@ -310,13 +331,13 @@ This also works for `run-android`. Alternatively, there are platform-specific op
310331

311332
The same environment variable can be used to assemble releases with a different config:
312333

313-
```
314-
$ cd android && KEYSFILE=keys.staging.json ./gradlew assembleRelease
334+
```sh
335+
cd android && KEYSFILE=keys.staging.json ./gradlew assembleRelease
315336
```
316337

317338
Alternatively, you can define a map in `build.gradle` associating builds with env files. Do it before the `apply from` call, and use build cases in lowercase, like:
318339

319-
```
340+
```groovy
320341
project.ext.keyFiles = [
321342
debug: "keys.development.json",
322343
release: "keys.staging.json",
@@ -330,7 +351,7 @@ apply from: project(':react-native-keys').projectDir.getPath() + "/RNKeys.gradle
330351
In `android/app/build.gradle`, if you use `applicationIdSuffix` or `applicationId` that is different from the package name indicated in `AndroidManifest.xml` in `<manifest package="...">` tag, for example, to support different build variants:
331352
Add this in `android/app/build.gradle`
332353

333-
```
354+
```groovy
334355
defaultConfig {
335356
...
336357
resValue "string", "build_config_package", "YOUR_PACKAGE_NAME_IN_ANDROIDMANIFEST_XML"

android/CMakeLists.txt

Lines changed: 71 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -7,97 +7,88 @@ set(CMAKE_CXX_STANDARD 17)
77
set(BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
88

99
if(${REACT_NATIVE_MINOR_VERSION} GREATER_EQUAL 71)
10-
# Consume shared libraries and headers from prefabs
11-
find_package(fbjni REQUIRED CONFIG)
12-
find_package(ReactAndroid REQUIRED CONFIG)
10+
# Consume shared libraries and headers from prefabs
11+
find_package(ReactAndroid REQUIRED CONFIG)
1312

14-
include_directories(
15-
${PACKAGE_NAME}
16-
"${NODE_MODULES_DIR}/react-native/React"
17-
"${NODE_MODULES_DIR}/react-native/React/Base"
18-
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
19-
"./androidcpp"
20-
"../cpp"
21-
${FOLLY_INCLUDE_DIR}
22-
"."
23-
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni/react/turbomodule"
24-
)
13+
include_directories(
14+
${PACKAGE_NAME}
15+
"./androidcpp"
16+
"../cpp"
17+
)
2518

26-
file(GLOB LIBRN_DIR "${BUILD_DIR}/react-native-0*/jni/${ANDROID_ABI}")
27-
message(STATUS "LIBRN_DIR: ${LIBRN_DIR}")
19+
file(GLOB LIBRN_DIR "${BUILD_DIR}/react-native-0*/jni/${ANDROID_ABI}")
20+
message(STATUS "LIBRN_DIR: ${LIBRN_DIR}")
2821

29-
add_library(
30-
${PACKAGE_NAME}
31-
SHARED
32-
./androidcpp/mediator.cpp
33-
./cpp-adapter.cpp
34-
../cpp/crypto.cpp
35-
../cpp/decryptor.cpp
36-
)
22+
add_library(
23+
${PACKAGE_NAME}
24+
SHARED
25+
./androidcpp/mediator.cpp
26+
./cpp-adapter.cpp
27+
../cpp/crypto.cpp
28+
../cpp/decryptor.cpp
29+
)
3730

38-
find_library(
39-
LOG_LIB
40-
log
41-
)
31+
find_library(
32+
LOG_LIB
33+
log
34+
)
4235

43-
find_library(
44-
REACT_NATIVE_JNI_LIB
45-
reactnativejni
46-
PATHS ${LIBRN_DIR}
47-
NO_CMAKE_FIND_ROOT_PATH
48-
)
36+
find_library(
37+
REACT_NATIVE_JNI_LIB
38+
reactnativejni
39+
PATHS ${LIBRN_DIR}
40+
NO_CMAKE_FIND_ROOT_PATH
41+
)
4942

50-
set_target_properties(
51-
${PACKAGE_NAME} PROPERTIES
52-
CXX_STANDARD 17
53-
CXX_EXTENSIONS OFF
54-
POSITION_INDEPENDENT_CODE ON
55-
)
43+
set_target_properties(
44+
${PACKAGE_NAME} PROPERTIES
45+
CXX_STANDARD 17
46+
CXX_EXTENSIONS OFF
47+
POSITION_INDEPENDENT_CODE ON
48+
)
5649

57-
find_package(openssl REQUIRED CONFIG)
50+
find_package(openssl REQUIRED CONFIG)
5851

59-
target_link_libraries(
60-
${PACKAGE_NAME}
61-
ReactAndroid::turbomodulejsijni
62-
fbjni::fbjni
63-
${LOG_LIB}
64-
ReactAndroid::jsi
65-
ReactAndroid::reactnativejni
66-
ReactAndroid::react_nativemodule_core
67-
android
68-
openssl::crypto
69-
)
52+
target_link_libraries(
53+
${PACKAGE_NAME}
54+
${LOG_LIB}
55+
ReactAndroid::jsi
56+
ReactAndroid::reactnativejni
57+
ReactAndroid::react_nativemodule_core
58+
android
59+
openssl::crypto
60+
)
7061
else()
71-
add_library(
72-
${PACKAGE_NAME}
73-
SHARED
74-
../../react-native/ReactCommon/jsi/jsi/jsi.cpp
75-
./androidcpp/mediator.cpp
76-
./cpp-adapter.cpp
77-
../cpp/crypto.cpp
78-
../cpp/decryptor.cpp
79-
)
62+
add_library(
63+
${PACKAGE_NAME}
64+
SHARED
65+
../../react-native/ReactCommon/jsi/jsi/jsi.cpp
66+
./androidcpp/mediator.cpp
67+
./cpp-adapter.cpp
68+
../cpp/crypto.cpp
69+
../cpp/decryptor.cpp
70+
)
8071

81-
include_directories(
82-
../../react-native/React
83-
../../react-native/React/Base
84-
../../react-native/ReactCommon/jsi
85-
./cpp
86-
../cpp
87-
)
72+
include_directories(
73+
../../react-native/React
74+
../../react-native/React/Base
75+
../../react-native/ReactCommon/jsi
76+
./cpp
77+
../cpp
78+
)
8879

89-
set_target_properties(
90-
${PACKAGE_NAME} PROPERTIES
91-
CXX_STANDARD 17
92-
CXX_EXTENSIONS OFF
93-
POSITION_INDEPENDENT_CODE ON
94-
)
80+
set_target_properties(
81+
${PACKAGE_NAME} PROPERTIES
82+
CXX_STANDARD 17
83+
CXX_EXTENSIONS OFF
84+
POSITION_INDEPENDENT_CODE ON
85+
)
9586

96-
find_package(openssl REQUIRED CONFIG)
87+
find_package(openssl REQUIRED CONFIG)
9788

98-
target_link_libraries(
99-
${PACKAGE_NAME}
100-
android
101-
openssl::crypto
102-
)
89+
target_link_libraries(
90+
${PACKAGE_NAME}
91+
android
92+
openssl::crypto
93+
)
10394
endif()

0 commit comments

Comments
 (0)