Android的误差sqlcipher上版本的Andr​​oid 4.2.2 [英] Android error with sqlcipher on version android 4.2.2

查看:705
本文介绍了Android的误差sqlcipher上版本的Andr​​oid 4.2.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,当我尝试推出在Android 4.2.2我的项目。
这里是堆栈跟踪:

  11月8日至6日:00:50.041:E / AndroidRuntime(10606):net.sqlcipher.database.SQLiteException:产生的原因不是错误
11月8日至6日:00:50.041:E / AndroidRuntime(10606):在net.sqlcipher.database.SQLiteDatabase.dbopen(本机方法)
。11月8日至6日:00:50.041:E / AndroidRuntime(10606):在net.sqlcipher.database.SQLiteDatabase<&初始化GT;(SQLiteDatabase.java:1951)
。11月8日至6日:00:50.041:E / AndroidRuntime(10606):在de.greenrobot.dao.wrapper.SQLiteDatabaseWrapper<&初始化GT;(SQLiteDatabaseWrapper.java:61)
11月8日至6日:00:50.041:E / AndroidRuntime(10606):在de.greenrobot.dao.wrapper.SQLiteDatabaseWrapper.openDatabase(SQLiteDatabaseWrapper.java:224)
11月8日至6日:00:50.041:E / AndroidRuntime(10606):在de.greenrobot.dao.wrapper.SQLiteDatabaseWrapper.openOrCreateDatabase(SQLiteDatabaseWrapper.java:276)
11月8日至6日:00:50.041:E / AndroidRuntime(10606):在de.greenrobot.dao.wrapper.SQLiteOpenHelperWrapper.getWritableDatabase(SQLiteOpenHelperWrapper.java:95)
11月8日至6日:00:50.041:E / AndroidRuntime(10606):在com.e_i.bad.utils.DAOManager.DAOInit(DAOManager.java:62)

这正常工作在Android 4.0.4,但是当我启动Android 4.2多数民众赞成崩溃的时间与例外。我给在官方网站sqlcipher的来源,我希望那是我所采取的最后一个来源(名字是SQLCipher +的+ Android + 2.2.0),我不看到了一个最新版本的这个项目的。

在预先感谢您的回答(我希望这不是一个重复的问题,引起我搜索并没有找到答案......)

编辑:
来源:

  =帮手新DaoMaster.DevOpenHelper(的getContext(),ID,密码为空);
            DB = helper.getWritableDatabase();
            daoMaster =新DaoMaster(DB);
            daoSession = daoMaster.newSession();公共静态类DevOpenHelper扩展OpenHelper {    公共DevOpenHelper(上下文的背景下,字符串名称,字符串密码,CursorFactory厂){
        超(背景下,名,密码,工厂);
    }    @覆盖
    公共无效onUpgrade(SQLiteDatabaseWrapper分贝,INT oldVersion,诠释静态网页){
        dropAllTables(分贝,真正的);
        的onCreate(DB);
    }
}公共静态抽象类OpenHelper扩展SQLiteOpenHelperWrapper {    公共OpenHelper(上下文的背景下,字符串名称,字符串密码,CursorFactory厂){
        超级(上下文,姓名,口令,工厂,SCHEMA_VERSION);
    }    @覆盖
    公共无效的onCreate(SQLiteDatabaseWrapper DB){
        createAllTables(DB,FALSE);
    }
}公共同步SQLiteDatabaseWrapper getWritableDatabase(){
    如果(mDatabase =空&放大器;!&放大器; mDatabase.isOpen()及&放大器;!mDatabase.isReadOnly()){
        返回mDatabase; //数据库已开门营业
    }    如果(mIsInitializing){
        抛出新IllegalStateException异常(getWritableDatabase递归调用);
    }    //如果我们有一个只读数据库打开,有人可能会使用它
    //(虽然他们不应该),这将导致举行的锁
    //该文件,我们试图打开数据库的读写会
    //失败等待文件锁。以prevent的是,我们获得了
    //只读数据库,它关闭了其他用户的锁。    布尔成功= FALSE;
    SQLiteDatabaseWrapper DB = NULL;
    如果(mDatabase!= NULL)
        mDatabase.lock();
    尝试{
        mIsInitializing = TRUE;
        如果(MNAME == NULL){
            DB = SQLiteDatabaseWrapper.create(NULL,mPassword);
        }其他{
            字符串路径= mContext.getDatabasePath(MNAME).getPath();            文件dbPathFile =新的文件(路径);
            如果(!dbPathFile.exists())
                dbPathFile.getParentFile()mkdirs()。            DB = SQLiteDatabaseWrapper.openOrCreateDatabase(路径,mPassword,mFactory);
        }        INT版本= db.getVersion();
        如果(版本!= mNewVersion){
            db.beginTransaction();
            尝试{
                如果(版本== 0){
                    的onCreate(DB);
                }其他{
                    如果(版本> mNewVersion){
                        Log.w(TAG,不能降级只读从版本数据库+版本+到+ mNewVersion +:+ db.getPath());
                    }
                    onUpgrade(DB,版本,mNewVersion);
                }
                db.setVersion(mNewVersion);
                db.setTransactionSuccessful();
            } {最后
                db.endTransaction();
            }
        }        的OnOpen(DB);
        成功= TRUE;
        返回分贝;
    } {最后
        mIsInitializing = FALSE;
        如果(成功){
            如果(mDatabase!= NULL){
                尝试{
                    mDatabase.close();
                }赶上(例外五){
                }
                mDatabase.unlock();
            }
            mDatabase = DB;
        }其他{
            如果(mDatabase!= NULL)
                mDatabase.unlock();
            如果(DB!= NULL)
                db.close();
        }
    }
}公共SQLiteOpenHelperWrapper(上下文的背景下,字符串名称,字符串密码,CursorFactory工厂,诠释的版本){
    如果(版本< 1)
        抛出新抛出:IllegalArgumentException(版本必须是> = 1,呈+版);    mContext =背景;
    MNAME =名称;
    mPassword =密码;
    mFactory =厂;
    mNewVersion =版本;    如果(mPassword =空&放大器;!&放大器; mPassword.length()大于0){
        //如果需要装载SQLcipher库
        SQLiteDatabaseWrapper.loadLibs(mContext);
    }
}

