Skip to main content

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
The Kotlin SDK does not support x86 devices. Since x86 devices are the default option in Android Studio, you must create an x86_64 or arm64 device in AVD Manager to run applications that use the SDK. You can find images for compatible devices in AVD Manager. Follow these steps to create and use a compatible device:
  1. Open AVD Manager in Android Studio by selecting Tools > AVD Manager.

  2. Click the Create Virtual Device button.

  3. Select a phone, such as Nexus 5.

  4. Click the Next button.

  5. Navigate to the x86 Images tab.

  6. Click the Download link next to an x86_64 device image, such as S / x86_64 / Android API S (Google Play).

  7. Click the Finish button to close the dialogue when the image finishes downloading.

  8. Click the Next button.

  9. Name your device and click the Finish button to add it to your list of virtual devices.

  10. 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​

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-base to the list of dependencies.
  • Add io.realm.kotlin to the list of plugins.
  • To use coroutines with the SDK, add org.jetbrains.kotlinx:kotlinx-coroutines-core to 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'
}

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.