a-5-1-1.Realm DBのライブラリの選定と適用(Gradle)
目標設定
Github
テスト実装
build.gradle
buildscript {
repositories {
google()
}
dependencies {
def nav_version = "2.5.3"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
}
plugins {
id 'com.android.application' version '8.0.2' apply false
id 'com.android.library' version '8.0.2' apply false
id 'org.jetbrains.kotlin.android' version '1.9.22' apply false
id 'io.realm.kotlin' version '1.11.0' apply false // 追加
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app/build.gradle
plugins {
id "com.android.application"
id "org.jetbrains.kotlin.android"
id "androidx.navigation.safeargs"
id 'io.realm.kotlin'
}
android {
compileSdk 34
defaultConfig {
applicationId "com.example.androidtest"
minSdk 21
targetSdk 34
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
viewBinding {
enabled = true
}
namespace 'com.example.androidtest'
}
dependencies {
implementation "androidx.core:core-ktx:1.8.0"
implementation "androidx.appcompat:appcompat:1.4.2"
implementation "com.google.android.material:material:1.6.1"
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
implementation "androidx.recyclerview:recyclerview:1.2.1"
implementation "androidx.cardview:cardview:1.0.0"
def navigation_version = "1.0.0"
implementation "android.arch.navigation:navigation-fragment:$navigation_version"
implementation "android.arch.navigation:navigation-ui:$navigation_version"
implementation "android.arch.navigation:navigation-fragment-ktx:$navigation_version"
implementation "android.arch.navigation:navigation-ui-ktx:$navigation_version"
def retrofit_version = "2.9.0"
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
def realm_version = "1.11.0" // 追加
implementation "io.realm.kotlin:library-base:$realm_version" // 追加
implementation "io.realm.kotlin:library-sync:$realm_version" // 追加
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.0' // 追加
testImplementation "junit:junit:4.13.2"
androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0"
}