Open ghost opened 8 years ago
As far as I know Kotlin is not supported. I assume your entity classes are written in Java? -ut
As far as I know Kotlin is not supported.
Kotlin works with most code-gen libs(Dagger 2, Realm) without any problems. Will be nice if your library will work with it too.
I assume your entity classes are written in Java?
Nope. It was written in Kotlin.
@Try4W Alright: the plugin only supports entities written in Java. So I suppose converting your entities to Java classes should make the plugin and generator work. -ut
Any concrete milestone to support it? Yes we can write Entity definitions by Java but Kotlin has been becoming the majority of Android development and its support make user's code more concise.
Writing Entity definitions in Java doesn't fix the problem. The code generated from the entity is not generated yet when compileDebugKotlin is executed.
Workaround for the issue: create a new module which is using greenDAO(without kotlin) and link it to the main module.
Does greendao have a plan to support kotlin?
@lishoulin greenDAO for now only supports entities written in Java. See @modislaszlox2 workaround to use it in a Kotlin project. -ut
Since Kotlin is official language now, it would be nice to have ability write models in Kotlin
Note: with your entity classes written in Java, to use the generated greenDAO files in your Kotlin classes you currently may have to manually add the generated source folder for Kotlin compilation to succeed:
android {
...
sourceSets {
main.java.srcDirs += 'build/generated/source/greendao'
}
}
This project is incredible. We really want it to work with Kotlin. Please make it true
Thank you!
With Google pushing Kotlin super hard I wouldn't be surprised if a sizable amount of work was moved to Kotlin. Please add support for Kotlin
Not supported yet I guess right? Is really converting the code to Java the easiest workaround? (a pitty...)
@rmr356 Yes. Indeed its not supported still.
Plz add a code gen plugin for kotlin. I wanna use this lib but i wont unless it supports kotlin. In my opinion, this is the only viable alternative to realm. I got bored of realm complexity. Threading, callbacks, no native rxjava support, and i find auto-updates useless and buggy. My project is 100% kotlin, i wanna avoid having to make a separate library project for java.
While I agree that it would be nice to have Kotlin support in GreenDao, nothing prevents you from having 99.9 % Kotlin project and just having the entity classes written in Java. This works for me (using kapt), without making a separate GreenDAO project/module.
I'm can't find DaoSession ,when in using greendao with dagger in kotlin.can you give me some advice
..... apply plugin: 'org.greenrobot.greendao' ... android {... sourceSets { main.java.srcDirs += 'build/generated/source/greendao' } } repositories { maven { url "https://oss.sonatype.org/content/repositories/snapshots" } mavenCentral() maven { url 'https://maven.fabric.io/public' } maven { url "https://jitpack.io" } } greendao { schemaVersion 1 } dependencies { testImplementation 'junit:junit:4.12' api "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" api "com.android.support:multidex:$rootProject.multidexVersion" api 'com.android.support.constraint:constraint-layout:1.0.2' .... // database compile "org.greenrobot:greendao:$rootProject.greenDaoVersion"
//Kotter Knife
api 'com.jakewharton:kotterknife:0.1.0-SNAPSHOT'
// dependency injection
implementation "com.google.dagger:dagger:${daggerVersion}"
kapt "com.google.dagger:dagger-compiler:${daggerVersion}"
compileOnly "org.glassfish:javax.annotation:${annotationVersion}"
....
}
Do you have your entity classes written in Java? Try commenting out all the uses of the DaoSession, then build the project and uncomment them.
@HarryHaiVn I'm having the same problem and it's preventing me to migrate the Dagger Graph to Kotlin, did you find any solution so far? there's no way the DaoSession can be found with Dagger in Kotlin, even having all GreeDAO entities in java.
try this order
apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'
apply plugin: 'kotlin-android'
works for me
@deviant-studio Thanks man! It worked like a charm!
Any updates on this? deviant-studio's solution didn't work for me.
afterEvaluate {
if (project.plugins.hasPlugin('org.greenrobot.greendao')) {
def taskGraph = project.getGradle().getTaskGraph()
taskGraph.whenReady {
Task greendaoPrepareTask = project.tasks.getByName("greendaoPrepare")
Task greendaoTask = project.tasks.getByName("greendao")
Task debugKotlin = project.tasks.getByName("kaptDebugKotlin")
Task releaseKotlin = project.tasks.getByName("kaptReleaseKotlin")
debugKotlin.doFirst {
greendaoPrepareTask.execute()
greendaoTask.execute()
}
releaseKotlin.doFirst {
greendaoPrepareTask.execute()
greendaoTask.execute()
}
}
}
}
I add this in my library project ,if you want to add this in your application module you can check the build type variants to start the greendao task
Any news on that? Do you guys plan to support Kotlin soon enough?
@deviant-studio Thanks man!
I am getting an error, can you please help me?
e: error: cannot access Database
class file for org.greenrobot.greendao.database.Database not found
Consult the following stack trace for details.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for org.greenrobot.greendao.database.Database not found
:app:kaptDebugKotlin FAILED
There likely will be no support for entities written in Kotlin.
-- Check out ObjectBox, our new fast, easy to use database!
ttgdz`s solution works perfect.
below is my workaround
1.comment kapt 2.make project. greendao generated 3.reopen kapt
@greenrobot @greenrobot-team I meet the same issue when i write the entity with java , but call Dao that haven't generated in kotlin class, report "compileDebugKotlin Unresolved reference: xxxDao" .For constrast, if i call the Dao in a java class, all going well. How can i fix that? thanks
my library module .gradle as below:
apply plugin: 'com.android.library' apply plugin: 'org.greenrobot.greendao' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions'
android { compileSdkVersion 30 buildToolsVersion "29.0.3"
defaultConfig {
minSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName "1.0"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
greendao { schemaVersion 1 //database version targetGenDir 'src/main/java' //specify the directory where the code is generated daoPackage 'com.coloros.testdir.greendao' //generate code to specific packages }
dependencies { implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "org.greenrobot:greendao:3.2.2"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.1'
}
build.gradle
gradlew greendao --info
output:Search in build\generated\source\ by keyword "greendao" do not find anything.