2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Android] Roomを使ってローカルDatabaseにデータを保存してみた

Last updated at Posted at 2022-05-16

背景

データ永続化するニーズが出てきたので、ローカルDBにデータを保存して、サーバーと常に同期するようにした

技術背景

  • Kotlin: 1.6.20
  • KSP: 1.6.20-1.0.5
  • Android Studio: BumbleBee

Roomとは

Room 永続ライブラリは SQLite 全体に抽象化レイヤを提供することで、データベースへのより安定したアクセスを可能にし、SQLite を最大限に活用できるようにします。

Room  |  Android デベロッパー  |  Android Developers

Setup Room

buildscript {
    ext {
        // sdk and tools
        compileSdkVersion = 31
        minSdkVersion = 25
        targetSdkVersion = 31

        // app dependencies
        kotlinVersion = '1.6.20'
        roomVersion = '2.4.2'
    }
  • settings.gradle
pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
    }
    plugins {
        id("com.google.devtools.ksp") version "1.6.20-1.0.5"
    }
}

kspのバージョンはこちらを参照しました:Maven Repository: com.google.devtools.ksp
settings.gradleにpluginManagementを書いた理由はこちら:gradle pluginManagement {} ブロックとは

  • app/build.gradle
plugins {
    id 'com.google.devtools.ksp'
}

implementation("androidx.room:room-runtime:$rootProject.roomVersion")
annotationProcessor("androidx.room:room-compiler:$rootProject.roomVersion")
ksp("androidx.room:room-compiler:$rootProject.roomVersion")

テーブル作成

To be continued...

エラー

Plugin [id: 'com.google.devtools.ksp'] was not found in any of the following sources:

↑のsettings.gradleにpluginManagementを設定すれば解決するはずです。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?