Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unresolved reference: DaoSession using greendao and kotlin

I am trying to convert a android project written in java to kotlin. My greendao class have been generated by anytime i build i get a Unresolved reference: DaoSession error message. I have
kapt { generateStubs = true } in my build gradle code.

like image 853
Bubunyo Nyavor Avatar asked Nov 29 '22 22:11

Bubunyo Nyavor


2 Answers

Move your greendao plugin before the kotlin plugin in your app build.gradle like below:

apply plugin: 'org.greenrobot.greendao'

apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android'
like image 195
0xAliHn Avatar answered Dec 03 '22 23:12

0xAliHn


This is caused by that Greendao generate DaoSession and other Dao files at a default path:"app/build/generated/source/greendao/", which cannot be found by kotlin.

So you just need to change the Dao path by adding this code to your module Gradle file:

greendao {
    targetGenDir 'src/main/java' 
}

Then, you can find the Dao files like DaoSesson.java are generated in your project path 'src/main/java'. Now Kotlin can find the DaoSession.

Hope can help.

Reference: https://github.com/greenrobot/greenDAO/issues/352

like image 20
CalvinChe Avatar answered Dec 04 '22 00:12

CalvinChe