agrosner / DBFlow

A blazing fast, powerful, and very simple ORM android database library that writes database code for you.
MIT License
4.88k stars 599 forks source link

GeneratedDatabaseHolder is re-created on second run in AS loosing database exceution #694

Closed AAverin closed 8 years ago

AAverin commented 8 years ago

After ./gradlew clean and building the project I see a GeneratedDatabaseHolder class that creates my database. First run of the project everything is working correctly, but after re-compilation without clean GeneratedDatabaseHolder class is regenerated, and line that would create a database is no longer there, that breaks the project.

We are using Kotlin + Dagger2 + Databinding, so lots of code-generation stuff

AAverin commented 8 years ago

Tried https://github.com/Raizlabs/DBFlow/blob/5c4e51090d0b7ccf556d02261d8460e0417d596e/usage/DatabaseModules.md

in hope that this was a bug because we have 2 modules in the app - ui and data, and only data module (android library) uses DBFlow.

But no luck, class is not regenerated, but app still breaks on second launch with an error that table is not connected to database

Caused by: com.raizlabs.android.dbflow.structure.InvalidDBConfiguration: Table: ...data.statistics.model.StatisticArticleModel is not registered with a Database. Did you forget the @Table annotation?

AAverin commented 8 years ago

Sorry for confusion, class is still regenerated loosing database invocation even with DatabaseModules applied

AAverin commented 8 years ago

Could this be some Google AutoService issue with Kapt?

agrosner commented 8 years ago

What version of the gradle plugin are you using, which classes are used in kotlin and which are in Java?

AAverin commented 8 years ago

Issue is present on both 1.5.1 and 2.0.0-beta6 All classes are in Kotlin

agrosner commented 8 years ago

you cant write dbflow @Table classes in Kotlin. There is some unexplained issue with KAPT.

AAverin commented 8 years ago

Do you have any detailed information about this unexplained kapt issue? Maybe we could followup with some help from IntelliJ guys on this topic.

If not, what would be a proper solution then? We can't write dbflow classes in Java because we already use kapt for everything else and compiler complains if you try to use both apt plugin and kapt at the same time. Is there any way to use dbflow without annotations, for example?

agrosner commented 8 years ago

you can still use KAPT, you just cant write DBFlow classes in Kotlin. Also you need to ensure stubs are enabled

AAverin commented 8 years ago

Stubs are enabled, we are also using Databinding and Dagger2, so we need them.

Thanks, let me try converting classes to Java to check

AAverin commented 8 years ago

Thanks, looks like the issue is resolved when writing databases and tables in Java classes. This is probably better to mention on the main page of dbflow+kotlin.

Also, I noticed that kotlinextensions are missing from the repo, at least my gradle was complaining about that and I had to remove them

agrosner commented 8 years ago

yeah, both times I tagged the repo without pushing it. I will fix this in next beta. For now you can use the develop-SNAPSHOT of the dbflow-kotlinextensions project (it won't change that much unless more features requested in future). And next beta should include it as an artifact.