This application provides the fastest way to deploy a CouchApp to an Android device using Couchbase Mobile and Apache Callback (formerly PhoneGap).
This project requires the latest version of the Android SDK. If you already have the SDK tools, you can upgrade by running android update sdk
, if you don't have them, you can install via this link
These instructions are divided into two sections, the first describes the development mode. In this mode you can continually couchapp push your changes in for test. The second describes distribution mode where you package your application for distribution.
-
Clone this repository
-
Create a local.properties pointing to your Android SDK
sdk.dir=...
-
Build this application, either using eclipse or command line tools
ant debug
-
Install/Launch this application on your device/emulator
adb install bin/AndroidCouchbaseCallback-debug.apk
adb shell am start -n com.couchbase.callback/.AndroidCouchbaseCallback
-
Couchbase Mobile is now running, you should see now see instructions on screen install your CouchApp.
-
Forward the Couchbase Mobile from the device to your development machine (the Couchbase port is dynamic and is shown on the screen)
adb forward tcp:8984 tcp:<value displayed on your screen>
-
From within your CouchApp project directory, run the following command to install your couchapp on the device.
couchapp push . http://localhost:8984/couchapp
-
Refresh the list of CouchApps and navigate to your applicaiton
-
Compact your database
curl -X POST -H "Content-Type: application/json" http://localhost:8984/couchapp/_compact
-
Copy the database off the device and into this Android application's assets directory:
adb pull /mnt/sdcard/Android/data/com.couchbase.callback/db/couchapp.couch assets
-
Repackage your application with the database file included
ant debug
-
Reinstall the application to launch the CouchApp
adb uninstall com.couchbase.callback
adb install bin/AndroidCouchbaseCallback-debug.apk
adb shell am start -n com.couchbase.callback/.AndroidCouchbaseCallback
Android Couchbase Callback now includes a couple of sample applications to help you get started.
-
PhoneGapCouchApp - this is basic PhoneGap demonstration application hosted inside a couchapp
- Follow the development instructions above
- cd examples/PhoneGapCouchApp/couchapp
- couchapp push http://localhost:8984/phonegapcouchapp
- Click refresh link on welcome page
-
PhotoShare - this photo sharing application shows the power of using Couchbase Mobile with Apache Callback to build real applications
- Follow the development instructions above
- cd examples/PhotoShare/couchapp
- couchapp push http://localhost:8984/photoshare
- (Optional) Refactor the ExampleAppActivity class and package name (see https://github.com/couchbaselabs/Android-Couchbase-Callback/blob/master/examples/PhotoShare/src/com/docomoinnovations/couchbase/photoshare/PhotoShare.java)
- (Optional) Replace the application icon with a custom icon (see https://github.com/couchbaselabs/Android-Couchbase-Callback/blob/master/examples/PhotoShare/res/drawable/icon.png)
- (Optional) Update the app_name string (see https://github.com/couchbaselabs/Android-Couchbase-Callback/blob/master/examples/PhotoShare/res/values/strings.xml)
A few assumptions are currently made to reduce the number of options that must be configured to get started. Currently these can only be changed by modifying the code.
- The name of the database can be anything (couchapp is used in the examples above). BUT, the design document must have the same name.
-
Change the name and package of your application
Refactor name and package of ExampleAppActivity to suit your needs
-
Provide your own custom splash screen
Override the getSplashScreenDrawable() method to point to your splash screen image
Q: When I start my application the splash screen shows for a long time, then I get the message "Application Error: The connection to the server was unsuccessful." In the background behind this message I now see my application. But when I press OK, the application exits. What is going on?
A: Most likely your application is loading a resource (something like the _chagnes feed) and this causes the PhoneGap container to fail to recognize that the page has loaded. The fix is simple, add a function to your application that listens for the "deviceReady" event and start your work after this event fires. For example:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
// start listenting to changes feed here
}
We are still looking for a better approach to this problem.
- spoof a call to
onPageFinished
so that phonegap paints the screen even if a long ajax call happens before onload.
Portions under Apache, Erlang, and other licenses.
The overall package is released under the Apache license, 2.0.
Copyright 2011-2012, Couchbase, Inc.