How to Setup a Room DB for Kotlin Multiplatform Compose

Поделиться
HTML-код
  • Опубликовано: 25 ноя 2024

Комментарии • 93

  • @Fo0nT
    @Fo0nT 6 месяцев назад +19

    There it is, nice! Next video suggestions:
    - Preparing for Kotlin 2.0
    - Compose Preview Screenshot testing

  • @gerardosanchez7548
    @gerardosanchez7548 6 месяцев назад +9

    No gonna lie, today i was decided to implement Rom in KMP with the documentation provided for google. And Philipp comes with this video, it is truly insane.
    Philipp you saved my day, tanks a lot!!!

    • @FreedivingTrainer
      @FreedivingTrainer 4 месяца назад +1

      I see Room docs and this video, prefer to stay with sqlDelight for multiplatform

  • @stasleonov5196
    @stasleonov5196 6 месяцев назад

    Philipp, I spent two days trying to do this, and here’s your video! Lord, give you everything you want and thank you so much

  • @peterpaniccc
    @peterpaniccc 6 месяцев назад

    Thank you Philipp, extremely helpful content. I'll stick to realm, but good to know room is now also supported.

  • @andreaslinis1586
    @andreaslinis1586 6 месяцев назад +9

    I used to have roomdb then wanted to migrate for kotlin multiplatform so changed to sqldelight. Now room is available for kotlin multi platform too. Too late 😂😂😂

    • @FreedivingTrainer
      @FreedivingTrainer 4 месяца назад +3

      I see Room docs and this video, prefer to stay with sqlDelight for multiplatform :)

    • @andreaslinis1586
      @andreaslinis1586 4 месяца назад +1

      @@FreedivingTrainer I think roomdb has better performance also one think I don't like about sqldelight is that all transaction content should be synchronous you can't use suspend functions. Also I don't like the too much code you have to write in sqldelight

  • @MaksimLA
    @MaksimLA 5 месяцев назад

    Great video, thanks! By the way, context exists on iOS as well. Core Data, which is the native persistence method in iOS, uses it too. However, for some reason, Kotlin databases on iOS, like Room or SQLDelight, don't seem to require it.

    • @PhilippLackner
      @PhilippLackner  5 месяцев назад

      Interesting, they're still two different contexts though 😄

  • @AravindhAthmanathan
    @AravindhAthmanathan 6 месяцев назад +6

    Hi Philipp, Can we use Room for Desktop also ?

    • @joeybasile545
      @joeybasile545 4 месяца назад

      Duh.

    • @ruhy99
      @ruhy99 3 месяца назад

      yes you can use it on desktop

  • @JeudryPeñaPeña
    @JeudryPeñaPeña 6 месяцев назад +1

    Ive foudn th best kotlin youtuber.

  • @vinupolly3558
    @vinupolly3558 6 месяцев назад +8

    For Kotlin 2.0.0, there seems to be an issue syncing 'Cannot change attributes of configuration ':composeApp:debugFrameworkIosX64' after it has been locked for mutation', have used the latest KSP so that IDE identifies generated sources, but still throwing this error. Any one had any luck with this?

    • @ZAKIALAM
      @ZAKIALAM 6 месяцев назад

      Philips this error is emerged from Kotlin 2.0.0 and KSP 2.0.0.
      Could you please help ?

    • @kocur-pl
      @kocur-pl 5 месяцев назад

      i have same error

    • @bardeebooboo
      @bardeebooboo 5 месяцев назад

      same...

    • @panagiotismargaritis3531
      @panagiotismargaritis3531 5 месяцев назад +6

      I had the same issue.
      Replace (for now) :
      dependencies {
      //room
      //Replace it with -> ksp(libs.room.compiler) when it is stable
      add("kspCommonMainMetadata", libs.room.compiler)
      }
      tasks.withType().configureEach {
      if (name != "kspCommonMainKotlinMetadata" ) {
      dependsOn("kspCommonMainKotlinMetadata")
      }
      }
      I think they will notice and they will come up with a change.

    • @mohitcharadva1655
      @mohitcharadva1655 5 месяцев назад

      @@panagiotismargaritis3531 For me it still not work, throws error -> error: Unresolved reference 'instantiateImpl'.

  • @mohammadhosein8378
    @mohammadhosein8378 6 месяцев назад +1

    please create a playlist for KMP videos on your channel for better access 🙏

  • @sakthir2617
    @sakthir2617 4 месяца назад +5

    Cannot change attributes of configuration ':composeApp:debugFrameworkIosX64' after it has been locked for mutation
    Guys anyone know how do solve this error

    • @Z17Developer
      @Z17Developer 3 месяца назад

      yes deps should look like this now:
      dependencies {
      // Room
      add("kspAndroid", libs.room.compiler)
      afterEvaluate {
      add("kspIosSimulatorArm64", libs.room.compiler)
      add("kspIosX64", libs.room.compiler)
      add("kspIosArm64", libs.room.compiler)
      }
      }

  • @tmjromao
    @tmjromao 6 месяцев назад +2

    Philipp many thanks for the video explanation. Could you explain how to implement dependency injection in this project? how to inject the room database in the viewmodel, shared amongst Android and iOS? thanks, best regards

    • @PhilippLackner
      @PhilippLackner  6 месяцев назад +1

      Check my recent video on how to share ViewModels and then connect these two :)

  • @sijanneupane
    @sijanneupane 6 месяцев назад +1

    damn Philipp!
    you're speeding up! ❤

  • @bolivarcortes426
    @bolivarcortes426 4 месяца назад

    Hi Phillip, You will know how to implement PagingSource, to a room dao function, if currently room for kmp only allows you to place the function as suspend or Flow

  • @MrBeskem
    @MrBeskem 5 месяцев назад

    Danke man, ich liebe deine Videos.

  • @HokiantoCandra
    @HokiantoCandra 5 месяцев назад +1

    Thank you for your extremely helpful content!
    I found an issue that the database is closed in app inspector, even if the app run and doing sql CRUD. I can't see my live database. Do you have any idea?

  • @RajeshJaswalPune
    @RajeshJaswalPune 6 месяцев назад +3

    error: Unresolved reference 'instantiateImpl'

    • @VikramKirubaharan
      @VikramKirubaharan 5 месяцев назад +1

      Same issue here. Did anyone found the root cause and resolved this issue?

    • @oleksiikolotylenko1004
      @oleksiikolotylenko1004 3 месяца назад

      @@VikramKirubaharan Pay attention on using instantiateImpl() - it is only for ios code

  • @HanifShaikh-w3e
    @HanifShaikh-w3e 3 месяца назад

    @philipp Do you have any idea how I can create a database instance with Koin?

  • @JOYTOY7
    @JOYTOY7 6 месяцев назад

    Could you make Playlist for KMP?

  • @mfatihy70
    @mfatihy70 6 месяцев назад

    damn i feel like u read my mind, thats what i was looking for :)

  • @ALEX54402
    @ALEX54402 6 месяцев назад +1

    🎉🎉🎉 keep going

  • @PhilippeNajem
    @PhilippeNajem 5 месяцев назад +3

    On a physical iOS device (iPhone), I encountered an error when using NSHomeDirectory in the databaseBuilder: Error Domain=KotlinException Code=0 "Unable to open lock file (Operation not permitted)". However, this issue did not occur on the simulator, where it worked fine. To resolve this, I replaced:
    val dbFile = NSHomeDirectory() + "/myDatabase.db"
    with
    val docDirectoryUrl = NSFileManager.defaultManager().URLForDirectory(NSDocumentDirectory, NSUserDomainMask, null, true, null)
    val dbFile = docDirectoryUrl?.path + "/myDatabase.db"
    and it worked fine. Does anyone have other suggestions? Thanks.

    • @JeeMorpheus
      @JeeMorpheus 5 месяцев назад +1

      this helped me as well

    • @Bluckyism
      @Bluckyism 3 месяца назад

      You saved my life! Thank you........

    • @hossamzaabl5275
      @hossamzaabl5275 3 месяца назад

      You also saved my life and my a**, super thank you man

  • @andreaslinis1586
    @andreaslinis1586 6 месяцев назад +1

    Philip is it safe to use compose multiplatform for production in this point or is it a bit risky with alpha version? (Jetbrains focus to release beta this year)

  • @betterboyfilms
    @betterboyfilms 6 месяцев назад

    Hi, whats your theme in Android Studio?

  • @MahmoudBashir-dd4or
    @MahmoudBashir-dd4or 6 месяцев назад

    Could you please integrating it with koin in kmm

  • @Nick-cx4rs
    @Nick-cx4rs 3 месяца назад

    Guys when cmp will usable and common you think ?

  • @khanhNguyen-ts6gj
    @khanhNguyen-ts6gj 6 месяцев назад

    How can you have code suggestion on kotlin files of iosMain package? Mine Android studio only treated like a plain text files :(

  • @FreedivingTrainer
    @FreedivingTrainer 4 месяца назад

    I see Room docs and this video, prefer to stay with sqlDelight for multiplatform ;)

  • @AlexisJimenez-wy4zu
    @AlexisJimenez-wy4zu Месяц назад

    I am facing some troubles because iOS requires ConstructedBy tag.

  • @bakjoul
    @bakjoul 2 месяца назад

    Is it not compatible with wasm ?

  • @CybercoderNaj
    @CybercoderNaj 5 месяцев назад

    Hey Philipp, great video! However, I noticed that you did all of your code in :composeApp. Why did you take this approach and not in the :shared module? I was under the impression that :shared is used for business logic...

    • @deriarmanda7807
      @deriarmanda7807 5 месяцев назад +1

      composeApp is a shared module. Right now, they shipped android and kmm together into one module named composeApp by default if you create project from kmp wizard.

    • @CybercoderNaj
      @CybercoderNaj 5 месяцев назад

      @@deriarmanda7807 Yeah that was quite confusing for me. Now I use `shared/` module for stuff that is shared between the app the server like serializing request/response bodies and type-safe routing.

  • @JeudryPeñaPeña
    @JeudryPeñaPeña 6 месяцев назад

    How to add dao on wasm and desktop app

  • @husordavid5405
    @husordavid5405 4 месяца назад

    how about migrate ?

  • @MrMarv37
    @MrMarv37 6 месяцев назад

    Would this be the same way to implement room in an intellij desktop project?

    • @LassNoches
      @LassNoches 6 месяцев назад

      I want to know this too

    • @PhilippLackner
      @PhilippLackner  6 месяцев назад +1

      Yes for Desktop it works as well

    • @MrMarv37
      @MrMarv37 6 месяцев назад

      ​@@PhilippLacknerthank you. And how do you create an instance of a room db in an intellij desktop only project?

  • @Nick-cx4rs
    @Nick-cx4rs 3 месяца назад

    Anyone got room doesnt work on release setup on desktop with .msi .. ??
    Working on android studio

  • @abada-s
    @abada-s 6 месяцев назад

    I hope to create a video about migrate from android project to kmp project

    • @PhilippLackner
      @PhilippLackner  6 месяцев назад +1

      Already done

    • @abada-s
      @abada-s 6 месяцев назад

      @@PhilippLackner I don't think that I missed a video for you, I mean if there is an existing android project, how to migrate its settings and configurations to be a kmp one

  • @VikramKirubaharan
    @VikramKirubaharan 5 месяцев назад

    Hii Philipp.. KSP has generate source code but instantiateImpl() is not resolved in iOS SourceSet. But it is resolved in Android SourceSet. I couldn't figure out the root cause. I have checked generated build folder. I found the method in both iOS & Android generated files but am not getting why it is not resolved in iOS source set resulting in build failure. Please help us to resolve this.

    • @PhilippLackner
      @PhilippLackner  5 месяцев назад

      Just launch the app, it'll work :)

    • @vikramkirubaharan7737
      @vikramkirubaharan7737 5 месяцев назад

      @@PhilippLackner Thanks for responding. And thanks a lot for your contribution towards Android Community..

  • @MrMindfullness
    @MrMindfullness 6 месяцев назад

    If some one from subscriber knows how to login to account on pl-coding, please reply. I am not able to see a way to login on pl-coding. I want to access course that I enrolled for.

  • @MrMindfullness
    @MrMindfullness 6 месяцев назад

    How to login to my account on pl-coding website?

    • @PhilippLackner
      @PhilippLackner  6 месяцев назад

      After the purchase you got an email with instructions to set a password on Memberspot. Then you just need to log in there with the link in the email :)

    • @MrMindfullness
      @MrMindfullness 6 месяцев назад

      @@PhilippLackner Thanks for reply! I was searching in emails by your name. Now I got it.

  • @ErnestoVega
    @ErnestoVega 4 месяца назад

    Struggling to use it with Koin

  • @arozendojr
    @arozendojr 6 месяцев назад

    I would like to see compose-ios, using a simple Android and ios webview

    • @PhilippLackner
      @PhilippLackner  6 месяцев назад +1

      Already have a 3h course here on RUclips :)

  • @Elkmor2
    @Elkmor2 5 месяцев назад

    If you want to show off multiplatform, it is a bad idea to do so on Android. We already know it works in Android, there is no point

  • @johnkenedy
    @johnkenedy 6 месяцев назад

  • @frank4pickerson
    @frank4pickerson 6 месяцев назад +1

    Why not use mongodb?

    • @fernandobsep
      @fernandobsep 6 месяцев назад

      Coisa de mongol

    • @alexbecar977
      @alexbecar977 6 месяцев назад +1

      Because its trash for most use cases

    • @FreedivingTrainer
      @FreedivingTrainer 4 месяца назад +1

      It was my mistake to implement realm years ago

  • @simonsloooow
    @simonsloooow 2 месяца назад

    For now, there are a new way to define ksp dependency(also recommended by Jetbrains)
    ```Kotlin
    dependencies {
    add("kspAndroid", libs.utils.db.room.compiler)
    add("kspIosSimulatorArm64", libs.utils.db.room.compiler)
    add("kspIosX64", libs.utils.db.room.compiler)
    add("kspIosArm64", libs.utils.db.room.compiler)
    add("kspJvm", libs.utils.db.room.compiler)
    }
    ```

    • @maciejnowak2120
      @maciejnowak2120 2 месяца назад

      Hi, do you have example project with these new upadtes? I cant manage how to set up this all ://

    • @JaroslavFilip
      @JaroslavFilip 2 месяца назад

      ​@@maciejnowak2120
      *** In build.gradle.kts replace:
      dependencies {
      ksp(libs.room.compiler)
      }
      by
      dependencies {
      add("kspAndroid", libs.room.compiler)
      add("kspIosSimulatorArm64", libs.room.compiler)
      add("kspIosX64", libs.room.compiler)
      add("kspIosArm64", libs.room.compiler)
      }
      *** In PeopleDatabase.kt replace:
      @Database(
      entities = [Person::class],
      version = 1
      )
      abstract class PeopleDatabase: RoomDatabase() {
      abstract fun peopleDao(): PeopleDao
      }
      by
      @ConstructedBy(PeopleDatabaseConstructor::class)
      @Database(
      entities = [Person::class],
      version = 1
      )
      abstract class PeopleDatabase: RoomDatabase() {
      abstract fun peopleDao(): PeopleDao
      }
      // The Room compiler generates the `actual` implementations.
      @Suppress("NO_ACTUAL_FOR_EXPECT")
      expect object PeopleDatabaseConstructor : RoomDatabaseConstructor {
      override fun initialize(): PeopleDatabase
      }
      *** In getPeopleDatabaseImpl.kt in isoMaon package comment out this line:
      factory = { PeopleDatabase::class.instantiateImpl() }