Github url


by realm

realm /realm-java

Realm is a mobile database: a replacement for SQLite & ORMs

11.0K Stars 1.7K Forks Last release: Not found Other 8.3K Commits 181 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:


bintray License

Realm is a mobile database that runs directly inside phones, tablets or wearables. This repository holds the source code for the Java version of Realm, which currently runs only on Android.


  • Mobile-first: Realm is the first database built from the ground up to run directly inside phones, tablets, and wearables.
  • Simple: Data is directly exposed as objects and queryable by code, removing the need for ORM's riddled with performance & maintenance issues. Plus, we've worked hard to keep our API down to very few classes: most of our users pick it up intuitively, getting simple apps up & running in minutes.
  • Modern: Realm supports easy thread-safety, relationships & encryption.
  • Fast: Realm is faster than even raw SQLite on common operations while maintaining an extremely rich feature set.

Getting Started

Please see the detailed instructions in our docs to add Realm to your project.


Documentation for Realm can be found at The API reference is located at

Getting Help

  • Got a question?: Look for previous questions on the #realm tag — or ask a new question. We actively monitor & answer questions on StackOverflow! You can also check out our Community Forum where general questions about how to do something can be discussed.
  • Think you found a bug? Open an issue. If possible, include the version of Realm, a full log, the Realm file, and a project that shows the issue.
  • Have a feature request? Open an issue. Tell us what the feature should do, and why you want the feature.

Using Snapshots

If you want to test recent bugfixes or features that have not been packaged in an official release yet, you can use a -SNAPSHOT release of the current development version of Realm via Gradle, available on JFrog OSS

