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.9k forks source link

DaoSession wrong namespace #896

Closed LuigiMaestrelli closed 5 years ago

LuigiMaestrelli commented 5 years ago

I've been using greenDao in the same project for months. Today I added a new entity. After that, the greenDao changed the DaoSession and DaoMaster's namespaces to the same namespace as the new entity added. And it broke all the project DaoSession's imports. Removing the @entity from the new class made the greenDao generating process go back to the same namespace as before.

All of that without changing any dependencies, I just changed the schemaVersion inside the build.gradle

This is my build.gradle

apply plugin: 'org.greenrobot.greendao'
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
    compileSdkVersion project.ext.compileSdkVersion
    buildToolsVersion project.ext.buildToolsVersion
    defaultConfig {
        applicationId "xxxxxxxxxxxxxxxxx"
        minSdkVersion project.ext.minSdkVersion
        targetSdkVersion project.ext.targetSdkVersion
        versionCode 37
        versionName "2.15"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        resConfigs "pt"
        signingConfig signingConfigs.config
    }
    dataBinding {
        enabled true
    }
    aaptOptions {
        cruncherEnabled false
    }
    buildTypes {
        debug {
            resValue "bool", "FIREBASE_CRASH_ENABLED", "false"
        }
        release {
            resValue "bool", "FIREBASE_CRASH_ENABLED", "true"
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

greendao {
    schemaVersion 6
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "com.android.support:appcompat-v7:$project.ext.androidSupportVersion"
    implementation "com.android.support:design:$project.ext.androidSupportVersion"
    implementation "com.android.support:support-v4:$project.ext.androidSupportVersion"
    implementation "com.android.support:recyclerview-v7:$project.ext.androidSupportVersion"
    implementation "com.android.support:cardview-v7:$project.ext.androidSupportVersion"
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    api 'org.greenrobot:greendao:3.2.2'
    api 'com.annimon:stream:1.2.1'
    implementation 'com.facebook.fresco:fresco:1.10.0'
    implementation 'com.facebook.fresco:animated-gif:1.10.0'
    implementation 'com.facebook.fresco:animated-webp:1.10.0'
    implementation 'com.facebook.fresco:webpsupport:1.10.0'
    implementation 'com.facebook.fresco:imagepipeline-okhttp3:1.10.0'
    api 'com.splitwise:tokenautocomplete:2.0.8@aar'
    api 'com.google.firebase:firebase-core:16.0.1'
    api 'com.google.firebase:firebase-messaging:17.3.0'
    api('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') {
        transitive = true
    }
    api 'com.github.bmelnychuk:atv:1.2.9'
    api 'com.github.sundeepk:compact-calendar-view:3.0.0'
}

apply plugin: 'com.google.gms.google-services'
LuigiMaestrelli commented 5 years ago

I use my class model structure like this:

model -- xxxx ------ xxxx.java ------ blablabla.java -- yyyy ------ test.java ------ ... -- ....

The DaoSession's namespace changed when I created a new package under model, and alphabetically, the new package is now the first package under model.

So, if I keep creating packages and by that, changing the first package on the list, the DaoSession will be changing namespaces every time?????

greenrobot-team commented 5 years ago

Yes, greenDAO automatically chooses a package based on where your entities are stored.

You can try to set the daoPackage property in the greendao closure:

greendao {
    schemaVersion 6
    daoPackage "com.example.model"
}

Though note that all generated classes will then be created in that package.

Closing. Please re-open if your question was not answered. -ut