Install (Android)
Prerequisites​
- Android Studio version 4.2.2 or higher.
- JDK 11 or higher
- Kotlin Plugin for Android Studio, version 1.5.20 or higher.
- Kotlin Multiplatform Mobile (KMM) Plugin for Android Studio, version 0.2.6 or higher.
- A KMM App created using the "KMM Application" template in Android Studio. Follow the instructions in the KMM documentation.
- An Android Virtual Device (AVD) using a compatible architecture (x86_64 or arm64).
x86 Devices are not Compatible with the Kotlin SDK
Open AVD Manager in Android Studio by selecting
Tools>AVD Manager.Click the
Create Virtual Devicebutton.Select a phone, such as
Nexus 5.Click the
Nextbutton.Navigate to the
x86 Imagestab.Click the
Downloadlink next to an x86_64 device image, such asS / x86_64 / Android API S (Google Play).Click the
Finishbutton to close the dialogue when the image finishes downloading.Click the
Nextbutton.Name your device and click the
Finishbutton to add it to your list of virtual devices.At the top of your Android Studio window, select your compatible device in the AVD dropdown.
You can track x86 support in this GitHub issue.
Installation​
- Realm Database
- Sync
To add local-only Realm Database to your application, make the
following changes to your app-level Gradle build file, typically found
at <project>/app/build.gradle:
- Add
io.realm.kotlin:library-baseto the list of dependencies. - Add
io.realm.kotlinto the list of plugins. - To use coroutines with the SDK, add
org.jetbrains.kotlinx:kotlinx-coroutines-coreto the list of dependencies.
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'io.realm.kotlin' version "0.10.0"
}
android {
compileSdk 31
defaultConfig {
applicationId "com.mongodb.realm.testkmmandroidonly"
minSdk 28
targetSdk 31
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_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0-native-mt'
implementation 'io.realm.kotlin:library-base:0.10.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
To add Realm Database and Sync to your application, make the following changes to your app-level Gradle build file, typically found at <project>/app/build.gradle:
- Add
io.realm.kotlin:library-syncto the list of dependencies. - Add
io.realm.kotlinto the list of plugins. - To use coroutines with the SDK, add
org.jetbrains.kotlinx:kotlinx-coroutines-coreto the list of dependencies.
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'io.realm.kotlin' version "0.10.0"
}
android {
compileSdk 31
defaultConfig {
applicationId "com.mongodb.realm.testkmmandroidonly"
minSdk 28
targetSdk 31
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_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0-native-mt'
implementation 'io.realm.kotlin:library-sync:0.10.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
After updating the Gradle configuration, resolve the dependencies by clicking File > Sync Project with Gradle Files in the Android Studio menu bar. You can now use the Kotlin SDK in your application.