buildscript { repositories { jcenter() google() maven { url '' } } dependencies { classpath "io.realm:realm-gradle-plugin:<version>-SNAPSHOT"

allprojects {
    repositories {
        maven {
            url ''

See version.txt for the latest version number.

Building Realm

In case you don't want to use the precompiled version, you can build Realm yourself from source.


  • Download the JDK 8 from Oracle and install it.
  • The latest stable version of Android Studio. Currently 3.6.2.
  • Download & install the Android SDK Build-Tools 28.0.3, Android Pie (API 28) (for example through Android Studio’s Android SDK Manager).
  • Install CMake from SDK manager in Android Studio ("SDK Tools" -> "CMake").

Install the NDK (currently r21) from the SDK Manager in Android Studio or using the website. If downloaded You may unzip the file wherever you choose. For macOS, a suggested location is


. The download will unzip as the directory



If you will be building with Android Studio, you will need to tell it to use the correct NDK. If you installed it using the SDK Manager, it will automatically be detected. Otherwise, you need to define the variable




and assign it the full pathname of the directory that you unzipped above. Note that there is a


in the root directory that is not the one that needs to be edited.


  • Add two environment variables to your profile (presuming you installed the NDK using the SDK Manager):

export ANDROID\_HOME=~/Library/android-sdk export ANDROID\_NDK\_HOME=~/Library/android-sdk/ndk/21.0.6113669
  • If you are launching Android Studio from the macOS Finder, you should also run the following two commands:

launchctl setenv ANDROID\_HOME "$ANDROID\_HOME" launchctl setenv ANDROID\_NDK\_HOME "$ANDROID\_NDK\_HOME"
  • If you'd like to specify the location in which to store the archives of Realm Core, define the


environment variable. It enables you to keep Core's archive when executing

git clean -xfd


export REALM\_CORE\_DOWNLOAD\_DIR=~/.realmCore

macOS users must also run the following command for Android Studio to see this environment variable.


It would be a good idea to add all of the symbol definitions (and their accompanying


commands, if you are using macOS) to your




if the login shell is



If you develop Realm Java with Android Studio, we recommend you to exclude some directories from indexing target by executing following steps on Android Studio. It really speeds up indexing phase after the build.

  • Under
    , select
    folders in
  • Press
    Command + Shift + A
    to open
    Find action
    dialog. If you are not using default keymap nor using macOS, you can find your shortcut key in
    preference by searching
    Find action
  • Search
    ) action and select it. Selected folder icons should become orange (in default theme).
  • Restart Android Studio.

Download sources

You can download the source code of Realm Java by using git. Since realm-java has git submodules, use


when cloning the repository.

git clone [email protected]:realm/realm-java.git --recursive


git clone --recursive


Once you have completed all the pre-requisites building Realm is done with a simple command.

./gradlew assemble

That command will generate:

  • a jar file for the Realm Gradle plugin
  • an aar file for the Realm library
  • a jar file for the annotations
  • a jar file for the annotations processor

The full build may take an hour or more, to complete.

Building from source

It is possible to build Realm Java against a local checked out version of Realm Core. This is done by providing the following parameter when building:



E.g in the case where the




repos are checked out next to each other you can build from source using:

git clone git clone cd realm-java/realm ./gradlew assembleBase -PcoreSourcePath=../../realm-core

Note: If the


project has already been compiled for non-Android builds and CMake files have been generated, this might conflict with


trying to build it. Cleanup the


project by calling

git clean -xfd

inside it (beware that all unsaved changes will be lost).

Note: Building from source with Realm Sync is not enabled yet. Only building the


variant is supported.

Note: If you want to build from source inside Android Studio, you need to update the Gradle parameters by going into the Realm projects settings

Settings \> Build, Execution, Deployment \> Compiler \> Command-line options

and add


to it.

Other Commands

  • ./gradlew tasks
    will show all the available tasks
  • ./gradlew javadoc
    will generate the Javadocs
  • ./gradlew monkeyExamples
    will run the monkey tests on all the examples
  • ./gradlew installRealmJava
    will install the Realm library and plugin to mavenLocal()
  • ./gradlew clean -PdontCleanJniFiles
    will remove all generated files except for JNI related files. This reduces recompilation time a lot.
  • ./gradlew connectedUnitTests -PbuildTargetABIs=$(adb shell getprop ro.product.cpu.abi)
    will build JNI files only for the ABI which corresponds to the connected device. These tests require a running Object Server (see below)

Generating the Javadoc using the command above may generate warnings. The Javadoc is generated despite the warnings.

Upgrading Gradle Wrappers

All gradle projects in this repository have


task to generate Gradle Wrappers. Those tasks refer to


property defined in


to determine Gradle Version of generating wrappers. We have a script


to automate these steps. When you update Gradle Wrappers, please obey the following steps.

  1. Edit
    property in defined in
    to new Gradle Wrapper version.
  2. Execute


The repository is organized into six Gradle projects:

  • realm
    : it contains the actual library (including the JNI layer) and the annotations processor.
  • realm-annotations
    : it contains the annotations defined by Realm.
  • realm-transformer
    : it contains the bytecode transformer.
  • gradle-plugin
    : it contains the Gradle plugin.
  • examples
    : it contains the example projects. This project directly depends on
    which adds a dependency to the artifacts produced by
  • The root folder is another Gradle project. All it does is orchestrate the other jobs.

This means that

./gradlew clean


./gradlew cleanExamples

will fail if


has not been executed first. Note that IntelliJ does not support multiple projects in the same windowso each of the six Gradle projects must be imported as a separate IntelliJ project.

Since the repository contains several completely independent Gradle projects, several independent builds are run to assemble it. Seeing a line like:

:realm:realm-library:compileBaseDebugAndroidTestSources UP-TO-DATE

in the build log does not imply that you can run

./gradlew :realm:realm-library:compileBaseDebugAndroidTestSources





folder contains many example projects showing how Realm can be used. If this is the first time you checkout or pull a new version of this repository to try the examples, you must call

./gradlew installRealmJava

from the top-level directory first. Otherwise, the examples will not compile as they depend on all Realm artifacts being installed in



Standalone examples can be downloaded from website.

Running Tests on a Device

To run these tests, you must have a device connected to the build computer, and the


command must be in your

  1. Connect an Android device and verify that the command

adb devices

shows a connected device:

adb devices List of devices attached 004c03eb5615429f device
  1. Run instrumentation tests:

cd realm ./gradlew connectedBaseDebugAndroidTest

These tests may take as much as half an hour to complete.

Running Tests Using The Realm Object Server

Tests in


require a running testing server to work. A docker image can be built from


to run the test server.


will build the docker image automatically.

To run a testing server locally:

  1. Install docker and run it.




cd tools/sync\_test\_server ./start\

This command will not complete until the server has stopped.

  1. Run instrumentation tests

In a new terminal window, run:

cd realm ./gradlew connectedObjectServerDebugAndroidTest

Note that if using VirtualBox (Genymotion), the network needs to be bridged for the tests to work. This is done in

VirtualBox \> Network

. Set "Adapter 2" to "Bridged Adapter".

These tests may take as much as half an hour to complete.


See for more details!

This project adheres to the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to [email protected].

The directory


contains lint and style files recommended for project code. Import them from Android Studio with Android Studio > Preferences... > Code Style > Manage... > Import, or Android Studio > Preferences... > Inspections > Manage... > Import. Once imported select the style/lint in the drop-down to the left of the Manage... button.


Realm Java is published under the Apache 2.0 license.

Realm Core is also published under the Apache 2.0 license and is availablehere.

This product is not being made available to any person located in Cuba, Iran, North Korea, Sudan, Syria or the Crimea region, or to any other person that is not eligible to receive the product under U.S. law.


If you use Realm and are happy with it, all we ask is that you, please consider sending out a tweet mentioning @realm to share your thoughts!

And if you don't like it, please let us know what you would like improved, so we can fix it!


We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.