Search code examples
androidgreendao

android studio can't resolve DaoMaster after import GreenDao


below are project build.gradle and app build.gradle files

//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'
    }

When using DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "notes-db", null),show me error, can't resolve DaoMaster. What wrong with that?


Solution

  • I'm a bit late to the party but you need to have at least one @Entity class in order for GreenDao to be able to generate classes like DaoMaster and DaoSession.

    So, simply create a class annotated with @Entity and the properties you need and click Build -> Make Build in AndroidStudio or Build -> Clean Build in IntelliJ. You can also click on the Gradle tab on the right side of AndroidStudio OR IntelliJ, look for the GreenDao Gradle task and run that.