Stephen
Stephen

Reputation: 10079

SqlCipher :UnSatisfiedLinkError dlopen failed :cannot open symbol

I have to do passwod encryption and decryption using sqlite database.I referred this github post.

I am getting failed: dlopen failed: cannot locate symbol Exception at runtime.I am pointed out the error line in below code.

I tried this and this.But it doesn't help me to solve this issue.

StackTrace:

04-15 01:45:02.767: E/dalvikvm(1423): dlopen("/data/app-lib/com.drspaceboo.sqlite2sqlcipher-1/libdatabase_sqlcipher.so") failed: dlopen failed: cannot locate symbol "_ZN7android10MemoryBaseC1ERKNS_2spINS_11IMemoryHeapEEElj" referenced by "libdatabase_sqlcipher.so"...
04-15 01:45:02.767: D/AndroidRuntime(1423): Shutting down VM
04-15 01:45:02.777: W/dalvikvm(1423): threadid=1: thread exiting with uncaught exception (group=0xb3b04ba8)
04-15 01:45:02.777: E/AndroidRuntime(1423): FATAL EXCEPTION: main
04-15 01:45:02.777: E/AndroidRuntime(1423): Process: com.drspaceboo.sqlite2sqlcipher, PID: 1423
04-15 01:45:02.777: E/AndroidRuntime(1423): java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZN7android10MemoryBaseC1ERKNS_2spINS_11IMemoryHeapEEElj" referenced by "libdatabase_sqlcipher.so"...
04-15 01:45:02.777: E/AndroidRuntime(1423):     at java.lang.Runtime.loadLibrary(Runtime.java:364)
04-15 01:45:02.777: E/AndroidRuntime(1423):     at java.lang.System.loadLibrary(System.java:526)
04-15 01:45:02.777: E/AndroidRuntime(1423):     at info.guardianproject.database.sqlcipher.SQLiteDatabase.loadLibs(SQLiteDatabase.java:106)
04-15 01:45:02.777: E/AndroidRuntime(1423):     at com.drspaceboo.sqlite2sqlcipher.SQLite2SQLCipher.onCreate(SQLite2SQLCipher.java:50)
04-15 01:45:02.777: E/AndroidRuntime(1423):     at android.app.Activity.performCreate(Activity.java:5231)
04-15 01:45:02.777: E/AndroidRuntime(1423):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-15 01:45:02.777: E/AndroidRuntime(1423):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
04-15 01:45:02.777: E/AndroidRuntime(1423):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-15 01:45:02.777: E/AndroidRuntime(1423):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
04-15 01:45:02.777: E/AndroidRuntime(1423):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-15 01:45:02.777: E/AndroidRuntime(1423):     at android.os.Handler.dispatchMessage(Handler.java:102)
04-15 01:45:02.777: E/AndroidRuntime(1423):     at android.os.Looper.loop(Looper.java:136)
04-15 01:45:02.777: E/AndroidRuntime(1423):     at android.app.ActivityThread.main(ActivityThread.java:5017)
04-15 01:45:02.777: E/AndroidRuntime(1423):     at java.lang.reflect.Method.invokeNative(Native Method)
04-15 01:45:02.777: E/AndroidRuntime(1423):     at java.lang.reflect.Method.invoke(Method.java:515)
04-15 01:45:02.777: E/AndroidRuntime(1423):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-15 01:45:02.777: E/AndroidRuntime(1423):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-15 01:45:02.777: E/AndroidRuntime(1423):     at dalvik.system.NativeStart.main(Native Method)

Sqlite2SQLCipher.java:

public class SQLite2SQLCipher extends Activity
{
    /*  
     * Please replace the following variables with the ones
     * relevant to your application
     */
    private static final String SQLITE_FILE = "test.sqlite";
    private static final String DB_NAME = "test.db";
    private static final String DB_PASSWORD = "testPassword";
    //Stop replacing here

