greenrobot / greenDAO

greenDAO is a light & fast ORM solution for Android that maps objects to SQLite databases.
http://greenrobot.org/greendao/
12.63k stars 2.89k forks source link

Using DAO in Library module #568

Closed karntrehan closed 7 years ago

karntrehan commented 7 years ago

Following is the structure of the our app:

app_core is the library module which should contain all the daos which would be accessed by app_feature1,app_feature_2, etc.. Also app_core should also contain the generated DaoMaster, DaoSession among other generated files. Currently the generated files only seem to work in the 'app' module. We tried to play with the targetGenDir and daoPackage parameters in app_core to change the generation path, but did not help.

Following is the excerpt of the build.gradle (project)

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath 'org.greenrobot:greendao-gradle-plugin:3.1.1'
    }
}
ext {
    minSdkVersion = 15
    targetSdkVersion = 25
    compileSdkVersion = 25
    buildToolsVersion = '25.0.2'
    sourceCompatibilityVersion = JavaVersion.VERSION_1_7
    targetCompatibilityVersion = JavaVersion.VERSION_1_7
}

ext.deps = [
        //https://github.com/greenrobot/greenDAO#add-greendao-to-your-project
        greendao            : "org.greenrobot:greendao:3.1.1"
]

Following is the excerpt of the build.gradle(app_core):

apply plugin: 'com.android.library'
apply plugin: 'org.greenrobot.greendao'

android {
................
}

greendao {
    schemaVersion 5
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile deps.greendao
}
greenrobot commented 7 years ago

Currently the generated files only seem to work in the 'app' module. What exactly happens when you try it on a library module?

We'll look into it - probably next week. Meanwhile you could try to have a plain-Java "persistence" module with all entities and DAOs. Make it a dependency to the library modules. We did this before and it worked.

karntrehan commented 7 years ago

Initially we were trying to refactor our existing app to a multimodule structure.. Yesterday I created a new project with just the DAO dependencies in the app_core library module and the files were generated in the library module itself. There must be a configuration mix-match in our existing app which we will now try to figure out. Nothing related to GreenDao. Thanks for your support.

greenrobot-team commented 7 years ago

@karantrehan Also try to update the greenDAO Gradle plugin to org.greenrobot:greendao-gradle-plugin:3.2.1 (from 3.1.1). It switched to an official Android Gradle Plugin API to better integrate into the build process. -ut