!!This project is no longer being maintained! Please use couchbase-lite-android instead!!
Apache CouchDB on Android provides a simple way to sync your application data across devices and provide cloud backup of user data. Unlike other cloud solutions, the data is hosted on the device by Couchbase Mobile, so even when the network is down or slow (airplane, subway, backyard) the application is responsive to users.
What this means for you:
- You can embed the rock solid distributed database, Mobile Couchbase, on your Android device.
- Your Android apps can use Apache CouchDB's well-proven synchronization technology.
- If you <3 CouchApps, you can deploy them as Android apps.
There is a Google Group here for Mobile Couchbase. Let's talk about how to optimize the Erlang build, what the best Java APIs are for CouchDB, how to take advantage of replication on mobile devices. It'll be fun.
There is a bug tracker available at http://www.couchbase.org/issues/browse/CBMA
If you have questions or get stuck or just want to say hi, email [email protected] and let us know that you're interested in Couchbase on mobile.
These instructions require you to have installed Eclipse and the Android SDK, the Android developer website has instructions.
NOTE: You do not need the source of this repository to use Mobile Couchbase in your Android application.
-
Create a new Android project or select an existing project
-
Download the Android-Couchbase.zip
- Extract Android-Couchbase.zip, you will see 3 files
- Couchbase.zip
- couchbase.xml
- README.txt
-
Place Couchbase.zip and couchbase.xml into the top-level of your project
-
Right-click on couchbase.xml and select Run As > Ant Build
-
Refresh your project
Now that your project supports Couchbase, starting Cocuhbase is accomplished by adding a few things to your application's Main Activity.
- Create an instance of ICouchbaseDelegate, you can implement these methods to respond to Couchbase events
private final ICouchbaseDelegate mDelegate = new ICouchbaseDelegate() { @Override public void couchbaseStarted(String host, int port) {} @Override public void exit(String error) {} };
- Declare a ServiceConnection instance to keep a reference to the Couchbase service
private ServiceConnection couchServiceConnection;
- Add a method to start Couchbase
public void startCouchbase() { CouchbaseMobile couch = new CouchbaseMobile(getBaseContext(), mCallback); couchServiceConnection = couch.startCouchbase(); }
- Call the startCouchbase method from the appropriate Activity lifecycle methods. For many applications the onCreate method is appropriate
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... startCouchbase(); }
A Broadcast Receiver registered to listen for the right events can now be used instead of a delegate.
- Optionally, use the CouchbaseMobile constructor without the delegate parameter
CouchbaseMobile couch = new CouchbaseMobile(getBaseContext());
- Declare a Broadcast Receiver
private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if(CouchbaseStarted.ACTION.equals(intent.getAction())) { String host = CouchbaseStarted.getHost(intent); int port = CouchbaseStarted.getPort(intent); } else if(CouchbaseError.ACTION.equals(intent.getAction())) { String message = CouchbaseError.getMessage(intent); } } };
- Register the receiver to listen for the appropriate events
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... registerReceiver(mReceiver, new IntentFilter(CouchbaseStarted.ACTION)); registerReceiver(mReceiver, new IntentFilter(CouchbaseError.ACTION)); }
For examples please look at:
- https://github.com/couchbase/Android-EmptyApp
- https://github.com/daleharvey/Android-MobileFuton
- https://github.com/couchbaselabs/AndroidGrocerySync
To build the Android-Couchbase project from source run the following ant command:
ant -Dsdk.dir=/path/to/android/sdk dist
Replacing the value for sdk.dir with the path to the Android SDK on the build server.
The current build of Android Couchbase embed the CouchDB binaries. There is information on how to build these binaries on the SourceBuild project.
In some environments it may not be possible to use the couchbase.xml ant script installer. Couchbase can be installed manually using the following steps.
-
Unzip the Couchbase.zip archive. This will produce another zip file named overlay.zip.
-
Remove any existing couchbase*.jar file from /libs
-
Extract the contents of the overlay.zip file into your project. This will place all assets and libraries in the correct location within the structure of your project.
cd unzip //overlay.zip
-
Update the project's AndroidManifest.xml to declare the Couchbase service and request the required permissions.
Within the "application" section add:
Within the "manifest" section add:
- Android 2.1 or newer
- Eclipse 3.6.2 or newer (if using Eclipse)
- Ant 1.7.1 or newer (if using Ant outside of Eclipse)
- When testing in the emulator, be sure to create an SD Card with sufficient space for your databases
- If using views in the emulator, create an AVD with CPU/ABI set to armeabi-v7a
Portions under Apache, Erlang, and other licenses.
The overall package is released under the Apache license, 2.0.
Copyright 2011, Couchbase, Inc.