Skip to content

Commit 5805904

Browse files
authored
Merge pull request #291 from ronickg/prefab-publishing
Added prefab publishing for android
2 parents c728bec + 2a15548 commit 5805904

2 files changed

Lines changed: 61 additions & 6 deletions

File tree

android/build.gradle

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,9 @@ def reactNativeArchitectures() {
115115
}
116116

117117
android {
118-
118+
119119
compileSdkVersion safeExtGet("compileSdkVersion", 35)
120120
namespace "com.op.sqlite"
121-
122121
// Used to override the NDK path/version on internal CI or by allowing
123122
// users to customize the NDK path/version from their root project (e.g. for M1 support)
124123
if (rootProject.hasProperty("ndkPath")) {
@@ -130,14 +129,21 @@ android {
130129

131130
buildFeatures {
132131
prefab true
132+
prefabPublishing true
133+
}
134+
135+
prefab {
136+
"op-sqlite" {
137+
headers "${project.buildDir}/headers/op-sqlite/"
138+
}
133139
}
134140

135141
defaultConfig {
136142
minSdkVersion safeExtGet("minSdkVersion", 24)
137143
targetSdkVersion safeExtGet('targetSdkVersion', 35)
138144
versionCode 1
139145
versionName "1.0"
140-
146+
141147
externalNativeBuild {
142148
cmake {
143149
if(useSQLCipher) {
@@ -179,7 +185,7 @@ android {
179185
include "**/*.cpp", "**/*.h"
180186
}
181187
sourceFiles = fileTree(dir: destDir, include: ["**/*.cpp", "**/*.h"]).files.join(";")
182-
tokenizersHeaderPath = "../c_sources/tokenizers.h"
188+
tokenizersHeaderPath = "../c_sources/tokenizers.h"
183189
}
184190

185191
cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
@@ -209,9 +215,8 @@ android {
209215
"**/libreactnative.so",
210216
]
211217
}
212-
213218
}
214-
219+
215220
compileOptions {
216221
sourceCompatibility JavaVersion.VERSION_17
217222
targetCompatibility JavaVersion.VERSION_17
@@ -248,6 +253,15 @@ dependencies {
248253
}
249254
}
250255

256+
task prepareHeaders(type: Copy) {
257+
from('../cpp')
258+
include "**/*.h"
259+
into "${project.buildDir}/headers/op-sqlite/op-engineering_op-sqlite/"
260+
includeEmptyDirs = false
261+
}
262+
263+
preBuild.dependsOn(prepareHeaders)
264+
251265
// Resolves "LOCAL_SRC_FILES points to a missing file, Check that libfb.so exists or that its path is correct".
252266
tasks.whenTaskAdded { task ->
253267
if (task.name.contains("configureCMakeDebug")) {

docs/docs/cpp_usage.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
sidebar_position: 10
3+
---
4+
5+
# C++ Usage
6+
7+
In certain scenarios, you may prefer direct access to SQLite C++ code, allowing efficient database operations directly from C++ in a React Native environment, independent of JavaScript.
8+
9+
## Android CMake Integration
10+
11+
The package supports prefab publishing for Android, which allows you to access it from within your CMakeLists.txt file.
12+
13+
Add the following to your `CMakeLists.txt`:
14+
15+
```cmake
16+
find_package(op-engineering_op-sqlite REQUIRED CONFIG)
17+
18+
# Link all libraries together
19+
target_link_libraries(
20+
${PACKAGE_NAME}
21+
${LOG_LIB}
22+
android
23+
op-engineering_op-sqlite::op-sqlite
24+
)
25+
```
26+
27+
## Header File Inclusion
28+
29+
Due to platform differences, you need to include the SQLite header differently for Android and iOS:
30+
31+
### Example on how to include the headers in C++
32+
33+
```cpp
34+
#ifdef __ANDROID__
35+
#include <op-engineering_op-sqlite/sqlite3.h>
36+
#include <op-engineering_op-sqlite/bridge.h>
37+
#else
38+
#include <op-sqlite/sqlite3.h>
39+
#include <op-sqlite/bridge.h>
40+
#endif
41+
```

0 commit comments

Comments
 (0)