编辑2:

  SQLiteDatabase.loadLibs(的getContext());
        字符串路径=;
        尝试{
            。PATH =的getContext()getDatabasePath(pathDB +.db的)的getPath();
        }赶上(空preferencesException E){        }
        文件dbPathFile =新的文件(路径);
        如果(!dbPathFile.exists()){
            dbPathFile.getParentFile()mkdirs()。
        }
        SQLiteDatabase数据库= SQLiteDatabase.openOrCreateDatabase(路径,123456,NULL);
        DB =新SQLiteDatabaseWrapper(数据库);        daoMaster =新DaoMaster(DB);
        daoSession = daoMaster.newSession();


解决方案

这就是Finaly工作。为了这个,我只是把greenDao取代net.sqlcipher android.database所有导入库然后我出口这一新greenDao中的.jar我拿SQLCipher.jar不要忘了进口commons- codec.jar和guavra-R09加的.jar文件夹armeabi和文件夹,从86和SQLCipher文件夹中的资产文件icudt46l.zip。

在我来说,我有一个包含SQLCipher是依赖关系和我的项目的Andr​​oid依赖于该daocore项目多数民众赞成在Android 4.1及较少,但没有奏效4.2,更使问题是项目之间的依赖关系,我的一个项目daocore不知道为什么,但如果你导入所有源项目多数民众赞成在工作所有Android完蛋了。

I have a problem when i try to launch my project on Android 4.2.2. Here is the stacktrace :

08-06 11:00:50.041: E/AndroidRuntime(10606): Caused by: net.sqlcipher.database.SQLiteException: not an error
08-06 11:00:50.041: E/AndroidRuntime(10606):    at net.sqlcipher.database.SQLiteDatabase.dbopen(Native Method)
08-06 11:00:50.041: E/AndroidRuntime(10606):    at net.sqlcipher.database.SQLiteDatabase.<init>(SQLiteDatabase.java:1951)
08-06 11:00:50.041: E/AndroidRuntime(10606):    at de.greenrobot.dao.wrapper.SQLiteDatabaseWrapper.<init>(SQLiteDatabaseWrapper.java:61)
08-06 11:00:50.041: E/AndroidRuntime(10606):    at de.greenrobot.dao.wrapper.SQLiteDatabaseWrapper.openDatabase(SQLiteDatabaseWrapper.java:224)
08-06 11:00:50.041: E/AndroidRuntime(10606):    at de.greenrobot.dao.wrapper.SQLiteDatabaseWrapper.openOrCreateDatabase(SQLiteDatabaseWrapper.java:276)
08-06 11:00:50.041: E/AndroidRuntime(10606):    at de.greenrobot.dao.wrapper.SQLiteOpenHelperWrapper.getWritableDatabase(SQLiteOpenHelperWrapper.java:95)
08-06 11:00:50.041: E/AndroidRuntime(10606):    at com.e_i.bad.utils.DAOManager.DAOInit(DAOManager.java:62)

This worked fine on an Android 4.0.4 but when i launch on Android 4.2 thats all time crash with that exception. I give the source of sqlcipher in official web site and i hope that was the last source that i have taken (name was SQLCipher+for+android+2.2.0), i don't saw a latest version of this project.

