6

I am trying to write an Android test case on a block of code in the android application.the block of code will interact with the database (sqlcipher library functions) specifically dbopen() function. When running the application, it is working fine. When we were trying to execute the test case for that block of code(which involves database interaction). It is giving following error: java.lang.UnsatisfiedLinkError: dbopen

Could any look into this and suggest.

Can't a test case has authority to call a function which is calling sqlcipher library functions. Any permissions required, or Any specific procedure is there for this type of test cases ?

complete Error log:

            04-30 12:08:33.997: I/TestRunner(2169): started: teststateMachine(com.americanlogistics.mdd.rhapsody.view.test.SigninViewsateMachineTest)
            04-30 12:08:34.147: W/dalvikvm(2169): No implementation found for native Linfo/guardianproject/database/sqlcipher/SQLiteDatabase;.dbopen (Ljava/lang/String;I)V
            04-30 12:08:34.164: I/TestRunner(2169): failed: teststateMachine(com.americanlogistics.mdd.rhapsody.view.test.SigninViewsateMachineTest)
            04-30 12:08:34.164: I/TestRunner(2169): ----- begin exception -----
            04-30 12:08:34.184: I/TestRunner(2169): java.lang.UnsatisfiedLinkError: dbopen
            04-30 12:08:34.184: I/TestRunner(2169):     at info.guardianproject.database.sqlcipher.SQLiteDatabase.dbopen(Native Method)
            04-30 12:08:34.184: I/TestRunner(2169):     at info.guardianproject.database.sqlcipher.SQLiteDatabase.<init>(SQLiteDatabase.java:1870)
            04-30 12:08:34.184: I/TestRunner(2169):     at info.guardianproject.database.sqlcipher.SQLiteDatabase.openDatabase(SQLiteDatabase.java:863)
            04-30 12:08:34.184: I/TestRunner(2169):     at info.guardianproject.database.sqlcipher.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:897)
            04-30 12:08:34.184: I/TestRunner(2169):     at info.guardianproject.database.sqlcipher.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:107)
            04-30 12:08:34.184: I/TestRunner(2169):     at com.americanlogistics.mdd.rhapsody.database.SendQueueDBAdapter.open(SendQueueDBAdapter.java:45)
            04-30 12:08:34.184: I/TestRunner(2169):     at com.americanlogistics.mdd.rhapsody.database.SendQueueDBAdapter.databaseHelperInstance(SendQueueDBAdapter.java:38)
            04-30 12:08:34.184: I/TestRunner(2169):     at com.americanlogistics.mdd.rhapsody.common.ApplicationController.startDatabase(ApplicationController.java:530)
            04-30 12:08:34.184: I/TestRunner(2169):     at com.americanlogistics.mdd.rhapsody.view.test.SigninViewsateMachineTest.teststateMachine(SigninViewsateMachineTest.java:61)
            04-30 12:08:34.184: I/TestRunner(2169):     at java.lang.reflect.Method.invokeNative(Native Method)
            04-30 12:08:34.184: I/TestRunner(2169):     at java.lang.reflect.Method.invoke(Method.java:507)
            04-30 12:08:34.184: I/TestRunner(2169):     at junit.framework.TestCase.runTest(TestCase.java:154)
            04-30 12:08:34.184: I/TestRunner(2169):     at junit.framework.TestCase.runBare(TestCase.java:127)
            04-30 12:08:34.184: I/TestRunner(2169):     at junit.framework.TestResult$1.protect(TestResult.java:106)
            04-30 12:08:34.184: I/TestRunner(2169):     at junit.framework.TestResult.runProtected(TestResult.java:124)
            04-30 12:08:34.184: I/TestRunner(2169):     at junit.framework.TestResult.run(TestResult.java:109)
            04-30 12:08:34.184: I/TestRunner(2169):     at junit.framework.TestCase.run(TestCase.java:118)
            04-30 12:08:34.184: I/TestRunner(2169):     at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
            04-30 12:08:34.184: I/TestRunner(2169):     at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
            04-30 12:08:34.184: I/TestRunner(2169):     at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529)
            04-30 12:08:34.184: I/TestRunner(2169):     at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)
            04-30 12:08:34.184: I/TestRunner(2169): ----- end exception -----

Code:

The below line in the test case is indirectly calling sqlcipher library function.

ApplicationController.getInstance().startDatabase(this.getContext().getApplicationContext());

Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186
candy
  • 734
  • 1
  • 11
  • 22

3 Answers3

18

I encountered the same error while intergrating SQLCipher for Android. The solution for me was to call

SQLiteDatabase.loadLibs(Context context)

before working with the database itself, as recommended. A good place to call that is in the Application's derived class.

Please see the instructions here

Jerome
  • 1,749
  • 1
  • 14
  • 40
ivohad
  • 211
  • 2
  • 5
  • Yes, we are using same but, even though getting java.lang.UnsatisfiedLinkError: no sqlcipher in java.library.path. Note: This error coming for only Robolectric unit test cases. – sandeepmaaram Oct 05 '17 at 12:31
1
No implementation found for native Linfo/guardianproject/database/sqlcipher/SQLiteDatabase;.dbopen (Ljava/lang/String;I)V

It seems you code is incompatible with version you are running. Make sure they are compatible.

kosa
  • 65,990
  • 13
  • 130
  • 167
0

http://www.coderanch.com/t/79145/Websphere/Native-lib-already-loaded-another

This "unsatisfy link" error may be due to the fact that a class has been loaded, but by the wrong classloader in the hierarchy of runtime classloaders.

Wild guess is that the Sqllite package is there and in the Classpath ,but in the scenario with running your tests, the wrong loader instance has loaded the DB packages.

Robert Rowntree
  • 6,230
  • 2
  • 24
  • 43