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 a constant to define a column name does not work #355

Closed TBoehm closed 8 years ago

TBoehm commented 8 years ago

If I try to execute the gradle plugin in my project

:app:greendaoPrepare UP-TO-DATE :app:greendao FAILED I get the error Error:Execution failed for task ':app:greendao'. Can't get String value from class org.eclipse.jdt.core.dom.SimpleName

How do I fix that?

My gradle file looks like this:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
        maven { url "https://jitpack.io" }
        mavenCentral()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'io.fabric.tools:gradle:1.+'
        classpath 'org.greenrobot:greendao-gradle-plugin:3.0.0'

    }
}

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

android {
    compileSdkVersion 24
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "de.toboehm.expensetracker"
        minSdkVersion 19
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    maven { url "https://jitpack.io" }
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'

    // Google support
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.android.support:design:24.0.0'
    compile 'com.android.support:support-annotations:24.0.0'

    compile 'com.google.android.gms:play-services-location:9.2.0'

    // 3rd party
    compile 'org.greenrobot:greendao:3.0.1'

    compile 'com.github.PhilJay:MPAndroidChart:v3.0.0-beta1'

    compile 'com.jakewharton:butterknife:8.1.0'
    apt 'com.jakewharton:butterknife-compiler:8.1.0'

    compile 'joda-time:joda-time:2.9.4'

    compile 'com.squareup.retrofit2:retrofit:2.1.0'

    compile('com.crashlytics.sdk.android:crashlytics:2.6.0@aar') {
        transitive = true;
    }

    compile('com.mapbox.mapboxsdk:mapbox-android-sdk:4.1.0@aar') {
        transitive = true;
    }

    compile 'com.github.BlacKCaT27:CurrencyEditText:v1.4.4'
}
TBoehm commented 8 years ago

I found the problem: If you do anything wrong while annotating a class (greenDAO 3), for example using a static String for setting a specific field name via @Property (btw. why is that wrong?! - what is the right way to do it?), the greendao plugin fails at generating the corresponding DAO which leads to the failure mentioned above.

greenrobot-team commented 8 years ago

You are right, looks like using a constant to define a custom column name is currently not supported. So you should do something like:

    @Property(nameInDb = "SUPERMAN_COLUMN")
    private String lastname;

-ut

greenrobot commented 8 years ago

Please check using version 3.1.1, which is currently on its way to Maven central. Let us know if it works for you.

TBoehm commented 8 years ago

Hey @greenrobot, thanks for looking at that feature/implementing it. However, atm I'm not using greendao in any project but I will try it out in the next one.

kkworden commented 6 years ago

Still is not working for me on GreenDAO 3.2.2

TBG-FR commented 4 years ago

As of today (version 3.2.2), it only works if constants are defined in the same file (class) as the Entity