Skip to content

Commit

Permalink
feat(all): add support new arch
Browse files Browse the repository at this point in the history
  • Loading branch information
ngocle2497 committed Aug 7, 2023
1 parent a846d04 commit eeb7f84
Show file tree
Hide file tree
Showing 86 changed files with 6,599 additions and 8,730 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jsconfig.json

# Xcode
#
.cxx/
build/
*.pbxuser
!default.pbxuser
Expand All @@ -28,7 +29,7 @@ DerivedData
*.ipa
*.xcuserstate
project.xcworkspace

ios/privateKey.m
# Android/IJ
#
.idea
Expand Down Expand Up @@ -60,6 +61,5 @@ android/keystores/debug.keystore

# generated by bob
lib/

**prebuild.log
example/ios/tmp.xcconfig
67 changes: 44 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Keep in mind It's [basically impossible to prevent users from reverse engineerin
Install the package:

```
$ yarn add react-native-keys
yarn add react-native-keys
```

Link the library:
Expand All @@ -123,7 +123,7 @@ Link the library:
or later. For earlier versions you need to manually link the module.)

```
$ react-native link react-native-keys
react-native link react-native-keys
```

if cocoapods are used in the project then pod has to be installed as well:
Expand All @@ -138,12 +138,12 @@ if cocoapods are used in the project then pod has to be installed as well:
- Manual Link (iOS)

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

- Manual Link (Android)

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

```diff
dependencies {
implementation "com.facebook.react:react-native:+" // From node_modules
+ implementation project(':react-native-keys')
implementation "com.facebook.react:react-native:+" // From node_modules
+ implementation project(':react-native-keys')
}
```

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

