android - greenDAO Android 没有在文件数据库中创建表
问题描述
我按照https://blog.mindorks.com/powerful-android-orm-greendao-3-tutorial的指南将 greenDAO 集成到我的 android 项目中,我遵循一切(或者我认为 XD),当我尝试我的移动它没有创建表,创建数据库文件但是当我用查看器打开它时它没有显示任何东西。
我没有如何在模拟器中进行测试以查看这是否是手机问题或我需要的某些权限问题。
我将离开该项目,看看您是否可以帮助我,非常感谢。
https://anonfile.com/R6j6J2d5o1/Test_zip
文件清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cafl.test">
<application
android:name="com.cafl.test.AppDbController"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.cafl.test.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
文件 gradle 项目
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.0'
classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
文件分级模块
apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.cafl.test"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
greendao{
schemaVersion 1
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'org.greenrobot:greendao:3.2.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
DaoMaster 和 DaoSession 它创建来构建项目
并且当我正在测试时,我正在使用原始的 DaoMaster 功能
mDaoSession = new DaoMaster(
new DaoMaster.DevOpenHelper(this, "greendao_demo.db").getWritableDb()).newSession();
解决方案
只需检查您的项目,它运行良好。在 MainActivity 你可以查询并设置为 textView,记住设置你的 textview id 为 nameTv:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = (TextView) findViewById(R.id.nameTv);
// Put this in a different thread or use AsyncSession in greenDAO.
// For Demo purpose, this query is made on main thread but it should in a different thread.
M_User user = ((AppDbController)getApplication()).getDaoSession().getM_UserDao().load(1L);
if(user != null){
textView.setText(user.getFullName());
}
}
}
推荐阅读
- azure - 如何使用自定义脚本扩展将多个脚本部署到 Azure Windows VM?
- reactjs - 使用 ApolloClient 从 useContext 钩子导入一个简单的变量
- java - Java中的获取平均值方法
- postgresql - 使用 WHERE 的情况
- javascript - 如果用户启用了更安静的消息传递,Notification.requestPermission 承诺永远不会得到解决
- reactjs - 禁用受控表单上的提交按钮反应
- octobercms - OctoberCMS 博客插件与最近的帖子
- url - 尝试使用 MFC 运行带参数的 PHP 文件
- sql-server - 如何限制我的用户在 SQL Server 中的输出行数?
- azure-devops - 在“下载构建工件”任务中,如何将“构建管道”指定为变量值?