Skip to content

Sergeyd/plugin system #187

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

Closed
wants to merge 4 commits into from
Closed
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
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,16 @@ npm install --save react-native-sqlite-storage
...

include ':react-native-sqlite-storage'
project(':react-native-sqlite-storage').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sqlite-storage/src/android')
project(':react-native-sqlite-storage').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sqlite-storage/src/android/storage')

include ':sqlite-plugin-provider'
project(':sqlite-plugin-provider').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sqlite-storage/src/android/sqlite-plugin-provider')

// for sqlitecipher support:
include ':sql-cipher-plugin'
project(':sql-cipher-plugin').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sqlite-storage/src/android/sql-cipher-plugin')


```

#### Step 3 - Update app Gradle Build
Expand All @@ -242,6 +251,9 @@ project(':react-native-sqlite-storage').projectDir = new File(rootProject.projec
dependencies {
...
compile project(':react-native-sqlite-storage')
compile project(':sqlite-plugin-provider')
// To add sqlite cipher support:
compile project(':sql-cipher-plugin')
}
```

Expand All @@ -265,7 +277,7 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand
.setBundleAssetName("index.android.bundle") // this is dependant on how you name you JS files, example assumes index.android.js
.setJSMainModuleName("index.android") // this is dependant on how you name you JS files, example assumes index.android.js
.addPackage(new MainReactPackage())
.addPackage(new SQLitePluginPackage()) // register SQLite Plugin here
.addPackage(new SQLitePluginPackage()) // register SQLite Plugin here. For SQLiteCipher support pass SqliteCipherConnectionProvider to PluginPackage.
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
Expand Down
28 changes: 5 additions & 23 deletions src/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
buildscript {
repositories {
mavenLocal()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.android.tools.build:gradle:2.0.0'
}
}

apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
allprojects {
repositories {
jcenter()
}
}

repositories {
mavenCentral()
}

dependencies {
compile 'com.facebook.react:react-native:0.14.+'
}
4 changes: 3 additions & 1 deletion src/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
rootProject.name = 'SQLitePlugin'
include ':app'
include ':sqlite-plugin-provider'
include ':sql-cipher-plugin'
include ':storage'
1 change: 1 addition & 0 deletions src/android/sql-cipher-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
24 changes: 24 additions & 0 deletions src/android/sql-cipher-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.0"

defaultConfig {
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile project(':sqlite-plugin-provider')
compile 'net.zetetic:android-database-sqlcipher:3.5.7@aar'
}
25 changes: 25 additions & 0 deletions src/android/sql-cipher-plugin/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/sergeyd/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
13 changes: 13 additions & 0 deletions src/android/sql-cipher-plugin/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<manifest package="com.microsoft.sqlcipher"

xmlns:android="http://schemas.android.com/apk/res/android"
>

<application android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.pgsqlite.sqlcipher;

import android.content.Context;

import org.pgsqlite.sqlite.plugin.Database;
import org.pgsqlite.sqlite.plugin.DatabaseConnectionProvider;

import net.sqlcipher.DatabaseErrorHandler;
import net.sqlcipher.SQLException;
import net.sqlcipher.database.SQLiteDatabase;

/**
* Written by Sergei Dryganets Jul 24/2017
*/
public class SqliteCipherConnectionProvider implements DatabaseConnectionProvider {
private static volatile boolean sNativeLibraryLoaded;

public SqliteCipherConnectionProvider(Context context) {
if (!sNativeLibraryLoaded) {
sNativeLibraryLoaded = true;
SQLiteDatabase.loadLibs(context);
}
}

@Override
public Database openDatabase(String databasePath, String password, int openFlags) {
return new SqliteCipherDatabase(SQLiteDatabase.openDatabase(databasePath, password, null,
openFlags, null, new DBErrorHandler()));
}

private class DBErrorHandler implements DatabaseErrorHandler {
@Override
public void onCorruption(SQLiteDatabase dbObj) {
throw new SQLException("Database is corrupted");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.pgsqlite.sqlcipher;

import org.pgsqlite.sqlite.plugin.Cursor;

import java.io.IOException;

/**
* Written by Sergei Dryganets Jul 24/2017
*/
public class SqliteCipherCursor implements Cursor {
private final net.sqlcipher.Cursor cursor;

public SqliteCipherCursor(net.sqlcipher.Cursor cursor) {
this.cursor = cursor;
}

@Override
public boolean moveToFirst() {
return cursor.moveToFirst();
}

@Override
public boolean moveToNext() {
return cursor.moveToNext();
}

@Override
public int getColumnCount() {
return cursor.getColumnCount();
}

@Override
public String getColumnName(int i) {
return cursor.getColumnName(i);
}

@Override
public int getType(int i) {
return cursor.getType(i);
}

@Override
public long getLong(int i) {
return cursor.getLong(i);
}

@Override
public double getDouble(int i) {
return cursor.getDouble(i);
}

@Override
public String getString(int i) {
return cursor.getString(i);
}

@Override
public byte[] getBlob(int i) {
return cursor.getBlob(i);
}

@Override
public int getCount() {
return cursor.getCount();
}

@Override
public void close() throws IOException {
cursor.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.pgsqlite.sqlcipher;

import net.sqlcipher.database.SQLiteDatabase;

import org.pgsqlite.sqlite.plugin.Database;
import org.pgsqlite.sqlite.plugin.Cursor;
import org.pgsqlite.sqlite.plugin.SQLStatement;

import java.io.IOException;

/**
* Written by Sergei Dryganets Jul 24/2017
*/
public class SqliteCipherDatabase implements Database {
private SQLiteDatabase database;

SqliteCipherDatabase(SQLiteDatabase database) {
this.database = database;
}

@Override
public void execSQL(String sql) {
database.execSQL(sql);
}

@Override
public SQLStatement compileStatement(String sql) {
return new SqliteCipherStatement(database.compileStatement(sql));
}

@Override
public Cursor rawQuery(String sql, String[] params) {
return new SqliteCipherCursor(database.rawQuery(sql, params));
}

@Override
public boolean isOpen() {
return database.isOpen();
}

@Override
public void beginTransaction() {
database.beginTransaction();
}

@Override
public void setTransactionSuccessful() {
database.setTransactionSuccessful();
}

@Override
public void endTransaction() {
database.endTransaction();
}

@Override
public void close() throws IOException {
database.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.pgsqlite.sqlcipher;

import org.pgsqlite.sqlite.plugin.SQLStatement;

import java.io.IOException;

/**
* Written by Sergei Dryganets Jul 24/2017
*/
public class SqliteCipherStatement implements SQLStatement {
private final net.sqlcipher.database.SQLiteStatement statement;
public SqliteCipherStatement(net.sqlcipher.database.SQLiteStatement statement) {
this.statement = statement;
}

@Override
public void bindDouble(int i, double value) {
statement.bindDouble(i, value);
}

@Override
public void bindString(int i, String value) {
statement.bindString(i, value);
}

@Override
public void bindNull(int i) {
statement.bindNull(i);
}

@Override
public void bindLong(int i, long value) {
statement.bindLong(i, value);
}

@Override
public long executeInsert() {
return statement.executeInsert();
}

@Override
public int executeUpdateDelete() {
return statement.executeUpdateDelete();
}

@Override
public void close() throws IOException {
statement.close();
}
}
1 change: 1 addition & 0 deletions src/android/sqlite-plugin-provider/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
20 changes: 20 additions & 0 deletions src/android/sqlite-plugin-provider/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.0"

defaultConfig {
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"

}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Loading