【发布时间】:2023-03-13 17:46:01
【问题描述】:
我一直在尝试让 Nativescript 与 SQLite 和我运行 Nougat (7.1.2)、SDK 25 的外部设备一起使用。
我收到以下错误:
Error: java.lang.NoClassDefFoundError: android.database.sqlite.SQLiteDatabase$OpenParams
我有一个扩展 SQLiteOpenHelper 的类
class DatabaseHelper extends android.database.sqlite.SQLiteOpenHelper {
static constructorCalled: boolean = false;
constructor(context: android.content.Context) {
super(context, '/data/user/0/org.nativescript.synctest/databases/swiftr.sqlite', null, 2);
DatabaseHelper.constructorCalled = true;
return global.__native(this);
}
onCreate(db: android.database.sqlite.SQLiteDatabase) { }
onUpdate(
db: android.database.sqlite.SQLiteDatabase,
oldVersion: number,
newVersion: number
) { }
}
我正在尝试像这样打开 SQLite 数据库:
const mOpenHelper: android.database.sqlite.SQLiteOpenHelper = new DatabaseHelper(application.android.context);
const sql = "SELECT name FROM sqlite_master WHERE type ='table' AND name NOT LIKE '%sqlite_%'";
const cursor = mOpenHelper.getReadableDatabase().rawQuery(sql, null);
const tables: string[] = [];
if (cursor.moveToFirst()) {
while (!cursor.isAfterLast() ) {
tables.push(cursor.getString(cursor.getColumnIndex('name')));
}
}
console.log('Tables: ', [tables]);
然后当我尝试在组件中使用这个类时,我得到了错误,
Error: java.lang.NoClassDefFoundError: android.database.sqlite.SQLiteDatabase$OpenParams
我进行了一些挖掘,发现SQLiteDatabase$OpenParams仅在版本27中添加到SDK中。然后我尝试将app.gradle中的compileSdkVersion设置为25,现在我收到以下错误:
app.gradle:
android {
compileSdkVersion 25
defaultConfig {
minSdkVersion 25
generatedDensities = []
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
错误:
AAPT: error: style attribute 'android:attr/forceDarkAllowed' not found.
AAPT: error: resource android:attr/colorError not found.
AAPT: error: style attribute 'android:attr/keyboardNavigationCluster' not found.
这里我只列出了三个,但其中有很多。
谁能帮我解决这个问题...我真的很难解决这个问题。
提前致谢。
【问题讨论】:
标签: java android sqlite nativescript