If you are not a total newbie then please move along. Or, better yet, if you actually know something please respond with the corrections to the outrageous mistakes I'm sure exist below.
The Listener is a project our dear friends at Couchbase mobile have put together for Android that lets one run a CouchDB server over HTTP. I need this because I'm working on a peer to peer project where both local apps as well as remote devices will need to talk over HTTP to the device's CouchDB Server.
In this mail I outline all the steps it took to get this all working.
I tried to build the listener in Android Studio but that caused endless problems. So instead I just built it on the command line as follows:
Step 1 - Point your Git client at from https://github.com/couchbase/couchbase-lite-android-listener.git and download.
Step 2 - Go download Gradle 1.8
Step 3 - Check the build.gradle file to make sure that "apply from: 'dependencies-test.gradle' is commented out and 'apply from: 'dependencies-archive.gradle' isn't commented. Now save.
Step 4 - Open a cmd line and issue "set UPLOAD_VERSION_CBLITE=1.0.0-beta".
Step 5 - Now cd into the directory for the Listener project that contains build.gradle and issue the equivalent (for your platform) of " c:\couchbase-lite-android-listener>c:\gradle-1.8\bin\gradle.bat build"
This 'just worked' for me and after 10 seconds I had a complete build.
Step 6 - Navigate down to build\libs and pick the .aar file of your choice. I use couchbase-lite-android-listener-debug.aar. I made a copy of it and changed the extension to .zip. Inside I found three jar file, classes.jar (in the root) and under 'libs' I found servlet-api-2.4.jar and webserver.jar.
Step 7 - I assume you have set up an Android Studio project to play with CouchDB following the instructions at http://docs.couchbase.com/couchbase-lite/cbl-android/.
Step 8 - Copy the three jar files to the libs directory you put td_collator_so.jar (see step 7).
Step 9 - Edit the build.gradle file for your CouchDB project (the one you built in step 7) and replace "compile fileTree(dir: 'libs', include: 'td_collator_so.jar')" with "compile fileTree(dir: 'libs', include: '*.jar')". This is arguably sleezy since it just sucks up anything in libs but that works for me. :)
Step 10 - Go to Tools->Android->Sync Project With Gradle files. This caused everything to download for me and set up the links to the jars.
At that point I could build and go.
Using the Listener is thankfully quite easy. Here is the code I currently use to start the listener up.
String filesDir = getFilesDir().getAbsolutePath();
CBLServer server = new CBLServer (filesDir);
cblListener = new CBLListener(server, defaultCouchPort);
cblListener.start();
if (cblListener.getStatus().equals("0") == false)
{
throw new RuntimeException("CouchDB Server didn't start up correctly, alas you will have to check the log to see why.");
}
At this point, unless something went wrong, it's up and running and ready to accept requests!
I've been trying to test it with Ektorp and that has been a miserable failure but I ran a bunch of tests using CURL over the Android bridge to the emulator and it ran like a champ.
Yaron
I tried to build the listener in Android Studio but that caused endless problems.
So instead I just built it on the command line as follows:
Step 1 - Point your Git client at from https://github.com/couchbase/couchbase-lite-android-listener.git and download.
Step 2 - Go download Gradle 1.8
Step 3 - Check the build.gradle file to make sure that "apply from: 'dependencies-test.gradle' is commented out and 'apply from: 'dependencies-archive.gradle' isn't commented. Now save.
Step 4 - Open a cmd line and issue "set UPLOAD_VERSION_CBLITE=1.0.0-beta".
Step 5 - Now cd into the directory for the Listener project that contains build.gradle and issue the equivalent (for your platform) of " c:\couchbase-lite-android-listener>c:\gradle-1.8\bin\gradle.bat build"
This 'just worked' for me and after 10 seconds I had a complete build.
Step 6 - Navigate down to build\libs and pick the .aar file of your choice. I use couchbase-lite-android-listener-debug.aar. I made a copy of it and changed the extension to .zip. Inside I found three jar file, classes.jar (in the root) and under 'libs' I found servlet-api-2.4.jar and webserver.jar.
Step 7 - I assume you have set up an Android Studio project to play with CouchDB following the instructions at http://docs.couchbase.com/couchbase-lite/cbl-android/.
Step 8 - Copy the three jar files to the libs directory you put td_collator_so.jar (see step 7).
Step 9 - Edit the build.gradle file for your CouchDB project (the one you built in step 7) and replace "compile fileTree(dir: 'libs', include: 'td_collator_so.jar')" with "compile fileTree(dir: 'libs', include: '*.jar')". This is arguably sleezy since it just sucks up anything in libs but that works for me. :)
Step 10 - Go to Tools->Android->Sync Project With Gradle files. This caused everything to download for me and set up the links to the jars.
At that point I could build and go.
Using the Listener is thankfully quite easy. Here is the code I currently use to start the listener up.
String filesDir = getFilesDir().getAbsolutePath();
CBLServer server = new CBLServer (filesDir);
cblListener = new CBLListener(server, defaultCouchPort);
cblListener.start();
if (cblListener.getStatus().equals("0") == false)
{
throw new RuntimeException("CouchDB Server didn't start up correctly, alas you will have to check the log to see why.");
}
At this point, unless something went wrong, it's up and running and ready to accept requests!
I've been trying to test it with Ektorp and that has been a miserable failure but I ran a bunch of tests using CURL over the Android bridge to the emulator and it ran like a champ.
Yaron
--
You received this message because you are subscribed to the Google Groups "Mobile Couchbase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Re Wiki - I'm glad I could be of some use! :)
Gradle Version - Actually I did run into that issue and even after fixing it things still didn't work but honestly gradle and intellij/Android Studio and I haven't been having the best of time in general. I literally spent all of today putting https://peerly.codeplex.com/wikipage?title=Gradle and IDEA Intellij together.
https://peerly.codeplex.com/wikipage?title=Gradle%20and%20IDEA%20Intellij
I also posted about this on the IDEA message board - http://devnet.jetbrains.com/thread/450454 but no responses as of when I sent this email.
Thanks,
Yaron
AndroidHttpClient httpClient = new AndroidHttpClient.Builder() .url("http://localhost:5984") .build(); CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient); CouchDbConnector db = new StdCouchDbConnector("mydatabase", dbInstance); db.createDatabaseIfNotExists();
A few things to consider:
ADB - Are you running on an Android device or are you using an Android VM? If the later then it will only listen on the 'local' hidden VM network. To get around that you need to use the 'adb forward' command to forward a port from your machine to the VM. Note that this only works for applications (e.g. the Ektorp client) that are running on the same physical machine as the VM. This issue has caused me endless grief, especially for demos.
Ektorp - The good news is that Ektorp absolutely does work with CouchBase Lite. I know this because it's my main client. See the bottom of https://github.com/couchbase/couchbase-lite-java-listener for how to configure Ektorp to work with Listener. I see in your code below that you aren't using the useExpectContinue(false) flag so your code won't work.
Hope that helps,
Yaron
This is all still on Android right?
So right now I'm running on a fork of the CBL code from 6/14/2014. I will be updating to the latest master in a few weeks. But we decided to snap and stabilize while we get ready for our internal review [1]. So my experiences might not be identical to yours.
The gradle file (with our dependencies and such) for Android is available at [2]. As you can see we are just using vanilla org.ektorp:org.ektorp.android:1.4.2. No magic.
What's killing me in that the '<' issue is ringing a bell in my head. I know I've run into that!!!! But I can't remember where or how. I'm really sorry. It's driving me nuts. Maybe my brain will surface it later. But I know I've heard of this issue before! Arg.
For the libc error, I'm assuming that's thrown by couchbase and not Ektorp? Please clarify because either way that is scary.
If you want to see how we use Ektorp you would need to clone [3] and then look for all uses of the two CreateEktorpClient APIs in CreateClientBuilder in the UniversalUtilities project. You will see various tests. We use the same Ektorp code in both Java and Android. The Android binding, for whatever it's worth, is in AndroidUtilities in AndroidEktorpCreateClientBuilder. We run these tests pretty much daily and they are passing fine.
Sorry I can't be of more help,
Yaron
[1]
https://pairlist10.pair.net/pipermail/thali-talk/2014-August/000020.html
[2]
[3]
https://github.com/thaliproject/thali.git