导入GreenDao后android studio无法解析DaoMaster

时间:2019-05-13 02:48:15

标签: android greendao

下面是项目build.gradle和应用程序build.gradle文件

//project build.gradle
buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0'
        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2'
    }
}

    //app build.gradle
    apply plugin: 'org.greenrobot.greendao' // apply plugin
    apply plugin: 'com.android.application'

    android {
        compileSdkVersion 28
        defaultConfig {
            applicationId "com.flover.greendaodemo"
            minSdkVersion 21
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:28.0.0'
        implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha5'
        testImplementation 'junit:junit:4.13-beta-3'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
        implementation 'com.android.support:recyclerview-v7:28.0.0'

        implementation 'org.greenrobot:greendao:3.2.2'
    }

当使用DaoMaster.DevOpenHelper helper =新的DaoMaster.DevOpenHelper(this,“ notes-db”,null)时,显示错误,无法解析DaoMaster。 怎么了?

1 个答案:

答案 0 :(得分:0)

我参加聚会有点晚了,但是您需要至少有一个@Entity类,GreenDao才能生成DaoMaster和DaoSession之类的类。

因此,只需创建一个用@Entity和所需属性注释的类,然后单击Build->在AndroidStudio中进行构建或Build->在IntelliJ中进行清理构建。您也可以单击AndroidStudio或IntelliJ右侧的Gradle选项卡,查找GreenDao Gradle任务并运行它。