Couchbase Lite and Robolectric or: How to load native libraries?

639 views
Skip to first unread message

schmit...@googlemail.com

unread,
Sep 14, 2014, 12:39:48 PM9/14/14
to robol...@googlegroups.com
Hey guys,

after the pain of setting up Robolectric with Android Studio I am facing another problem now:
I get an UnsatisfiedLinkError when using Robolectric on an activity, which uses Couchbase Lite. Couchbase Lite, apparently, relies on native libraries to perform.

So I read a lot about this (at least what I could find). I tried the following things:
Using gradlew -Djava.library.path=bla/bla/bla test (with an absolute path to the directory and an relative path beginning from project root). 
I also added the following to my build gradle:

tasks.withType(Test) {
    systemProperty
"java.library.path", "src/main/jniLibs"
}

(and with an absolute path)

Because all this ends up in UnsatisfiedLinkErrors I tried loading the library with the following command:

System.load("/path/to/library/armeabi-v7a/com_couchbase_touchdb_TDCollateJSON.so");


The library is found. But the following Error occurs:

java.lang.UnsatisfiedLinkError: /path/to/lib/armeabi-v7a/com_couchbase_touchdb_TDCollateJSON.so:  no suitable image found.  Did find:  /path/to/lib/armeabi-v7a/com_couchbase_touchdb_TDCollateJSON.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00


To sum it up: I assume I am facing two problems here.
The first one is: How to set the correct library path for gradlew?

And the second one, which is more painful:
Since Robolectric does not use the Emulator or an Android device to run the tests, it runs on my Mac. And the *.so library is not a native Mac library, this is why it says: "unknown filetype" in the error above. This leads me to the question? Does anybody know how to avoid loading the library? Or does anybody know if there are Mac libraries of Couchbase, which I could use? 

I appreciate your effort and am looking forward to your answers.

Cheers,
Jan

Xavier Gouchet

unread,
Jan 26, 2015, 4:29:11 AM1/26/15
to robol...@googlegroups.com
Hi Jan, 

I'm facing the same problem myself, did you manage to have a running test with native libraries ? 

Best regards

benwilcock

unread,
Jan 29, 2015, 7:24:53 AM1/29/15
to robol...@googlegroups.com
Ditto Jan!

I'm getting the exact same UnsatisfiedLinkError problem with Robolectric 2.4, Android Studio 1.1 Preview and Couchbase lite.

Did a solution come to light or must one simply choose between couchbase-lite and robolectric?

Cheers

schmit...@googlemail.com

unread,
Jan 30, 2015, 6:05:27 AM1/30/15
to robol...@googlegroups.com
Hey guys.

No, I did not find a solution yet... I do not think it is possible to test your app with a native database connection, but it should be possible to mock Couchbase w/ robolectric. Of course you have to find other ways to test your database connection then, but you can benefit from robolectric in UI tests and other things without the annoying emulator though. Maybe this http://www.bignerdranch.com/blog/testing-the-android-way/ and that https://github.com/mutexkid/android-studio-robolectric-example may give an idea.

Since I did not have the time to focus on Android dev in the last couple month, I did not try it though. I will post a solution to this here as soon as I have one.
Nevertheless I'd be glad if anyone has another idea to this topic.

Cheers
Reply all
Reply to author
Forward
0 new messages