我必须使用sqlite数据库进行passwod加密和解密。我引用了这个github post。
我在运行时得到failed: dlopen failed: cannot locate symbol
异常。我在下面的代码中指出了错误行。
堆栈跟踪:
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;
}
}
}
在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 ("test1@test.com", "Text User One");
/*
* This is a test of the multiline comment removal
*/
INSERT INTO `user` (`email`,`name`) VALUES ("test2@test.com", "Text User Two");
-- This is a test of the single line comment removal
INSERT INTO `user` (`email`,`name`) VALUES ("test3@test.com", "Text User Three");
INSERT INTO `user` (`email`,`name`) VALUES ("test4@test.com", "Text User Four");
INSERT INTO `user` (`email`,`name`) VALUES ("test5@test.com", "Text User Five");
java构建路径 - &gt;库:
任何人都可以帮助我。谢谢。
答案 0 :(得分:1)
更改本机CursorWindow以删除私有android :: MemoryBase
的使用随着2.2.0的发布,我们可以发现在android OS的地图中sqlcipher发生了很多变化。因此,由于* .so文件
,会发生UnsatisfiedLinkError获取最新的二进制文件,可以找到here,适用于4.4