Skip to content

Add documentation for using android-native platform #393

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 1 commit into from
Dec 22, 2019
Merged
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
56 changes: 41 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@ The library has been tested with React 16.2 (and earlier) and XCode 7,8,9 - it w

Version 3.2 is the first version compatible with RN 0.40.

# Installation
```
npm install --save react-native-sqlite-storage
```
Then follow the instructions for your platform to link react-native-sqlite-storage into your project

# How to use (iOS):
## iOS
#### Standard Method
** React Native 0.60 and above **
Run `cd ios && pod install && cd ..`. Linking is not required in React Native 0.60 and above

** React Native 0.59 and below **

#### Step 1. Install Dependencies

##### With CocoaPods:

This command should be executed in the root directory of your RN project
```shell
npm install --save react-native-sqlite-storage
```
Then add this to your Podfile which should be located inside the ios project subdirectory
Add this to your Podfile which should be located inside the ios project subdirectory
```ruby
pod 'React', :path => '../node_modules/react-native'
pod 'react-native-sqlite-storage', :path => '../node_modules/react-native-sqlite-storage'
Expand All @@ -45,14 +51,12 @@ OR
pod update
```


Done, skip to Step 2.

##### Without CocoaPods:

This command should be executed in the root directory of your RN project
```shell
npm install --save react-native-sqlite-storage
react-native link
```

Expand Down Expand Up @@ -126,12 +130,34 @@ db.transaction((tx) => {

# How to use (Android):

#### Step 1 - NPM Install
** React Native 0.60 and above **
If you would like to use the devices SQLite there are no extra steps.
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`

```shell
npm install --save react-native-sqlite-storage
```js
module.exports = {
...,
dependencies: {
...,
"react-native-sqlite-storage": {
platforms: {
android: {
sourceDir:
"../node_modules/react-native-sqlite-storage/platforms/android-native",
packageImportPath: "import io.liteglue.SQLitePluginPackage;",
packageInstance: "new SQLitePluginPackage()"
}
}
}
...
}
...
};
```
#### Step 2 - Update Gradle Settings (located under Gradle Settings in Project Panel)

** React Native 0.59 and below **

#### Step 1 - Update Gradle Settings (located under Gradle Settings in Project Panel)

```gradle
// file: android/settings.gradle
Expand All @@ -141,7 +167,7 @@ include ':react-native-sqlite-storage'
project(':react-native-sqlite-storage').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sqlite-storage/src/android')
```

#### Step 3 - Update app module Gradle Build script (located under Gradle Settings in Project Panel)
#### Step 2 - Update app module Gradle Build script (located under Gradle Settings in Project Panel)

```gradle
// file: android/app/build.gradle
Expand All @@ -153,7 +179,7 @@ dependencies {
}
```

#### Step 4 - Register React Package (this should work on React version but if it does not , try the ReactActivity based approach. Note: for version 3.0.0 and below you would have to pass in the instance of your Activity to the SQLitePluginPackage constructor
#### Step 3 - Register React Package (this should work on React version but if it does not , try the ReactActivity based approach. Note: for version 3.0.0 and below you would have to pass in the instance of your Activity to the SQLitePluginPackage constructor

```java
...
Expand Down Expand Up @@ -205,7 +231,7 @@ public class MainApplication extends Application implements ReactApplication {
}
```

#### Step 5 - Require and use in Javascript - see full examples (callbacks and Promise) in test directory.
#### Step 4 - Require and use in Javascript - see full examples (callbacks and Promise) in test directory.

```js
// file: index.android.js
Expand Down