Skip to content

Upinion/react-native-couchbase-lite

Repository files navigation

react-native-couchbase

React native Couchbase allows to create a couchbase server.

Installation

npm install --save react-native-couchbase

or manually

git clone the directory to [node_modules/react-native-couchbase]

Guide

  • Initialising: How to start couchbase.

  • Functions: Available functions to interact with couchbase.

  • Events: All the different events emitted.

Setup

Android

  • In android/setting.gradle
...
include ':CouchBase', ':app'
project(':CouchBase').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-couchbase/android')
  • In android/app/build.gradle
android {
    ...
    
    // workaround for "duplicate files during packaging of APK" issue
    // see https://groups.google.com/d/msg/adt-dev/bl5Rc4Szpzg/wC8cylTWuIEJ
    packagingOptions {
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }
}


dependencies {
    ...
    compile project(':CouchBase')
}
  • give internet and network-state access, in android/app/src/main/AndroidManifest.xml:
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    ...
</manifest>
  • register module (in MainActivity.java)
import com.upinion.CouchBase.CouchBasePackage;  // <--- import

public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
  ......
    
    /**
     * A list of packages used by the app. If the app uses additional views
     * or modules besides the default ones, add more packages here.
     */
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new CouchBasePackage()
      );
    }
}

iOS

  1. Download Couchbase Mobile for iOS and add the libraries to the React native project, including CBLRegisterJSViewCompiler.h
  2. Add the project RCTCouchBase to the React Native project.
  3. In RCTCouchBase, in Header Search Paths, add the route to your ${react native mobile application}/node_modules/react-native/React folder and also Frameworks headers
  4. In the React Native project, you have to add the following frameworks and libraries to your Build phase:
    • libCBJSViewCompiler.a
    • libRCTCouchBase (from the product folder in RCTCouchBase)
    • CouchbaseLite.framework
    • CouchbaseLiteListener.framework
    • CFNetwork.framework
    • Security.framework
    • SystemConfiguration.framework
    • libsqlite3.dylib
    • libz.dylib
  5. Compile RCTCouchBase and run the React native project.