How to install realm as a gradle dependency?

Viewed 28456

I am completely new to realm. I want to use realm db in my android project. I have gone through the official Realm documentation. I need to set up realm in my android project. For that I have added the gradle dependancy as

    buildscript {
            repositories {
                     jcenter()
                         }
            dependencies {
                classpath "io.realm:realm-gradle-plugin:0.88.2"
           }
       }
 apply plugin: 'realm-android'

This is what they have given in documentation. But this doesn't work for me. It gives error saying Plugin with id 'realm-android' not found.

This is my build.gradle file

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.db.realmsample"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "io.realm:realm-gradle-plugin:0.88.2"
    }
  }

 }

 dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  testCompile 'junit:junit:4.12'
  compile 'com.android.support:appcompat-v7:23.2.1'
  }

Is my configuration correct?

4 Answers

Prerequisites

  • Android Studio version 1.5.1 or higher
  • JDK version 7.0 or higher
  • A recent version of the Android SDK
  • Android API Level 9 or higher (Android 2.3 and above)

Step 1: Add the class path dependency to the project level build.gradle file.

buildscript {
 repositories {
    jcenter()
 }
 dependencies {
    classpath "io.realm:realm-gradle-plugin:4.1.1"
 }
}

Step 2: Apply the realm-android plugin to the top of the application level build.gradle file.

apply plugin: 'realm-android'

Step 3: Gradle sync

For the official complete installation guide. Please see the following link.

https://realm.io/docs/java/latest/#installation

Related