当前位置: 首页 > 软件库 > 手机/移动开发 > >

realm-java

授权协议 View license
开发语言 Java
所属分类 手机/移动开发
软件类型 开源软件
地区 不详
投 递 者 长孙瑞
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

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

See Realm Kotlin for more information about our new SDK written specifically for Kotlin Multiplatform and Android. The SDK is still experimental and the API surface has not been finalized yet, but we highly encourage any feedback you might have.

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.

Getting Started

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

Documentation

Documentation for Realm can be found at realm.io/docs/java.The API reference is located at realm.io/docs/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 git@github.com: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 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 implythat 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 reportunacceptable behavior to community-conduct@mongodb.com.

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 thestyle/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 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 isnot eligible to receive the product under U.S. law.

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 是一个轻量的android版本的数据存储库 Realm 是一个轻量的android版本的数据存储库,快速简洁的操作方式,使得其优势得以凸显,我们来看下一个实例: // 定义需要存储的类,继承自 RealmObject public class Dog extends RealmObject { @Required // Name cannot b

  • 我遵循android realm hear的入门指南. 我将最新的android studio版本3.0 RC 1与以下build.gradle文件一起使用: buildscript { repositories { jcenter() google() } dependencies { classpath 'com.android.tools.build:gradle:3.0.0-rc1' cl

  • Realm(Java)数据库使用文档(目录) Realm的默认架构只是项目中的所有Realm模型类。但是,您可以更改此行为-例如,您可能希望限制Realm仅包含类的子集。为此,请创建一个自定义RealmModule。 // 创建module @RealmModule(classes = { Person.class, Dog.class }) public class MyModule { }

  • 本篇博客给大家带来一篇关于Android 数据库的内容。 Android中的数据库,我们的老朋友-SQLite,想必大家都不陌生。轻量级的SQLite以及Android为我们封装的SQL操作,让开发者操作数据库变得异常简单。但是,频繁的编写SQL语句让我们仍然痛苦不堪。渐之,ORM的出现改变了这种格局(ORM,对象关系映射)。ORM的出现,让开发者可以在不关注SQL语句的情况下,以面向对象的方式来

  • 我这里有个奇怪的用例,我的项目分为2个模块,一个是服务器项目,另一个是android-app,现在它们都共享相同的模型类.在Eclipse中使用Maven构建工具进行服务器项目,在Android Studio中使用gradle进行android-app应用. 看起来像是没有maven工件的领域,也没有找到最新版本的jar文件. 请帮助我找出奇怪的情况. 解决方法: 您需要在模型中加入某种技巧才能在

  • 简述: 数据库Realm,是用来替代sqlite的一种解决方案,它有一套自己的数据库存储引擎,比sqlite更轻量级,拥有更快的速度,并且具有很多现代数据库的特性,比如支持JSON,流式api,数据变更通知,自动数据同步,简单身份验证,访问控制,事件处理,最重要的是跨平台,目前已有Java,Objective C,Swift,React-Native,Xamarin这五种实现。 1.易用:Ream

  • failed to execute ‘send’ on ‘xmlhttprequest’ 方案一:修改node_modules/realm/lib/browser/rpc.js if (global.__debug__) { let request = global.__debug__.require('sync-request'); let response = request(

 相关资料
  • Realm 是一个移动数据库,可运行于手机、平板和可穿戴设备之上。可以让你的应用更快速,带来难以想象的体验。其目标是为了代替 CoreData 和 SQLite 数据库。 目前支持 iOS/OS X/Android 平台,提供 Swift/Objective-C/Java 语言的 API: // Optional: turn off persistenceRLMRealm.useInMemoryD

  • 一个用于Stetho的Realm模块:可以通过Stetho,在Chrome浏览器上查看Realm数据库。 使用方法: 1. 在您的build.gradle文件中添加: repositories {    maven { url "https://jitpack.io" }}dependencies {    compile 'com.facebook.stetho:stetho:1.5.0'   

  • Realm 是手机数据库,是 Core Data 和 SQLite 的替代品。

  • 行动时刻 - 定义领域 以下步骤演示了如何定义领域: 将以下域添加到位于FreeRADIUS配置目录下的proxy.conf文件中: realm my-org.com { } 以调试模式重新启动FreeRADIUS服务器,并以alice@my-org.com身份进行验证。 观察FreeRADIUS服务器的输出。 以下应该是输出的一部分: [suffix] Looking up realm "my

  • 问题内容: 我在活动中创建了一个领域对象。我需要能够在我创建的服务中访问该对象。但是在服务中创建Realm对象时出现错误 java.lang.IllegalStateException:来自错误线程的领域访问。只能在创建对象的线程上访问领域对象 现在我理解这意味着,因为领域对象是在我的活动上创建的,所以我无法从后台线程访问它。但是,除了创建自己的自定义处理程序线程外,我没有找到其他简便的方法,但这

  • 行动时刻 - 激活NULL领域 请按照以下步骤激活NULL域: 编辑FreeRADIUS配置目录下的proxy.conf文件,并更改以下部分: #realm NULL { # authhost = radius.company.com:1600 # accthost = radius.company.com:1601 # secret = testing123 #} 更改为: realm NUL