@Override
protected List<ReactPackage> getPackages() {
return Arrays.asList(
new MainReactPackage()
+ new KeysPackage()
return Arrays.asList(
new MainReactPackage()
+ new KeysPackage()
);
}
```
Expand All @@ -189,7 +189,7 @@ you can only read jni key into java file.like this
URL url = new URL(BuildConfig.API_URL); // https://example.com
```

You can also read them from your Gradle configuration:
You can also read them from your Gradle configuration(only public keys):

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

#### Advanced Android Setup

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:
Add this in `android/app/build.gradle`

```
defaultConfig {
...
resValue "string", "build_config_package", "YOUR_PACKAGE_NAME_IN_ANDROIDMANIFEST_XML_OR_YOUR_NAME_SPACE"
}
```

#### Secure Keys (JNI)

```java
import static com.reactnativekeysjsi.KeysModule.getSecureFor;

String secureValue=getSecureFor("BRANCH_KEY"); // key_test_omQ7YYKiq57vOqEJsdcsdfeEsiWkwxE
String secureValue = getSecureFor("BRANCH_KEY"); // key_test_omQ7YYKiq57vOqEJsdcsdfeEsiWkwxE
```

### iOS
Expand Down Expand Up @@ -279,10 +291,19 @@ ios/tmp.xcconfig

- 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.

```
```sh
"${SRCROOT}/../node_modules/react-native-keys/keysIOS.js"
```

Alternatively, you can define a map in `Pre-actions` associating builds with env files:

```sh
export KEYSFILE = "path_to_env"
"${SRCROOT}/../node_modules/react-native-keys/keysIOS.js"
```

call, and use build cases in lowercase, like:

### Different environments

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

```
$ KEYSFILE=keys.staging.json react-native run-ios # bash
$ SET KEYSFILE=keys.staging.json && react-native run-ios # windows
$ env:KEYSFILE="keys.staging.json"; react-native run-ios # powershell
KEYSFILE=keys.staging.json react-native run-ios # bash
SET KEYSFILE=keys.staging.json && react-native run-ios # windows
env:KEYSFILE="keys.staging.json"; react-native run-ios # powershell
```

This also works for `run-android`. Alternatively, there are platform-specific options below.
Expand All @@ -303,13 +324,13 @@ This also works for `run-android`. Alternatively, there are platform-specific op

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

```
$ cd android && KEYSFILE=keys.staging.json ./gradlew assembleRelease
```sh
cd android && KEYSFILE=keys.staging.json ./gradlew assembleRelease
```

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:

```
```groovy
project.ext.keyFiles = [
debug: "keys.development.json",
release: "keys.staging.json",
Expand All @@ -323,7 +344,7 @@ apply from: project(':react-native-keys').projectDir.getPath() + "/RNKeys.gradle
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:
Add this in `android/app/build.gradle`

```
```groovy
defaultConfig {
...
resValue "string", "build_config_package", "YOUR_PACKAGE_NAME_IN_ANDROIDMANIFEST_XML"
Expand Down
151 changes: 71 additions & 80 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,97 +7,88 @@ set(CMAKE_CXX_STANDARD 17)
set(BUILD_DIR ${CMAKE_SOURCE_DIR}/build)

if(${REACT_NATIVE_MINOR_VERSION} GREATER_EQUAL 71)
# Consume shared libraries and headers from prefabs
find_package(fbjni REQUIRED CONFIG)
find_package(ReactAndroid REQUIRED CONFIG)
# Consume shared libraries and headers from prefabs
find_package(ReactAndroid REQUIRED CONFIG)

include_directories(
${PACKAGE_NAME}
"${NODE_MODULES_DIR}/react-native/React"
"${NODE_MODULES_DIR}/react-native/React/Base"
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
"./androidcpp"
"../cpp"
${FOLLY_INCLUDE_DIR}
"."
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni/react/turbomodule"
)
include_directories(
${PACKAGE_NAME}
"./androidcpp"
"../cpp"
)

file(GLOB LIBRN_DIR "${BUILD_DIR}/react-native-0*/jni/${ANDROID_ABI}")
message(STATUS "LIBRN_DIR: ${LIBRN_DIR}")
file(GLOB LIBRN_DIR "${BUILD_DIR}/react-native-0*/jni/${ANDROID_ABI}")
message(STATUS "LIBRN_DIR: ${LIBRN_DIR}")

add_library(
${PACKAGE_NAME}
SHARED
./androidcpp/mediator.cpp
./cpp-adapter.cpp
../cpp/crypto.cpp
../cpp/decryptor.cpp
)
add_library(
${PACKAGE_NAME}
SHARED
./androidcpp/mediator.cpp
./cpp-adapter.cpp
../cpp/crypto.cpp
../cpp/decryptor.cpp
)

find_library(
LOG_LIB
log
)
find_library(
LOG_LIB
log
)

find_library(
REACT_NATIVE_JNI_LIB
reactnativejni
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
find_library(
REACT_NATIVE_JNI_LIB
reactnativejni
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)

set_target_properties(
${PACKAGE_NAME} PROPERTIES
CXX_STANDARD 17
CXX_EXTENSIONS OFF
POSITION_INDEPENDENT_CODE ON
)
set_target_properties(
${PACKAGE_NAME} PROPERTIES
CXX_STANDARD 17
CXX_EXTENSIONS OFF
POSITION_INDEPENDENT_CODE ON
)

find_package(openssl REQUIRED CONFIG)
find_package(openssl REQUIRED CONFIG)

target_link_libraries(
${PACKAGE_NAME}
ReactAndroid::turbomodulejsijni
fbjni::fbjni
${LOG_LIB}
ReactAndroid::jsi
ReactAndroid::reactnativejni
ReactAndroid::react_nativemodule_core
android
openssl::crypto
)
target_link_libraries(
${PACKAGE_NAME}
${LOG_LIB}
ReactAndroid::jsi
ReactAndroid::reactnativejni
ReactAndroid::react_nativemodule_core
android
openssl::crypto
)
else()
add_library(
${PACKAGE_NAME}
SHARED
../../react-native/ReactCommon/jsi/jsi/jsi.cpp
./androidcpp/mediator.cpp
./cpp-adapter.cpp
../cpp/crypto.cpp
../cpp/decryptor.cpp
)
add_library(
${PACKAGE_NAME}
SHARED
../../react-native/ReactCommon/jsi/jsi/jsi.cpp
./androidcpp/mediator.cpp
./cpp-adapter.cpp
../cpp/crypto.cpp
../cpp/decryptor.cpp
)

include_directories(
../../react-native/React
../../react-native/React/Base
../../react-native/ReactCommon/jsi
./cpp
../cpp
)
include_directories(
../../react-native/React
../../react-native/React/Base
../../react-native/ReactCommon/jsi
./cpp
../cpp
)

set_target_properties(
${PACKAGE_NAME} PROPERTIES
CXX_STANDARD 17
CXX_EXTENSIONS OFF
POSITION_INDEPENDENT_CODE ON
)
set_target_properties(
${PACKAGE_NAME} PROPERTIES
CXX_STANDARD 17
CXX_EXTENSIONS OFF
POSITION_INDEPENDENT_CODE ON
)

find_package(openssl REQUIRED CONFIG)
find_package(openssl REQUIRED CONFIG)

target_link_libraries(
${PACKAGE_NAME}
android
openssl::crypto
)
target_link_libraries(
${PACKAGE_NAME}
android
openssl::crypto
)
endif()
Loading

0 comments on commit eeb7f84

Please sign in to comment.