realm-java README

The project's README from github.com/realm/realm-java. As one markdown file: README.md.

[!WARNING] We announced the deprecation of Atlas Device Sync + Realm SDKs in September 2024. For more information please see:

realm

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

Getting Started

Please see the Quick Start to add Realm to your project.

Documentation

Documentation for Realm can be found in the docs/ directory.

The Javadoc and Kotlin Extensions API Reference docs can be generated from source.

Getting Help

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

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)

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:

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

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:

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().

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!

realm-java (realm/realm-java)

Searching Database…

这是什么?Realm Java 是一款面向 Android 的移动端数据库,可以替代 SQLite 和传统的 ORM,让应用以普通对象的形式存储和查询数据。
这是库还是独立应用?它是一个嵌入到 Android 项目中的库,由 Gradle 插件、基于 JNI 的原生数据库引擎,以及用于生成模型类的注解处理器组成。
我该如何把它添加到项目中?按照快速入门指南,将 Realm Gradle 插件和库依赖添加到你的 Android 项目中;从源码构建则需要 JDK 8、Android Studio、NDK 和 CMake。
这个项目还在维护吗?不再维护——Realm Java 和 Atlas Device Sync 已于 2024 年 9 月正式被弃用,README 建议新项目改用更新的 Realm Kotlin SDK。
这个也能在 iOS 上运行吗?不能,这个仓库只支持 Java,目前仅能在 Android 上运行;其他平台由独立的 Realm SDK 提供支持。
和 SQLite 加 ORM 相比,Realm 有什么优势?Realm 无需 ORM 层,就能将数据直接以可查询的对象形式提供;官方称在常见操作上比原生 SQLite 更快,并且开箱即支持线程安全、关系和加密。
新应用应该用 Realm Java 还是 Realm Kotlin?README 建议所有新项目都使用 Realm Kotlin,因为它现已正式发布,同时支持 Android 和 Kotlin Multiplatform,而 Realm Java 正在逐步淘汰。
Device Sync 是什么?还能用吗?Device Sync 可以让你实时同步多个用户、多台设备与后端之间的数据,但截至 2024 年 9 月,它已和 Realm SDK 一起被弃用。
正式发布前,能先测试尚未发布的修复吗?可以,你可以通过 Gradle 从 Sonatype OSS 仓库拉取当前开发版本的 -SNAPSHOT 构建。
Creator
realm
Size
64.4 MB
Stars
11.5K
Updated
CommitSep 15
Age
14y
Commits · 90 Days