Ошибка во время обновление sqlcipher с 3x на 4x
SВ проекте используется библиотека net.zetetic:android-database-sqlcipher:3.5.9@aar
.
Каласс OpenHelper:
public class DBHelperKey extends SQLiteOpenHelper {
private static DBHelperKey instance;
SQLiteDatabase db;
public DBHelperKey(Context context) {
super(context, "base.db", null, 1);
}
static public synchronized DBHelperKey getInstance(Context context) {
if (instance == null) {
instance = new DBHelperKey(context);
}
return instance;
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL("Create table mysettings (id TEXT PRIMARY KEY,myvalue TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
onCreate(sqLiteDatabase);
sqLiteDatabase.execSQL("DROP table if exists mysettings");
}
public void set(String mykey, String myvalue) {
if (!exist(mykey)) {
db.execSQL("insert into mysettings(id,myvalue) values('" + mykey + "','" + myvalue + "')");
} else {
db.execSQL("update mysettings set myvalue='" + myvalue + "' where id='" + mykey + "'");
}
}
public void remove(String mykey) {
db.execSQL("delete from mysettings where id='" + mykey + "'");
}
public String get(String mykey) {
String res = null;
Cursor cursor = db.rawQuery("select myvalue from mysettings where id = '" + mykey + "'", null);
cursor.moveToLast();
try {
res = cursor.getString(cursor.getColumnIndex("myvalue"));
} catch (Exception ignored) {
}
cursor.close();
cursor.deactivate();
//db.close();
return res;
}
public Boolean exist(String mykey) {
boolean res = false;
Cursor cursor = db.rawQuery("select count(myvalue)as cnt from mysettings where id = '" + mykey + "'", null);
cursor.moveToLast();
if (Integer.parseInt(cursor.getString(cursor.getColumnIndex("cnt"))) > 0) {
res = true;
}
cursor.close();
cursor.deactivate();
return res;
}
public void openDB(String key) {
Boolean res = false;
try {
db = instance.getWritableDatabase(key);
} catch (Exception ex) {
Log.e("openDB_ex", ex.toString());
}
}
}
Необходимо было обновить версию библиотеки.
Письмо от google : net.zetetic:android-database-sqlcipher has reported android-database-sqlcipher:3.5.9 as outdated. You may not be able to release future versions of your app with this SDK version to production or open testing.
Я обновил библиотеку на
implementation 'net.zetetic:sqlcipher-android:4.5.6@aar'
implementation 'androidx.sqlite:sqlite:2.4.0'
После обновления приложение, ошибка лога "openDB_ex"
в openDB()
- android.database.sqlite.SQLiteException: file is not a database (code 26): , while compiling: PRAGMA journal_mode
.
Подскажите пожалуйста, решение данной проблемы.