Thanks in advance for your answer (and i hope that isn't a duplication question caused i search and don't find answer...)

Edit : Source :

helper = new DaoMaster.DevOpenHelper(getContext(), id, password, null);
            db = helper.getWritableDatabase();
            daoMaster = new DaoMaster(db);
            daoSession = daoMaster.newSession();

public static class DevOpenHelper extends OpenHelper {

    public DevOpenHelper(Context context, String name, String password, CursorFactory factory) {
        super(context, name, password, factory);
    }

    @Override
    public void onUpgrade(SQLiteDatabaseWrapper db, int oldVersion, int newVersion) {
        dropAllTables(db, true);
        onCreate(db);
    }
}

public static abstract class OpenHelper extends SQLiteOpenHelperWrapper {

    public OpenHelper(Context context, String name, String password, CursorFactory factory) {
        super(context, name, password, factory, SCHEMA_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabaseWrapper db) {
        createAllTables(db, false);
    }
}

public synchronized SQLiteDatabaseWrapper getWritableDatabase() {
    if (mDatabase != null && mDatabase.isOpen() && !mDatabase.isReadOnly()) {
        return mDatabase; // The database is already open for business
    }

    if (mIsInitializing) {
        throw new IllegalStateException("getWritableDatabase called recursively");
    }

    // If we have a read-only database open, someone could be using it
    // (though they shouldn't), which would cause a lock to be held on
    // the file, and our attempts to open the database read-write would
    // fail waiting for the file lock. To prevent that, we acquire the
    // lock on the read-only database, which shuts out other users.

    boolean success = false;
    SQLiteDatabaseWrapper db = null;
    if (mDatabase != null)
        mDatabase.lock();
    try {
        mIsInitializing = true;
        if (mName == null) {
            db = SQLiteDatabaseWrapper.create(null, mPassword);
        } else {
            String path = mContext.getDatabasePath(mName).getPath();

            File dbPathFile = new File(path);
            if (!dbPathFile.exists())
                dbPathFile.getParentFile().mkdirs();

            db = SQLiteDatabaseWrapper.openOrCreateDatabase(path, mPassword, mFactory);
        }

        int version = db.getVersion();
        if (version != mNewVersion) {
            db.beginTransaction();
            try {
                if (version == 0) {
                    onCreate(db);
                } else {
                    if (version > mNewVersion) {
                        Log.w(TAG, "Can't downgrade read-only database from version " + version + " to " + mNewVersion + ": " + db.getPath());
                    }
                    onUpgrade(db, version, mNewVersion);
                }
                db.setVersion(mNewVersion);
                db.setTransactionSuccessful();
            } finally {
                db.endTransaction();
            }
        }

        onOpen(db);
        success = true;
        return db;
    } finally {
        mIsInitializing = false;
        if (success) {
            if (mDatabase != null) {
                try {
                    mDatabase.close();
                } catch (Exception e) {
                }
                mDatabase.unlock();
            }
            mDatabase = db;
        } else {
            if (mDatabase != null)
                mDatabase.unlock();
            if (db != null)
                db.close();
        }
    }
}

public SQLiteOpenHelperWrapper(Context context, String name, String password, CursorFactory factory, int version) {
    if (version < 1)
        throw new IllegalArgumentException("Version must be >= 1, was " + version);

    mContext = context;
    mName = name;
    mPassword = password;
    mFactory = factory;
    mNewVersion = version;

    if (mPassword != null && mPassword.length() > 0) {
        // Load SQLcipher libraries if needed
        SQLiteDatabaseWrapper.loadLibs(mContext);
    }
}

Edit 2 :

SQLiteDatabase.loadLibs(getContext());
        String path = "";
        try {
            path = getContext().getDatabasePath(pathDB + ".db").getPath();
        } catch (NullPreferencesException e) {

        }
        File dbPathFile = new File(path);
        if (!dbPathFile.exists()) {
            dbPathFile.getParentFile().mkdirs();
        }
        SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(path, "123456", null);
        db = new SQLiteDatabaseWrapper(database);

        daoMaster = new DaoMaster(db);
        daoSession = daoMaster.newSession();

解决方案

Finaly thats work. For this i just take greenDao replace all import library android.database by net.sqlcipher then i export this new greenDao in .jar i take the SQLCipher.jar don't forgot to import commons-codec.jar and guavra-r09.jar plus folder armeabi and folder x86 from SQLCipher and in folder assets the file icudt46l.zip.

In my case i have a project daocore that contains the SQLCipher and is dependancies and my project Android dependant of that daocore project thats worked in Android 4.1 and less but not in 4.2 and more so the problem was the dependencies between project, i don't know why but if you import all in the source project thats work in all Android thats it.

这篇关于Android的误差sqlcipher上版本的Andr​​oid 4.2.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