Skip to content

Added prefab publishing for android #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ def reactNativeArchitectures() {
}

android {

compileSdkVersion safeExtGet("compileSdkVersion", 35)
namespace "com.op.sqlite"

// Used to override the NDK path/version on internal CI or by allowing
// users to customize the NDK path/version from their root project (e.g. for M1 support)
if (rootProject.hasProperty("ndkPath")) {
Expand All @@ -130,14 +129,21 @@ android {

buildFeatures {
prefab true
prefabPublishing true
}

prefab {
"op-sqlite" {
headers "${project.buildDir}/headers/op-sqlite/"
}
}

defaultConfig {
minSdkVersion safeExtGet("minSdkVersion", 24)
targetSdkVersion safeExtGet('targetSdkVersion', 35)
versionCode 1
versionName "1.0"

externalNativeBuild {
cmake {
if(useSQLCipher) {
Expand Down Expand Up @@ -179,7 +185,7 @@ android {
include "**/*.cpp", "**/*.h"
}
sourceFiles = fileTree(dir: destDir, include: ["**/*.cpp", "**/*.h"]).files.join(";")
tokenizersHeaderPath = "../c_sources/tokenizers.h"
tokenizersHeaderPath = "../c_sources/tokenizers.h"
}

cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
Expand Down Expand Up @@ -209,9 +215,8 @@ android {
"**/libreactnative.so",
]
}

}

compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
Expand Down Expand Up @@ -248,6 +253,15 @@ dependencies {
}
}

task prepareHeaders(type: Copy) {
from('../cpp')
include "**/*.h"
into "${project.buildDir}/headers/op-sqlite/op-engineering_op-sqlite/"
includeEmptyDirs = false
}

preBuild.dependsOn(prepareHeaders)

// Resolves "LOCAL_SRC_FILES points to a missing file, Check that libfb.so exists or that its path is correct".
tasks.whenTaskAdded { task ->
if (task.name.contains("configureCMakeDebug")) {
Expand Down
41 changes: 41 additions & 0 deletions docs/docs/cpp_usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
sidebar_position: 10
---

# C++ Usage

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.

## Android CMake Integration

The package supports prefab publishing for Android, which allows you to access it from within your CMakeLists.txt file.

Add the following to your `CMakeLists.txt`:

```cmake
find_package(op-engineering_op-sqlite REQUIRED CONFIG)

# Link all libraries together
target_link_libraries(
${PACKAGE_NAME}
${LOG_LIB}
android
op-engineering_op-sqlite::op-sqlite
)
```

## Header File Inclusion

Due to platform differences, you need to include the SQLite header differently for Android and iOS:

### Example on how to include the headers in C++

```cpp
#ifdef __ANDROID__
#include <op-engineering_op-sqlite/sqlite3.h>
#include <op-engineering_op-sqlite/bridge.h>
#else
#include <op-sqlite/sqlite3.h>
#include <op-sqlite/bridge.h>
#endif
```