Prateek Ratnaker Prateek Ratnaker - 1 month ago 6
Android Question

GreenDao Cannot find org.greenrobot.greendao.annotation.*

I have started with greendao 3.2. I added greendao jar in libs folder and added it as library. I generated my entities using greendao-generator. It generates entities but the generated entities java some annotations and android studio is giving error on these annotations.It is giving an error cannot find "org.greenrobot.greendao.annotation.*". How to resolve this?

Answer

Probably you didn't add the library in your app module . First of all rather than using jar , you can use gradle dependency . In your generator project add the following dependency

compile 'org.greenrobot:greendao-generator:3.2.0'

So the gradle file of your generator module , should be look like this

    apply plugin: 'java'

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'org.greenrobot:greendao-generator:3.2.0'
    }

And in your gradle file (module app) add the following

    compile 'org.greenrobot:greendao:3.2.0'  

Your main gradle file (module app) should be like this

  apply plugin: 'com.android.application'

    android {
        compileSdkVersion 24
        buildToolsVersion "24.0.2"

        defaultConfig {
            applicationId "com.tcs.a1003548.greendao"
            minSdkVersion 14
            targetSdkVersion 24
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:24.2.0'
        compile 'org.greenrobot:greendao:3.2.0'

    }