Skip to content

Commit b2bfa79

Browse files
author
Oscar Franco
authored
Merge pull request #86 from craftzdog/android-flags
feat(ios&android): Support specifying pre-processor flags to sqlite
2 parents 088ee7c + b41daf5 commit b2bfa79

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,37 @@ If you have an existing database file you want to load you can navigate from the
340340

341341
Alternatively you can place/move your database file using the one of the many react-native fs libraries.
342342

343+
## Enable compile-time options
344+
345+
By specifying pre-processor flags, you can enable optional features like FTS5, Geopoly, etc.
346+
347+
### iOS
348+
349+
Add a `post_install` block to your `<PROJECT_ROOT>/ios/Podfile` like so:
350+
351+
```ruby
352+
post_install do |installer|
353+
installer.pods_project.targets.each do |target|
354+
if target.name == "react-native-quick-sqlite" then
355+
target.build_configurations.each do |config|
356+
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', '<SQLITE_FLAGS>']
357+
end
358+
end
359+
end
360+
end
361+
```
362+
363+
Replace the `<SQLITE_FLAGS>` part with flags you want to add.
364+
For example, you could add `SQLITE_ENABLE_FTS5=1` to `GCC_PREPROCESSOR_DEFINITIONS` to enable FTS5 in the iOS project.
365+
366+
### Android
367+
368+
You can specify flags via `<PROJECT_ROOT>/android/gradle.properties` like so:
369+
370+
```
371+
quickSqliteFlags="<SQLITE_FLAGS>"
372+
```
373+
343374
## More
344375

345376
If you want to learn how to make your own JSI module buy my [JSI/C++ cheat sheet](http://ospfranco.gumroad.com/).

android/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ add_library(
5656
cpp-adapter.cpp
5757
)
5858

59+
add_definitions(
60+
${SQLITE_FLAGS}
61+
)
62+
5963
# find fbjni package
6064
file (GLOB LIBFBJNI_INCLUDE_DIR "${BUILD_DIR}/fbjni-*-headers.jar/")
6165

android/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def rnMinorVersion = Integer.parseInt(minor)
5454
def reactProperties = new Properties()
5555
file("$nodeModules/react-native/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
5656
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME").split("\\.")[1].toInteger()
57+
def SQLITE_FLAGS = rootProject.properties['quickSqliteFlags']
5758

5859
android {
5960

@@ -72,7 +73,8 @@ android {
7273
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
7374
arguments '-DANDROID_STL=c++_shared',
7475
"-DREACT_NATIVE_VERSION=${REACT_NATIVE_VERSION}",
75-
"-DNODE_MODULES_DIR=${nodeModules}"
76+
"-DNODE_MODULES_DIR=${nodeModules}",
77+
"-DSQLITE_FLAGS='${SQLITE_FLAGS ? SQLITE_FLAGS : ''}'"
7678
}
7779
}
7880

@@ -249,4 +251,4 @@ tasks.whenTaskAdded { task ->
249251
task.dependsOn(extractAARHeaders)
250252
task.dependsOn(extractJNIFiles)
251253
}
252-
}
254+
}

0 commit comments

Comments
 (0)