• Stars
    star
    11,451
  • Rank 2,893 (Top 0.06 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 12 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Realm is a mobile database: a replacement for SQLite & ORMs
realm by MongoDB

Maven Central 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.

Realm Kotlin

The Realm Kotlin SDK is now GA and can be used for both Android and Kotlin Multiplatform. While we are still adding features, please consider using Realm Kotlin for any new project, and let us know if you miss anything there!

Features

  • 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.
  • Device Sync: Makes it simple to keep data in sync across users, devices, and your backend in real-time. Get started for free with a template application and create the cloud backend.

Getting Started

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

Documentation

Documentation for Realm can be found at mongodb.com/docs/atlas/device-sdks/sdk/java/. The API reference is located at mongodb.com/docs/atlas/device-sdks/sdk/java/api/.

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 Sonatype OSS

buildscript {
    repositories {
        mavenCentral()
        google()
        maven {
            url 'https://oss.sonatype.org/content/repositories/snapshots/'
        }
        jcenter()
    }
    dependencies {
        classpath "io.realm:realm-gradle-plugin:<version>-SNAPSHOT"
    }
}

allprojects {
    repositories {
        mavenCentral()
        google()
        maven {
            url 'https://oss.sonatype.org/content/repositories/snapshots/'
        }
        jcenter()
    }
}

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.

Prerequisites

  • Download the JDK 8 from Oracle and install it.

  • The latest stable version of Android Studio. Currently 4.1.1.

  • Download & install the Android SDK Build-Tools 29.0.3, Android Pie (API 29) (for example through Android Studio’s Android SDK Manager).

  • Install CMake version 3.18.4 and build Ninja.

  • Install the NDK (Side-by-side) 21.0.6113669 from the SDK Manager in Android Studio. Remember to check β˜‘ Show package details in the manager to display all available versions.

  • Add the Android home environment variable to your profile:

    export ANDROID_HOME=~/Library/Android/sdk
    
  • If you are launching Android Studio from the macOS Finder, you should also run the following command:

    launchctl setenv ANDROID_HOME "$ANDROID_HOME"
    
  • If you'd like to specify the location in which to store the archives of Realm Core, define the REALM_CORE_DOWNLOAD_DIR environment variable. It enables caching core release artifacts.

    export REALM_CORE_DOWNLOAD_DIR=~/.realmCore
    

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

    launchctl setenv REALM_CORE_DOWNLOAD_DIR "$REALM_CORE_DOWNLOAD_DIR"
    

It would be a good idea to add all of the symbol definitions (and their accompanying launchctl commands, if you are using macOS) to your ~/.profile (or ~/.zprofile if the login shell is zsh)

  • 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 /realm/realm-library/, select build, .cxx and distribution folders in Project view.
    • 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 Keymap preference by searching Find action.
    • Search Excluded (not Exclude) 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 --recursive when cloning the repository.

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

or

git clone https://github.com/realm/realm-java.git --recursive

Build

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 with the submodule version of Realm Core. This is done by providing the following parameter when building: -PbuildCore=true.

./gradlew assembleBase -PbuildCore=true

You can turn off interprocedural optimizations with the following parameter: -PenableLTO=false.

./gradlew assembleBase -PenableLTO=false`

Note: Building the Base variant would always build realm-core.

Note: Interprocedural optimizations are enabled by default.

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 -PbuildCore=true or -PenableLTO=false to it. Alternatively you can add it into your gradle.properties:

buildCore=true
enableLTO=false

Note: If building on OSX you might like to prevent Gatekeeper to block all NDK executables by disabling it: sudo spctl --master-disable. Remember to enable it afterwards: sudo spctl --master-enable

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 wrapper task to generate Gradle Wrappers. Those tasks refer to gradle property defined in /dependencies.list to determine Gradle Version of generating wrappers. We have a script ./tools/update_gradle_wrapper.sh to automate these steps. When you update Gradle Wrappers, please obey the following steps.

  1. Edit gradle property in defined in /dependencies.list to new Gradle Wrapper version.
  2. Execute /tools/update_gradle_wrapper.sh.

Gotchas

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 gradle-plugin which adds a dependency to the artifacts produced by realm.
  • The root folder is another Gradle project. All it does is orchestrate the other jobs.

This means that ./gradlew clean and ./gradlew cleanExamples will fail if assembleExamples has not been executed first. Note that IntelliJ does not support multiple projects in the same window so 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.

Examples

The ./examples 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 mavenLocal().

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 adb command must be in your PATH

  1. Connect an Android device and verify that the command adb devices shows a connected device:

    adb devices
    List of devices attached
    004c03eb5615429f device
  2. 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 realm/realm-library/src/syncIntegrationTest require a running testing server to work. A docker image can be built from tools/sync_test_server/Dockerfile to run the test server. tools/sync_test_server/start_server.sh will build the docker image automatically.

To run a testing server locally:

  1. Install docker and run it.

  2. Run tools/sync_test_server/start_server.sh:

    cd tools/sync_test_server
    ./start_server.sh

    This command will not complete until the server has stopped.

  3. 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.

Contributing

See CONTRIBUTING.md for more details!

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

The directory realm/config/studio 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.

License

Realm Java is published under the Apache 2.0 license.

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

Feedback

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!

More Repositories

1

SwiftLint

A tool to enforce Swift style and conventions.
Swift
18,607
star
2

realm-swift

Realm is a mobile database: a replacement for Core Data & SQLite
Objective-C
16,280
star
3

jazzy

Soulful docs for Swift & Objective-C
Ruby
7,341
star
4

realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
TypeScript
5,758
star
5

realm-dotnet

Realm is a mobile database: a replacement for SQLite & ORMs
C#
1,243
star
6

realm-core

Core database component for the Realm Mobile Database SDKs
C++
1,016
star
7

realm-kotlin

Kotlin Multiplatform and Android SDK for the Realm Mobile Database: Build Better Apps Faster.
Kotlin
942
star
8

realm-dart

Realm is a mobile database: a replacement for SQLite & ORMs.
Dart
758
star
9

SwiftCov

A tool to generate test code coverage information for Swift.
Swift
562
star
10

realm-browser-osx

DEPRECATED - Realm Browser for Mac OS X has been replaced by realm-studio which is cross platform.
Objective-C
501
star
11

realm-android-adapters

Adapters for combining Realm Java with Android UI components and framework classes
Java
414
star
12

realm-tasks

To Do app built with Realm, inspired by Clear for iOS
Swift
369
star
13

summer-of-swift

An ephemeral contest to learn Swift by doing
308
star
14

realm-studio

Realm Studio
TypeScript
300
star
15

realm-object-server

Tracking of issues related to the Realm Object Server and other general issues not related to the specific SDK's
Shell
293
star
16

RealmContent

Light Realm-powered content management system
Swift
238
star
17

realm-cocoa-converter

A library that provides the ability to import/export Realm files from a variety of data container formats.
Swift
219
star
18

realm-draw

The official Realm Draw app used in promotional videos
C#
163
star
19

github-gantt

Generate Gantt Charts From Github Issues!
JavaScript
156
star
20

realm-object-store

Cross-platform abstractions used within Realm products
C++
119
star
21

realm-kotlin-samples

Samples demonstrating the usage of Realm-Kotlin SDK
Kotlin
91
star
22

RChat

Swift
88
star
23

realm-graphql

GraphQL client for Realm Object Server
TypeScript
80
star
24

realm-loginkit

A generic interface for logging in to Realm Mobile Platform apps
Swift
74
star
25

realm-cpp

Realm C++
C++
73
star
26

realm-dart-samples

Samples for Realm Flutter and Realm Dart SDKs
C++
68
star
27

EventKit

A template conference app, featuring real-time schedule and data changes & running on Realm πŸš€
Swift
63
star
28

realm-scanner

A scanning app that can analyze and report on any photos it is given
Java
54
star
29

react-realm-context

Components that simplifies using Realm with React
TypeScript
50
star
30

realm-graphql-service

GraphQL service for Realm Object Server
TypeScript
43
star
31

RealmPop

Java
39
star
32

my-first-realm-app

ToDo demo app using Realm and Realm Object Server to synchronize tasks.
Java
38
star
33

task-tracker-swiftui

Simple task manager using Realm and SwiftUI
Swift
36
star
34

realm-dvdrental

Demo inventory application which synchronizes data originating in Postgres via the Realm Postgres data connector.
Swift
36
star
35

realm-android-user-store

Java
35
star
36

realm-inventory

An sample inventory app demonstrating safe counters via Lists and Realm Counters
Swift
32
star
37

unity-examples

C#
30
star
38

realm-teamwork-MR

A Realm demo app showing an idealized version of a field-service type application using multiple Realms, permissions, etc
Swift
26
star
39

FindOurDevices

A React Native + MongoDB Realm application for allowing users to see location and movement of their own devices or those of people in the same private group.
JavaScript
25
star
40

node-template-project

A template for your Node and TypeScript Project with Visual Studio Code Debugging!
TypeScript
23
star
41

realm-flipper-plugin

A Flipper plugin to debug React Native applications using a Realm database.
TypeScript
20
star
42

realm-java-benchmarks

Kotlin
18
star
43

realm-drawkit

A modular drawing library that uses RMP for collaboration
Swift
17
star
44

aws-devicefarm

Github action for triggering runs on AWS devicefarm
JavaScript
17
star
45

Scrumdinger

Showing how the app from Apple's SwiftUI tutorial can be enhanced by adding Realm
Swift
16
star
46

awesome-realm

A curated list of awesome Realm resources, libraries, tools and applications
15
star
47

roc-ios

Swift
14
star
48

realm-search

An example implementation of synchronizing specific objects from a massive global Realm.
Swift
13
star
49

roc-ios-controller

A Chat Controller powered by Realm and Chatto
Swift
13
star
50

realm-puzzle

A small collaborative game where players work to complete a jigsaw puzzle.
Objective-C
12
star
51

realm-sync-demos

Demo apps for MongoDB Realm Sync
Kotlin
11
star
52

RCurrency

Swift
10
star
53

jazzy-integration-specs

Integration specs for https://github.com/realm/jazzy
HTML
10
star
54

realm-MultiUserTasksTutorial

Walk-though of constructing a multi-user example using Realm Tasks
Swift
9
star
55

charts

A Collection of Helm Charts
Smarty
9
star
56

realm-surveys

A reactive survey application powered by Realm
Swift
9
star
57

realm-connectors

Realm Object Server Data Connectors
8
star
58

realm-cloud-functions-demo

Realm & IBM Cloud Functions demo
JavaScript
8
star
59

realm-dotnet-groupedcollection

C#
8
star
60

realm-dotnet-lfs

C#
8
star
61

electron-react-samples

TypeScript
7
star
62

Realm-Sweeper

Swift
7
star
63

FindOurDevices-backend

A backend MongoDB Realm application for allowing users to see location and movement of their own devices or those of people in the same private group.
JavaScript
7
star
64

Realm-Drawing

Swift
6
star
65

feedback-manager

A simple Realm-powered feedback app that employs the Azure Text Analytics API to extract sentiment and key phrases from tickets
C#
5
star
66

BarCodes-Demo

A small demo app to show how to scan barcode and place into into a Realm
Swift
5
star
67

realm-qna

question and answer app
Swift
4
star
68

realm-dotnet-samples

C#
4
star
69

realm-swift-samples

Sample applications for realm-swift database
Swift
4
star
70

realm-tools

Various tools for testing Realm
TypeScript
3
star
71

ci-actions

A repository for commonly used GitHub Actions inside the various realm repositories
TypeScript
3
star
72

xamarin-examples-architecture

Test
C#
3
star
73

realm-flexible-sync-test-api

Sample App for A/B testing two version of the Flexible Sync API
Swift
3
star
74

realm-SharedTasks

Swift
2
star
75

unity-examples-3d-chess

Examples and tutorials for the Realm Unity SDK.
2
star
76

global-notifier-design-patterns

C++
2
star
77

realm.github.io

HTML
2
star
78

realm-object-server-cognito-auth

Cognito authentication provider for Realm Object Server
TypeScript
2
star
79

aws-devicefarm-sample-data

Sample data to use with the AWS devicefarm action
Java
1
star
80

realm-lua-bootcamp

Teaching the basics of building a Realm SDK
C++
1
star
81

realm-crowdcircle

A collaborative experimental game, played between 6 teams
Swift
1
star
82

realm-js-playground

JavaScript
1
star