    private static final String DEBUG_TAG = "SQLite2SQLCipher";

    private SQLiteDatabase database;
    private ProgressDialog progressDialog;

    /*
     * (non-Javadoc)
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //Loading the SQLCipher libraries
        SQLiteDatabase.loadLibs(this);  ----->50th line

        //Preparing the database directories and file to be opened
        File databaseFile = getDatabasePath(DB_NAME);
        databaseFile.mkdirs();
        databaseFile.delete();

        //Opening or Creating the database with our specified password
        database = SQLiteDatabase.openOrCreateDatabase(databaseFile, DB_PASSWORD, null);

        //Making a progress dialog so we can see that the database is still being loaded
        progressDialog = new ProgressDialog(this);
        progressDialog.setCancelable(false);
        progressDialog.setMessage("Creating database");
        progressDialog.show();

        /*
         * Creating the database from the .sqlite file. We do this in
         * an AsyncTask so that we aren't locking the UI thread.
         */
        new CreateDatabaseFromFileTask().execute();
    }

  private class CreateDatabaseFromFileTask extends AsyncTask<Void, Void, Void>
    {
        @Override
        protected Void doInBackground(Void... params)
        {
            StringBuilder statement = new StringBuilder();
            String line;
            int lineCount = 1;
            int statementCount = 1;
            BufferedReader reader = null;

            try
            {
                //Opening the .sqlite file from the Assets folder
                reader = new BufferedReader(new InputStreamReader(getAssets().open(SQLITE_FILE)));

                while((line = reader.readLine()) != null)
                {
                    //A very handy line count log
                    Log.d(DEBUG_TAG,"Reading line " + lineCount);
                    if(line.length() > 1)
                    {
                        statement.append(line);

                        //If this line is the end of the statement we run that statement
                        if(line.matches(".*;$"))
                        {
                            //Getting the string from the String Builder
                            String statementString = statement.toString();
                            statement = new StringBuilder();

                            //Logging the statement, this might help with debugging any problems you encounter
                            Log.d(DEBUG_TAG,"Statement #" + statementCount + "\"" + statementString + "\"");
                            statementCount++;

                            //Loading the statement into the database
                            database.execSQL(statementString);
                        }
                    }
                    lineCount++;
                }

                //Closing the progress dialog
                progressDialog.dismiss();
                //Updating the UI with a success message
                updateUIWithSuccess();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            finally
            {
                //Closing the buffered reader
                try
                {
                    reader.close();
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            //Closing the database
            database.close();
            return null;
        }
    }


}

In asset/test.sqlite:

CREATE TABLE `user` (
  `ID` INTEGER NOT NULL PRIMARY KEY,
  `email` TEXT NOT NULL,
  `name` TEXT NOT NULL);

INSERT INTO `user` (`email`,`name`) VALUES ("[email protected]", "Text User One");
/*
 * This is a test of the multiline comment removal
*/
INSERT INTO `user` (`email`,`name`) VALUES ("[email protected]", "Text User Two");
-- This is a test of the single line comment removal
INSERT INTO `user` (`email`,`name`) VALUES ("[email protected]", "Text User Three");

INSERT INTO `user` (`email`,`name`) VALUES ("[email protected]", "Text User Four");
INSERT INTO `user` (`email`,`name`) VALUES ("[email protected]", "Text User Five");

enter image description here

java build path -> Libraries:

enter image description here

Anyone can help me with this.Thank you.

Upvotes: 0

Views: 1176

Answers (1)

Harsha Vardhan
Harsha Vardhan

Reputation: 3344

SQLCipher for Android 2.2.0 release

A change to the native CursorWindow to remove usage of private android::MemoryBase

With the release of 2.2.0, we can identify there are lot of changes happened in the sqlcipher in the map of android OS. So, there are UnsatisfiedLinkError are occurring due to *.so files

Take the latest binaries, can be found here, which works for 4.4

Upvotes: 1

Related Questions