Wednesday, December 1, 2010

Android

Ok, so I have been trying to integrate CouchDB into an android app for a couple of days now, and have finally determined the cause of all my problems.  I will try and illuminate what happened, in hopes that it can help others who are just starting out.

My first problem was the emulator.  No matter what I tried to do, it simply refused to show me my app.  After experimenting with all permutations of various settings, I have discovered that removing the test project, AVDs and all the launch configurations; and starting over, creating the AVD, then choosing to launch "in foreground" (i.e. uncheck "run in background"), in manual mode, launching my app instead of the "default activity" finally gives me some output.  I suspect it is probably something to do with how I had my project laid out, but I think if you fiddle with the settings enough, you will eventually see the application launch.

Here's the important thing: once it does, you don't ever have to shut it off again!  You can just use the DDMS view to just stop your process and then hit the debug icon again and choose the emulator that is still running.  This is one hell of a time saver as you don't have to look at that boot-up screen every time you need to make a change.

Now, CouchDb.  I downloaded and integrated DroidCouch into my project, but I kept receiving an error about how it couldn't connect to the local couchDB instance.  I had a really dumb day today, and didn't see that it was looking for a couchDb instance "on the emulated instance" and not on my comp.  So really, it needs to have couchDb already installed on the machine, and not have it as a portable instance like SQLite.  Ok, so how do you go about doing that?

You need to go and find the couch-android-launcher from GitHub, download it, and then shove it into the emulator.  Ah, but how do you do that?  You can't simply put it into your project and have it go because it is only a shell.  What you really need to do is use the NDK tool to generate some native code with it and load that into your eclipse project.  See this thread.  It so happens that you need to use Cygwin for it to work in Windows.

Crash course in Cygwin (installed the Base and did a search for "awk" and "make" and selected those packages).  I had to then find where cygwin operates from (the install directory, funnily enough).  I had to then copy the ndk and couch-android-launcher directories to /var/test and then run the ndk-build command on the couch-android-launcher folder.  Finally, I went back to Eclipse, and imported the "existing project" and chose to copy it to my workspace.  When I hit debug, tada, the emulator asked me to hit a button to install couchDb.  Almost there!

Success! Some 1,600+ files later, I see two buttons : "Start CouchDB"and "Stop CouchDB".  Well, hurry up then!  I now see the couch guy lounging in the notification bar and all looks good.

Ahhh, maybe I can go lounge about on my own couch after all of that!

Labels: , , , ,

3 Comments:

At December 15, 2010 at 2:40 PM , Blogger Unknown said...

Edit: I just realized that I never went back to edit the post to explain what actually happened with the emulator. The way to make the emulator work if it doesn't connect right away is to choose to start it manually, then once it is running, switch to the DDMS and use the little downward arrow in the "Devices" window to "reset adb". You can also reset adb manually and it will now pick up the running emulator.

Good luck!

 
At August 10, 2011 at 5:14 AM , Blogger alex said...

how did you integrated droidcouch in your project?

 
At August 12, 2011 at 2:03 PM , Blogger Unknown said...

Have you downloaded the source and added it into your project in Eclipse? It's been a while since I've done this, but I believe it was pretty straightforward or I would have elaborated in my post. The github repo is at https://github.com/sig/DroidCouch

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home