Skip to content

Commit d85acbd

Browse files
committed
Fix for Android 11+
Based on andpor#492
1 parent bb728b5 commit d85acbd

13 files changed

+571
-607
lines changed

README.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The library has been tested with React 0.41 (and earlier) and XCode 7,8 - it wor
1818

1919
Version 3.2 is the first version compatible with RN 0.40.
2020

21-
#Version History
21+
# Version History
2222

2323
v3.2.2
2424
1. Corrects the CocoaPods based development set-up instructions and includes sample Podfile. [Issue #125] (https://github.com/andpor/react-native-sqlite-storage/issues/125)
@@ -89,7 +89,7 @@ v2.0 - Full support for Promise API. Backward compatible with Callbacks.
8989

9090
v1.0 - Initial release for iOS with full support of all operations based on plan JavaScript callbacks.
9191

92-
#How to use (iOS):
92+
# How to use (iOS):
9393

9494
#### Step 1. Install Dependencies
9595

@@ -194,7 +194,33 @@ db.transaction((tx) => {
194194
});
195195
```
196196

197-
#How to use (Android):
197+
# How to use (Android):
198+
199+
** React Native 0.60 and above **
200+
If you would like to use the devices SQLite there are no extra steps.
201+
However, if you would like to use the SQLite bundled with this library (includes support for FTS5), add the following to your `react-native.config.js`
202+
203+
```js
204+
module.exports = {
205+
...,
206+
dependencies: {
207+
...,
208+
"react-native-sqlite-storage": {
209+
platforms: {
210+
android: {
211+
sourceDir: '../node_modules/react-native-sqlite-storage/src/android-native',
212+
packageImportPath: "import io.liteglue.SQLitePluginPackage;",
213+
packageInstance: "new SQLitePluginPackage()"
214+
}
215+
}
216+
}
217+
...
218+
}
219+
...
220+
};
221+
```
222+
223+
** React Native 0.59 and below **
198224

199225
#### Step 1 - NPM Install
200226

@@ -435,11 +461,11 @@ dbMaster.detach( 'second', successCallback, errorCallback );
435461
For sure, their is also Promise-support available for attach() and detach(), as shown in the example-application under the
436462
directory "examples".
437463

438-
#Original Cordova SQLite Bindings from Chris Brody
464+
# Original Cordova SQLite Bindings from Chris Brody
439465
https://github.com/litehelpers/Cordova-sqlite-storage
440466

441467
The issues and limitations for the actual SQLite can be found on this site.
442468

443-
##Issues
469+
## Issues
444470

445471
1. Android binds all numeric SQL input values to double. This is due to the underlying React Native limitation where only a Numeric type is available on the interface point making it ambiguous to distinguish integers from doubles. Once I figure out the proper way to do this I will update the codebase [(Issue #4141)] (https://github.com/facebook/react-native/issues/4141).

src/android-native/build.gradle

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
buildscript {
22
repositories {
3+
google()
34
jcenter()
45
}
56

67
dependencies {
7-
classpath 'com.android.tools.build:gradle:1.3.0'
8+
classpath 'com.android.tools.build:gradle:3.1.4'
89
}
910
}
1011

1112
apply plugin: 'com.android.library'
1213

14+
def safeExtGet(prop, fallback) {
15+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
16+
}
17+
1318
android {
14-
compileSdkVersion 23
15-
buildToolsVersion "23.0.1"
19+
compileSdkVersion safeExtGet('compileSdkVersion', 23)
20+
buildToolsVersion safeExtGet('buildToolsVersion', '27.0.3')
1621

1722
defaultConfig {
18-
minSdkVersion 16
19-
targetSdkVersion 22
23+
minSdkVersion safeExtGet('minSdkVersion', 21)
24+
targetSdkVersion safeExtGet('targetSdkVersion', 22)
2025
versionCode 1
2126
versionName "1.0"
2227
}
@@ -25,15 +30,19 @@ android {
2530
}
2631
sourceSets.main {
2732
jni.srcDirs = [] // This prevents the auto generation of Android.mk
28-
jniLibs.srcDir 'libs'
33+
jniLibs.srcDir 'libs'
2934
}
3035
}
3136

3237
repositories {
3338
mavenCentral()
39+
google()
40+
maven {
41+
url "https://maven.google.com"
42+
}
3443
}
3544

3645
dependencies {
37-
compile 'com.facebook.react:react-native:0.14.+'
38-
compile files('libs/sqlite-connector.jar')
46+
implementation 'com.facebook.react:react-native:+'
47+
implementation files('libs/sqlite-connector.jar')
3948
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
2.13 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

src/android-native/src/main/java/io/liteglue/CallbackContext.java

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,8 @@ public CallbackContext(Callback success, Callback error) {
3030
*
3131
* @param message The message to add to the success result.
3232
*/
33-
public void success(JSONObject message) {
34-
try {
35-
WritableMap writableMap = SQLitePluginConverter.jsonToReact(message);
36-
successCallback.invoke(writableMap);
37-
} catch (JSONException ex){
38-
errorCallback.invoke("Internal error converting results:"+ex.getMessage());
39-
}
33+
public void success(WritableMap message) {
34+
successCallback.invoke(message);
4035
}
4136

4237
/**
@@ -53,14 +48,8 @@ public void success(String message) {
5348
*
5449
* @param message The message to add to the success result.
5550
*/
56-
public void success(JSONArray message) {
57-
try {
58-
WritableArray writableArray = SQLitePluginConverter.jsonToReact(message);
59-
successCallback.invoke(writableArray);
60-
} catch (JSONException ex){
61-
errorCallback.invoke("Internal error converting results:"+ex.getMessage());
62-
}
63-
51+
public void success(WritableArray message) {
52+
successCallback.invoke(message);
6453
}
6554

6655
/**
@@ -75,13 +64,8 @@ public void success() {
7564
*
7665
* @param message The message to add to the error result.
7766
*/
78-
public void error(JSONObject message) {
79-
try {
80-
WritableMap writableMap = SQLitePluginConverter.jsonToReact(message);
81-
errorCallback.invoke(writableMap);
82-
} catch (JSONException ex){
83-
errorCallback.invoke("Internal error converting results:"+ex.getMessage());
84-
}
67+
public void error(WritableMap message) {
68+
errorCallback.invoke(message);
8569
}
8670

8771
/**

0 commit comments

Comments
 (0)