react-native-quick-crypto 0.2.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.
- package/LICENSE +21 -0
- package/README.md +84 -0
- package/android/.DS_Store +0 -0
- package/android/CMakeLists.txt +117 -0
- package/android/build.gradle +367 -0
- package/android/gradle/.DS_Store +0 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradle.properties +6 -0
- package/android/gradlew +183 -0
- package/android/gradlew.bat +100 -0
- package/android/src/.DS_Store +0 -0
- package/android/src/main/.DS_Store +0 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/cpp/cpp-adapter.cpp +60 -0
- package/android/src/main/java/.DS_Store +0 -0
- package/android/src/main/java/com/.DS_Store +0 -0
- package/android/src/main/java/com/reactnativequickcrypto/QuickCryptoModule.java +70 -0
- package/android/src/main/java/com/reactnativequickcrypto/QuickCryptoPackage.java +26 -0
- package/cpp/.DS_Store +0 -0
- package/cpp/Cipher/MGLCipherHostObject.cpp +632 -0
- package/cpp/Cipher/MGLCipherHostObject.h +90 -0
- package/cpp/Cipher/MGLCreateCipherInstaller.cpp +74 -0
- package/cpp/Cipher/MGLCreateCipherInstaller.h +17 -0
- package/cpp/Cipher/MGLCreateDecipherInstaller.cpp +74 -0
- package/cpp/Cipher/MGLCreateDecipherInstaller.h +17 -0
- package/cpp/HMAC/MGLHmacHostObject.cpp +95 -0
- package/cpp/HMAC/MGLHmacHostObject.h +39 -0
- package/cpp/HMAC/MGLHmacInstaller.cpp +43 -0
- package/cpp/HMAC/MGLHmacInstaller.h +20 -0
- package/cpp/Hash/MGLHashHostObject.cpp +147 -0
- package/cpp/Hash/MGLHashHostObject.h +53 -0
- package/cpp/Hash/MGLHashInstaller.cpp +46 -0
- package/cpp/Hash/MGLHashInstaller.h +20 -0
- package/cpp/JSIUtils/MGLJSIMacros.h +37 -0
- package/cpp/JSIUtils/MGLSmartHostObject.cpp +43 -0
- package/cpp/JSIUtils/MGLSmartHostObject.h +46 -0
- package/cpp/JSIUtils/MGLThreadAwareHostObject.cpp +24 -0
- package/cpp/JSIUtils/MGLThreadAwareHostObject.h +43 -0
- package/cpp/JSIUtils/MGLTypedArray.cpp +325 -0
- package/cpp/JSIUtils/MGLTypedArray.h +160 -0
- package/cpp/MGLQuickCryptoHostObject.cpp +64 -0
- package/cpp/MGLQuickCryptoHostObject.h +30 -0
- package/cpp/Random/MGLRandomHostObject.cpp +89 -0
- package/cpp/Random/MGLRandomHostObject.h +27 -0
- package/cpp/Utils/MGLDispatchQueue.cpp +75 -0
- package/cpp/Utils/MGLDispatchQueue.h +55 -0
- package/cpp/Utils/logs.h +38 -0
- package/cpp/fastpbkdf2/MGLPbkdf2HostObject.cpp +164 -0
- package/cpp/fastpbkdf2/MGLPbkdf2HostObject.h +29 -0
- package/cpp/fastpbkdf2/fastpbkdf2.c +352 -0
- package/cpp/fastpbkdf2/fastpbkdf2.h +68 -0
- package/ios/.DS_Store +0 -0
- package/ios/QuickCrypto.xcodeproj/project.pbxproj +274 -0
- package/ios/QuickCryptoModule.h +5 -0
- package/ios/QuickCryptoModule.mm +42 -0
- package/lib/.DS_Store +0 -0
- package/lib/commonjs/Cipher.js +293 -0
- package/lib/commonjs/Cipher.js.map +1 -0
- package/lib/commonjs/Hash.js +102 -0
- package/lib/commonjs/Hash.js.map +1 -0
- package/lib/commonjs/Hmac.js +104 -0
- package/lib/commonjs/Hmac.js.map +1 -0
- package/lib/commonjs/NativeQuickCrypto/Cipher.js +6 -0
- package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +1 -0
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +61 -0
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -0
- package/lib/commonjs/NativeQuickCrypto/hash.js +2 -0
- package/lib/commonjs/NativeQuickCrypto/hash.js.map +1 -0
- package/lib/commonjs/NativeQuickCrypto/hmac.js +2 -0
- package/lib/commonjs/NativeQuickCrypto/hmac.js.map +1 -0
- package/lib/commonjs/NativeQuickCrypto/pbkdf2.js +2 -0
- package/lib/commonjs/NativeQuickCrypto/pbkdf2.js.map +1 -0
- package/lib/commonjs/NativeQuickCrypto/random.js +2 -0
- package/lib/commonjs/NativeQuickCrypto/random.js.map +1 -0
- package/lib/commonjs/QuickCrypto.js +35 -0
- package/lib/commonjs/QuickCrypto.js.map +1 -0
- package/lib/commonjs/Utils.js +152 -0
- package/lib/commonjs/Utils.js.map +1 -0
- package/lib/commonjs/index.js +19 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/pbkdf2.js +64 -0
- package/lib/commonjs/pbkdf2.js.map +1 -0
- package/lib/commonjs/random.js +213 -0
- package/lib/commonjs/random.js.map +1 -0
- package/lib/module/Cipher.js +287 -0
- package/lib/module/Cipher.js.map +1 -0
- package/lib/module/Hash.js +87 -0
- package/lib/module/Hash.js.map +1 -0
- package/lib/module/Hmac.js +90 -0
- package/lib/module/Hmac.js.map +1 -0
- package/lib/module/NativeQuickCrypto/Cipher.js +2 -0
- package/lib/module/NativeQuickCrypto/Cipher.js.map +1 -0
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +53 -0
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -0
- package/lib/module/NativeQuickCrypto/hash.js +2 -0
- package/lib/module/NativeQuickCrypto/hash.js.map +1 -0
- package/lib/module/NativeQuickCrypto/hmac.js +2 -0
- package/lib/module/NativeQuickCrypto/hmac.js.map +1 -0
- package/lib/module/NativeQuickCrypto/pbkdf2.js +2 -0
- package/lib/module/NativeQuickCrypto/pbkdf2.js.map +1 -0
- package/lib/module/NativeQuickCrypto/random.js +2 -0
- package/lib/module/NativeQuickCrypto/random.js.map +1 -0
- package/lib/module/QuickCrypto.js +18 -0
- package/lib/module/QuickCrypto.js.map +1 -0
- package/lib/module/Utils.js +131 -0
- package/lib/module/Utils.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/pbkdf2.js +51 -0
- package/lib/module/pbkdf2.js.map +1 -0
- package/lib/module/random.js +190 -0
- package/lib/module/random.js.map +1 -0
- package/lib/typescript/Cipher.d.ts +30 -0
- package/lib/typescript/Hash.d.ts +44 -0
- package/lib/typescript/Hmac.d.ts +37 -0
- package/lib/typescript/NativeQuickCrypto/Cipher.d.ts +22 -0
- package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts +19 -0
- package/lib/typescript/NativeQuickCrypto/hash.d.ts +6 -0
- package/lib/typescript/NativeQuickCrypto/hmac.d.ts +5 -0
- package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts +4 -0
- package/lib/typescript/NativeQuickCrypto/random.d.ts +4 -0
- package/lib/typescript/QuickCrypto.d.ts +31 -0
- package/lib/typescript/Utils.d.ts +13 -0
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/pbkdf2.d.ts +9 -0
- package/lib/typescript/random.d.ts +20 -0
- package/package.json +168 -0
- package/react-native-quick-crypto.podspec +44 -0
- package/src/Cipher.ts +322 -0
- package/src/Hash.ts +98 -0
- package/src/Hmac.ts +107 -0
- package/src/NativeQuickCrypto/Cipher.ts +25 -0
- package/src/NativeQuickCrypto/NativeQuickCrypto.ts +79 -0
- package/src/NativeQuickCrypto/hash.ts +10 -0
- package/src/NativeQuickCrypto/hmac.ts +9 -0
- package/src/NativeQuickCrypto/pbkdf2.ts +16 -0
- package/src/NativeQuickCrypto/random.ts +12 -0
- package/src/QuickCrypto.ts +23 -0
- package/src/Utils.ts +151 -0
- package/src/index.ts +1 -0
- package/src/pbkdf2.ts +96 -0
- package/src/random.ts +277 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Marc Rousavy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# ⚡️ react-native-quick-crypto
|
|
2
|
+
|
|
3
|
+
A fast implementation of Node's `crypto` module written in C/C++ JSI.
|
|
4
|
+
|
|
5
|
+
QuickCrypto can be used as a drop-in replacement for your Web3/Crypto apps to speed up all cryptography functions.
|
|
6
|
+
|
|
7
|
+
For example, creating a Wallet using ethers.js uses complex algorithms to generate a private-key/mnemonic-phrase pair:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const start = performance.now()
|
|
11
|
+
const wallet = ethers.Wallet.createRandom()
|
|
12
|
+
const end = performance.now()
|
|
13
|
+
console.log(`Creating a Wallet took ${end - start}ms.`)
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
**Without** react-native-crypto 🐢:
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
Creating a Wallet took 31.3582738422ms
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**With** react-native-crypto ⚡️:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
Creating a Wallet took 2.47425001859ms
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
### React Native
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
yarn add react-native-quick-crypto
|
|
36
|
+
cd ios && pod install
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Expo
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
expo install react-native-quick-crypto
|
|
43
|
+
expo prebuild
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
In your `metro.config.js`, add a module resolver to replace `crypto` with `react-native-quick-crypto`:
|
|
49
|
+
|
|
50
|
+
```diff
|
|
51
|
+
+const path = require('path');
|
|
52
|
+
|
|
53
|
+
module.exports = {
|
|
54
|
+
+ resolver: {
|
|
55
|
+
+ extraNodeModules: {
|
|
56
|
+
+ crypto: path.resolve(__dirname, './node_modules/react-native-quick-crypto'),
|
|
57
|
+
+ },
|
|
58
|
+
+ },
|
|
59
|
+
...
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Now, all imports for `crypto` will be resolved as `react-native-quick-crypto` instead.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Sponsors
|
|
67
|
+
|
|
68
|
+
- TODO: List sponsors here
|
|
69
|
+
|
|
70
|
+
## Limitations
|
|
71
|
+
|
|
72
|
+
As the library uses JSI for synchronous native methods access, remote debugging (e.g. with Chrome) is no longer possible. Instead, you should use [Flipper](https://fbflipper.com).
|
|
73
|
+
|
|
74
|
+
## Adopting at scale
|
|
75
|
+
|
|
76
|
+
react-native-quick-crypto was built at Margelo, an elite app development agency. For enterprise support or other business inquiries, contact us at <a href="mailto:hello@margelo.io?subject=Adopting react-native-quick-crypto at scale">hello@margelo.io</a>!
|
|
77
|
+
|
|
78
|
+
## Contributing
|
|
79
|
+
|
|
80
|
+
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
MIT
|
|
Binary file
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.9.0)
|
|
2
|
+
|
|
3
|
+
set (PACKAGE_NAME "react-native-quick-crypto")
|
|
4
|
+
set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
|
|
5
|
+
file (GLOB LIBFBJNI_INCLUDES "${BUILD_DIR}/fbjni-*-headers.jar/")
|
|
6
|
+
file (GLOB LIBRN_SO "${BUILD_DIR}/react-native-0*/jni/${ANDROID_ABI}")
|
|
7
|
+
set (CMAKE_CXX_STANDARD 17)
|
|
8
|
+
# TODO(osp) remove before release
|
|
9
|
+
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g")
|
|
10
|
+
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
|
|
11
|
+
|
|
12
|
+
include_directories(
|
|
13
|
+
../cpp
|
|
14
|
+
"${NODE_MODULES_DIR}/react-native/React"
|
|
15
|
+
"${NODE_MODULES_DIR}/react-native/React/Base"
|
|
16
|
+
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni"
|
|
17
|
+
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni"
|
|
18
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon"
|
|
19
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
|
|
20
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
|
|
21
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/turbomodule/core"
|
|
22
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/react/nativemodule/core"
|
|
23
|
+
"${LIBFBJNI_INCLUDES}"
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
if(${REACT_NATIVE_VERSION} LESS 66)
|
|
27
|
+
set (
|
|
28
|
+
INCLUDE_JSI_CPP
|
|
29
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/jsi.cpp"
|
|
30
|
+
)
|
|
31
|
+
endif()
|
|
32
|
+
|
|
33
|
+
add_library(reactnativequickcrypto # <-- Library name
|
|
34
|
+
SHARED
|
|
35
|
+
"src/main/cpp/cpp-adapter.cpp"
|
|
36
|
+
"../cpp/MGLQuickCryptoHostObject.cpp"
|
|
37
|
+
"../cpp/JSIUtils/MGLTypedArray.cpp"
|
|
38
|
+
"../cpp/Utils/MGLDispatchQueue.cpp"
|
|
39
|
+
"../cpp/JSIUtils/MGLThreadAwareHostObject.cpp"
|
|
40
|
+
"../cpp/JSIUtils/MGLSmartHostObject.cpp"
|
|
41
|
+
"../cpp/HMAC/MGLHmacInstaller.cpp"
|
|
42
|
+
"../cpp/HMAC/MGLHmacHostObject.cpp"
|
|
43
|
+
"../cpp/fastpbkdf2/MGLPbkdf2HostObject.cpp"
|
|
44
|
+
"../cpp/fastpbkdf2/fastpbkdf2.c"
|
|
45
|
+
"../cpp/Random/MGLRandomHostObject.cpp"
|
|
46
|
+
"../cpp/Hash/MGLHashInstaller.cpp"
|
|
47
|
+
"../cpp/Hash/MGLHashHostObject.cpp"
|
|
48
|
+
"../cpp/Cipher/MGLCipherHostObject.cpp"
|
|
49
|
+
"../cpp/Cipher/MGLCreateCipherInstaller.cpp"
|
|
50
|
+
"../cpp/Cipher/MGLCreateDecipherInstaller.cpp"
|
|
51
|
+
${INCLUDE_JSI_CPP} # only on older RN versions
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
set_target_properties(
|
|
55
|
+
reactnativequickcrypto PROPERTIES
|
|
56
|
+
CXX_STANDARD 17
|
|
57
|
+
CXX_EXTENSIONS OFF
|
|
58
|
+
POSITION_INDEPENDENT_CODE ON
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
file (GLOB LIBRN_DIR "${PREBUILT_DIR}/${ANDROID_ABI}")
|
|
62
|
+
|
|
63
|
+
find_library(
|
|
64
|
+
log-lib
|
|
65
|
+
log
|
|
66
|
+
)
|
|
67
|
+
find_library(
|
|
68
|
+
REACT_NATIVE_JNI_LIB
|
|
69
|
+
reactnativejni
|
|
70
|
+
PATHS ${LIBRN_DIR}
|
|
71
|
+
NO_CMAKE_FIND_ROOT_PATH
|
|
72
|
+
)
|
|
73
|
+
find_library(
|
|
74
|
+
FBJNI_LIB
|
|
75
|
+
fbjni
|
|
76
|
+
PATHS ${LIBRN_SO}
|
|
77
|
+
NO_CMAKE_FIND_ROOT_PATH
|
|
78
|
+
)
|
|
79
|
+
find_library(
|
|
80
|
+
TURBOMODULES_LIB
|
|
81
|
+
turbomodulejsijni
|
|
82
|
+
PATHS ${LIBRN_DIR}
|
|
83
|
+
NO_CMAKE_FIND_ROOT_PATH
|
|
84
|
+
)
|
|
85
|
+
find_library(
|
|
86
|
+
REACT_LIB
|
|
87
|
+
react_nativemodule_core
|
|
88
|
+
PATHS ${LIBRN_DIR}
|
|
89
|
+
NO_CMAKE_FIND_ROOT_PATH
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
if(${REACT_NATIVE_VERSION} LESS 66)
|
|
93
|
+
# JSI lib didn't exist on RN 0.65 and before. Simply omit it.
|
|
94
|
+
set (JSI_LIB "")
|
|
95
|
+
else()
|
|
96
|
+
# RN 0.66 distributes libjsi.so, can be used instead of compiling jsi.cpp manually.
|
|
97
|
+
find_library(
|
|
98
|
+
JSI_LIB
|
|
99
|
+
jsi
|
|
100
|
+
PATHS ${LIBRN_DIR}
|
|
101
|
+
NO_CMAKE_FIND_ROOT_PATH
|
|
102
|
+
)
|
|
103
|
+
endif()
|
|
104
|
+
|
|
105
|
+
find_package(openssl REQUIRED CONFIG)
|
|
106
|
+
|
|
107
|
+
target_link_libraries(
|
|
108
|
+
reactnativequickcrypto
|
|
109
|
+
${TURBOMODULES_LIB}
|
|
110
|
+
${FBJNI_LIB}
|
|
111
|
+
${log-lib}
|
|
112
|
+
${JSI_LIB}
|
|
113
|
+
${REACT_NATIVE_JNI_LIB}
|
|
114
|
+
${REACT_LIB}
|
|
115
|
+
android
|
|
116
|
+
openssl::crypto
|
|
117
|
+
)
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import groovy.json.JsonSlurper
|
|
2
|
+
import org.apache.tools.ant.filters.ReplaceTokens
|
|
3
|
+
import java.nio.file.Paths
|
|
4
|
+
|
|
5
|
+
static def findNodeModules(baseDir) {
|
|
6
|
+
def basePath = baseDir.toPath().normalize()
|
|
7
|
+
// Node's module resolution algorithm searches up to the root directory,
|
|
8
|
+
// after which the base path will be null
|
|
9
|
+
while (basePath) {
|
|
10
|
+
def nodeModulesPath = Paths.get(basePath.toString(), "node_modules")
|
|
11
|
+
def reactNativePath = Paths.get(nodeModulesPath.toString(), "react-native")
|
|
12
|
+
if (nodeModulesPath.toFile().exists() && reactNativePath.toFile().exists()) {
|
|
13
|
+
return nodeModulesPath.toString()
|
|
14
|
+
}
|
|
15
|
+
basePath = basePath.getParent()
|
|
16
|
+
}
|
|
17
|
+
throw new GradleException("QuickCrypto: Failed to find node_modules/ path!")
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
def nodeModules = findNodeModules(projectDir)
|
|
21
|
+
logger.warn("QuickCrypto: node_modules/ found at: ${nodeModules}")
|
|
22
|
+
|
|
23
|
+
buildscript {
|
|
24
|
+
repositories {
|
|
25
|
+
google()
|
|
26
|
+
jcenter()
|
|
27
|
+
maven {
|
|
28
|
+
url "https://plugins.gradle.org/m2/"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
dependencies {
|
|
33
|
+
classpath 'com.android.tools.build:gradle:4.2.2'
|
|
34
|
+
classpath 'de.undercouch:gradle-download-task:4.1.2'
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
apply plugin: 'com.android.library'
|
|
39
|
+
apply plugin: 'de.undercouch.download'
|
|
40
|
+
|
|
41
|
+
def getExtOrDefault(name) {
|
|
42
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['QuickCrypto_' + name]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
def getExtOrIntegerDefault(name) {
|
|
46
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['QuickCrypto_' + name]).toInteger()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
def reactNativeArchitectures() {
|
|
50
|
+
def value = project.getProperties().get("reactNativeArchitectures")
|
|
51
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
def sourceBuild = false
|
|
55
|
+
def defaultDir = null
|
|
56
|
+
def androidSourcesDir = null
|
|
57
|
+
def androidSourcesName = 'React Native sources'
|
|
58
|
+
|
|
59
|
+
if (rootProject.ext.has('reactNativeAndroidRoot')) {
|
|
60
|
+
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
|
|
61
|
+
androidSourcesDir = defaultDir.parentFile.toString()
|
|
62
|
+
} else if (findProject(':ReactAndroid') != null) {
|
|
63
|
+
sourceBuild = true
|
|
64
|
+
defaultDir = project(':ReactAndroid').projectDir
|
|
65
|
+
androidSourcesDir = defaultDir.parentFile.toString()
|
|
66
|
+
} else {
|
|
67
|
+
defaultDir = file("$nodeModules/react-native/android")
|
|
68
|
+
androidSourcesDir = defaultDir.parentFile.toString()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!defaultDir.exists()) {
|
|
72
|
+
throw new GradleException(
|
|
73
|
+
"${project.name}: React Native android directory (node_modules/react-native/android) does not exist! Resolved node_modules to: ${nodeModules}"
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
def prebuiltDir = sourceBuild
|
|
78
|
+
? "$nodeModules/react-native/ReactAndroid/src/main/jni/prebuilt/lib"
|
|
79
|
+
: "$buildDir/react-native-0*/jni"
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def reactProperties = new Properties()
|
|
83
|
+
file("$nodeModules/react-native/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
|
|
84
|
+
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME").split("\\.")[1].toInteger()
|
|
85
|
+
|
|
86
|
+
android {
|
|
87
|
+
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
|
|
88
|
+
buildToolsVersion getExtOrDefault('buildToolsVersion')
|
|
89
|
+
ndkVersion getExtOrDefault('ndkVersion')
|
|
90
|
+
|
|
91
|
+
defaultConfig {
|
|
92
|
+
minSdkVersion 21
|
|
93
|
+
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
|
|
94
|
+
versionCode 1
|
|
95
|
+
versionName "1.0"
|
|
96
|
+
externalNativeBuild {
|
|
97
|
+
cmake {
|
|
98
|
+
cppFlags "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID"
|
|
99
|
+
arguments '-DANDROID_STL=c++_shared',
|
|
100
|
+
"-DREACT_NATIVE_VERSION=${REACT_NATIVE_VERSION}",
|
|
101
|
+
"-DNODE_MODULES_DIR=${nodeModules}",
|
|
102
|
+
"-DPREBUILT_DIR=${prebuiltDir}"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
ndk {
|
|
106
|
+
abiFilters (*reactNativeArchitectures())
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
dexOptions {
|
|
111
|
+
javaMaxHeapSize "4g"
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
externalNativeBuild {
|
|
115
|
+
cmake {
|
|
116
|
+
path "CMakeLists.txt"
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
packagingOptions {
|
|
121
|
+
excludes = ["**/libc++_shared.so", "**/libfbjni.so", "**/libreactnativejni.so", "**/libjsi.so", "**/MANIFEST.MF", ""]
|
|
122
|
+
doNotStrip '**/*.so'
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
buildTypes {
|
|
126
|
+
debug {
|
|
127
|
+
packagingOptions {
|
|
128
|
+
doNotStrip '**/*.so'
|
|
129
|
+
}
|
|
130
|
+
minifyEnabled false
|
|
131
|
+
debuggable true
|
|
132
|
+
jniDebuggable true
|
|
133
|
+
renderscriptDebuggable true
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
release {
|
|
137
|
+
minifyEnabled false
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
lintOptions {
|
|
141
|
+
disable 'GradleCompatible'
|
|
142
|
+
}
|
|
143
|
+
compileOptions {
|
|
144
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
145
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
configurations {
|
|
149
|
+
extractHeaders
|
|
150
|
+
extractJNI
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
buildFeatures {
|
|
154
|
+
prefab true
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
repositories {
|
|
159
|
+
mavenCentral()
|
|
160
|
+
google()
|
|
161
|
+
|
|
162
|
+
maven {
|
|
163
|
+
url defaultDir.toString()
|
|
164
|
+
name androidSourcesName
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
dependencies {
|
|
169
|
+
// https://mvnrepository.com/artifact/com.android.ndk.thirdparty/openssl
|
|
170
|
+
implementation 'com.android.ndk.thirdparty:openssl:1.1.1l-beta-1'
|
|
171
|
+
// noinspection GradleDynamicVersion
|
|
172
|
+
implementation 'com.facebook.react:react-native:+'
|
|
173
|
+
|
|
174
|
+
//noinspection GradleDynamicVersion
|
|
175
|
+
extractHeaders("com.facebook.fbjni:fbjni:+:headers")
|
|
176
|
+
//noinspection GradleDynamicVersion
|
|
177
|
+
extractJNI("com.facebook.fbjni:fbjni:+")
|
|
178
|
+
|
|
179
|
+
if (!sourceBuild) {
|
|
180
|
+
def rnAAR = fileTree("${defaultDir.toString()}").matching({ it.include "**/**/*.aar" }).singleFile
|
|
181
|
+
extractJNI(files(rnAAR))
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// third-party-ndk deps headers
|
|
186
|
+
// mostly a copy of https://github.com/software-mansion/react-native-reanimated/blob/master/android/build.gradle#L115
|
|
187
|
+
|
|
188
|
+
def downloadsDir = new File("$buildDir/downloads")
|
|
189
|
+
def thirdPartyNdkDir = new File("$buildDir/third-party-ndk")
|
|
190
|
+
def thirdPartyVersionsFile = new File("${androidSourcesDir.toString()}/ReactAndroid/gradle.properties")
|
|
191
|
+
def thirdPartyVersions = new Properties()
|
|
192
|
+
thirdPartyVersions.load(new FileInputStream(thirdPartyVersionsFile))
|
|
193
|
+
|
|
194
|
+
def BOOST_VERSION = thirdPartyVersions["BOOST_VERSION"]
|
|
195
|
+
def boost_file = new File(downloadsDir, "boost_${BOOST_VERSION}.tar.gz")
|
|
196
|
+
def DOUBLE_CONVERSION_VERSION = thirdPartyVersions["DOUBLE_CONVERSION_VERSION"]
|
|
197
|
+
def double_conversion_file = new File(downloadsDir, "double-conversion-${DOUBLE_CONVERSION_VERSION}.tar.gz")
|
|
198
|
+
def FOLLY_VERSION = thirdPartyVersions["FOLLY_VERSION"]
|
|
199
|
+
def folly_file = new File(downloadsDir, "folly-${FOLLY_VERSION}.tar.gz")
|
|
200
|
+
def GLOG_VERSION = thirdPartyVersions["GLOG_VERSION"]
|
|
201
|
+
def glog_file = new File(downloadsDir, "glog-${GLOG_VERSION}.tar.gz")
|
|
202
|
+
|
|
203
|
+
task createNativeDepsDirectories {
|
|
204
|
+
doLast {
|
|
205
|
+
downloadsDir.mkdirs()
|
|
206
|
+
thirdPartyNdkDir.mkdirs()
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) {
|
|
211
|
+
src("https://github.com/react-native-community/boost-for-react-native/releases/download/v${BOOST_VERSION.replace("_", ".")}-0/boost_${BOOST_VERSION}.tar.gz")
|
|
212
|
+
onlyIfNewer(true)
|
|
213
|
+
overwrite(false)
|
|
214
|
+
dest(boost_file)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
task prepareBoost(dependsOn: downloadBoost, type: Copy) {
|
|
218
|
+
from(tarTree(resources.gzip(downloadBoost.dest)))
|
|
219
|
+
from("src/main/jni/third-party/boost/Android.mk")
|
|
220
|
+
include("Android.mk", "boost_${BOOST_VERSION}/boost/**/*.hpp", "boost/boost/**/*.hpp")
|
|
221
|
+
includeEmptyDirs = false
|
|
222
|
+
into("$thirdPartyNdkDir") // /boost_X_XX_X
|
|
223
|
+
doLast {
|
|
224
|
+
file("$thirdPartyNdkDir/boost_${BOOST_VERSION}").renameTo("$thirdPartyNdkDir/boost")
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
task downloadDoubleConversion(dependsOn: createNativeDepsDirectories, type: Download) {
|
|
229
|
+
src("https://github.com/google/double-conversion/archive/v${DOUBLE_CONVERSION_VERSION}.tar.gz")
|
|
230
|
+
onlyIfNewer(true)
|
|
231
|
+
overwrite(false)
|
|
232
|
+
dest(double_conversion_file)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
task prepareDoubleConversion(dependsOn: downloadDoubleConversion, type: Copy) {
|
|
236
|
+
from(tarTree(downloadDoubleConversion.dest))
|
|
237
|
+
from("src/main/jni/third-party/double-conversion/Android.mk")
|
|
238
|
+
include("double-conversion-${DOUBLE_CONVERSION_VERSION}/src/**/*", "Android.mk")
|
|
239
|
+
filesMatching("*/src/**/*", { fname -> fname.path = "double-conversion/${fname.name}" })
|
|
240
|
+
includeEmptyDirs = false
|
|
241
|
+
into("$thirdPartyNdkDir/double-conversion")
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
task downloadFolly(dependsOn: createNativeDepsDirectories, type: Download) {
|
|
245
|
+
src("https://github.com/facebook/folly/archive/v${FOLLY_VERSION}.tar.gz")
|
|
246
|
+
onlyIfNewer(true)
|
|
247
|
+
overwrite(false)
|
|
248
|
+
dest(folly_file)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
task prepareFolly(dependsOn: downloadFolly, type: Copy) {
|
|
252
|
+
from(tarTree(downloadFolly.dest))
|
|
253
|
+
from("src/main/jni/third-party/folly/Android.mk")
|
|
254
|
+
include("folly-${FOLLY_VERSION}/folly/**/*", "Android.mk")
|
|
255
|
+
eachFile { fname -> fname.path = (fname.path - "folly-${FOLLY_VERSION}/") }
|
|
256
|
+
includeEmptyDirs = false
|
|
257
|
+
into("$thirdPartyNdkDir/folly")
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
task downloadGlog(dependsOn: createNativeDepsDirectories, type: Download) {
|
|
261
|
+
src("https://github.com/google/glog/archive/v${GLOG_VERSION}.tar.gz")
|
|
262
|
+
onlyIfNewer(true)
|
|
263
|
+
overwrite(false)
|
|
264
|
+
dest(glog_file)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
task prepareGlog(dependsOn: downloadGlog, type: Copy) {
|
|
268
|
+
from(tarTree(downloadGlog.dest))
|
|
269
|
+
from("src/main/jni/third-party/glog/")
|
|
270
|
+
include("glog-${GLOG_VERSION}/src/**/*", "Android.mk", "config.h")
|
|
271
|
+
includeEmptyDirs = false
|
|
272
|
+
filesMatching("**/*.h.in") {
|
|
273
|
+
filter(ReplaceTokens, tokens: [
|
|
274
|
+
ac_cv_have_unistd_h : "1",
|
|
275
|
+
ac_cv_have_stdint_h : "1",
|
|
276
|
+
ac_cv_have_systypes_h : "1",
|
|
277
|
+
ac_cv_have_inttypes_h : "1",
|
|
278
|
+
ac_cv_have_libgflags : "0",
|
|
279
|
+
ac_google_start_namespace : "namespace google {",
|
|
280
|
+
ac_cv_have_uint16_t : "1",
|
|
281
|
+
ac_cv_have_u_int16_t : "1",
|
|
282
|
+
ac_cv_have___uint16 : "0",
|
|
283
|
+
ac_google_end_namespace : "}",
|
|
284
|
+
ac_cv_have___builtin_expect : "1",
|
|
285
|
+
ac_google_namespace : "google",
|
|
286
|
+
ac_cv___attribute___noinline : "__attribute__ ((noinline))",
|
|
287
|
+
ac_cv___attribute___noreturn : "__attribute__ ((noreturn))",
|
|
288
|
+
ac_cv___attribute___printf_4_5: "__attribute__((__format__ (__printf__, 4, 5)))"
|
|
289
|
+
])
|
|
290
|
+
it.path = (it.name - ".in")
|
|
291
|
+
}
|
|
292
|
+
into("$thirdPartyNdkDir/glog")
|
|
293
|
+
|
|
294
|
+
doLast {
|
|
295
|
+
copy {
|
|
296
|
+
from(fileTree(dir: "$thirdPartyNdkDir/glog", includes: ["stl_logging.h", "logging.h", "raw_logging.h", "vlog_is_on.h", "**/src/glog/log_severity.h"]).files)
|
|
297
|
+
includeEmptyDirs = false
|
|
298
|
+
into("$thirdPartyNdkDir/glog/exported/glog")
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
task prepareThirdPartyNdkHeaders {
|
|
304
|
+
if (!boost_file.exists()) {
|
|
305
|
+
dependsOn(prepareBoost)
|
|
306
|
+
}
|
|
307
|
+
if (!double_conversion_file.exists()) {
|
|
308
|
+
dependsOn(prepareDoubleConversion)
|
|
309
|
+
}
|
|
310
|
+
if (!folly_file.exists()) {
|
|
311
|
+
dependsOn(prepareFolly)
|
|
312
|
+
}
|
|
313
|
+
if (!glog_file.exists()) {
|
|
314
|
+
dependsOn(prepareGlog)
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
prepareThirdPartyNdkHeaders.mustRunAfter createNativeDepsDirectories
|
|
319
|
+
|
|
320
|
+
task extractAARHeaders {
|
|
321
|
+
doLast {
|
|
322
|
+
configurations.extractHeaders.files.each {
|
|
323
|
+
def file = it.absoluteFile
|
|
324
|
+
copy {
|
|
325
|
+
from zipTree(file)
|
|
326
|
+
into "$buildDir/$file.name"
|
|
327
|
+
include "**/*.h"
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
extractAARHeaders.mustRunAfter prepareThirdPartyNdkHeaders
|
|
333
|
+
|
|
334
|
+
task extractJNIFiles {
|
|
335
|
+
doLast {
|
|
336
|
+
configurations.extractJNI.files.each {
|
|
337
|
+
def file = it.absoluteFile
|
|
338
|
+
|
|
339
|
+
copy {
|
|
340
|
+
from zipTree(file)
|
|
341
|
+
into "$buildDir/$file.name"
|
|
342
|
+
include "jni/**/*"
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
extractJNIFiles.mustRunAfter extractAARHeaders
|
|
348
|
+
|
|
349
|
+
def nativeBuildDependsOn(dependsOnTask, variant) {
|
|
350
|
+
def buildTasks = tasks.findAll({ task ->
|
|
351
|
+
!task.name.contains("Clean") && (task.name.contains("externalNative") || task.name.contains("CMake")) })
|
|
352
|
+
if (variant != null) {
|
|
353
|
+
buildTasks = buildTasks.findAll({ task -> task.name.contains(variant) })
|
|
354
|
+
}
|
|
355
|
+
buildTasks.forEach { task -> task.dependsOn(dependsOnTask) }
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
afterEvaluate {
|
|
359
|
+
if (sourceBuild) {
|
|
360
|
+
nativeBuildDependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck", "Debug")
|
|
361
|
+
nativeBuildDependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck", "Rel")
|
|
362
|
+
} else {
|
|
363
|
+
nativeBuildDependsOn(extractAARHeaders, null)
|
|
364
|
+
nativeBuildDependsOn(extractJNIFiles, null)
|
|
365
|
+
nativeBuildDependsOn(prepareThirdPartyNdkHeaders, null)
|
|
366
|
+
}
|
|
367
|
+
}
|
|
Binary file
|
|
Binary file
|