Hello hello. I trying to use room as a database fo...
# compose-ios
l
Hello hello. I trying to use room as a database for the iOS version of my compose app. The code is inside the
commonMain
folders of my modules and it works just fine with the android app... but when I try to build the iOS app, if throws this error:
Copy code
> Task :application:core:persistence_room:kspKotlinIosSimulatorArm64 FAILED
note: [ksp] loaded provider(s): [androidx.room.RoomKspProcessor$Provider]
error: [ksp] Entities and POJOs must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).
Tried the following constructors but they failed to match:
<init> -> [param:id -> matched field:unmatched, param:title -> matched field:unmatched, [i'm hidding the parameters here] - [hidden].document.DocumentEntity
error: [ksp] Entities and POJOs must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type). -
Does anyone had this problem already? How did you solve it?
c
Hi Leandro, I had the same thing yesterday. Idk about your project structure, but I have something like this:
Copy code
:shared
---- :database
-------- AppDatabase
-------- Dao1
-------- Dao2
-------- etc...

:feature
---- :database
-------- FeatureDao
---- :model
-------- FeatureModel
In the initial setup of the db I put everything under
:shared:database
, but I decided to move things into their own feature module (also daos and db models). So now I just add
projects.feature.database
as a dependency in the
projects.shared.database
module to keep things separated. Like you said on android everything works well, but when I try to run the iOS app I get the same error. After many attempts I resolved this by duplicating
FeatureDao
and
FeatureModel
inside
projects.shared.database
module and use those in my `AppDatabase`class instead of the one in
projects.feature.database
. I don’t like this setup because everything is mixed up and it slows down the builds when I want to change something of Feature1 which is unrelated to Feature2. I’ll let you know if I find a proper solution, but for now you may want to put in one module the daos, models and the database class.
l
That would be hard for me... the app has some many modules already and each has its own responsibility, I can't move the DAOs to the shared module because many other modules dependends on the persistence one
I created an abstraction on top of the databases for switching from SQL Delight to Room and visa versa is easy in this project. My solution so far is to use SQL delight 😓
Which is not a bad library, btw
quite good
c
That sucks indeed... Tonight I'll create a sample project to confirm that what I described is the actual issue. If I can confirm I will create a ticket on androidx-room, otherwise I guess we are both doing something wrong. I'll update the thread when I have news.
Regarding SQL delight yes I tried it a couple of years ago, but I can't use it on the project 😭
l
Hahaha, but room should solve the problem. Hey, thanks for the help!
c
No worries! Here is the issue