Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install realm as a gradle dependency?

Tags:

android

realm

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?

like image 882
dev Avatar asked Mar 16 '16 06:03

dev


2 Answers

Move the buildscript to your main build.gradle file (Project) , it shouldn't be there in build.gradle (module:app)

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

This should go to main build.gradle

like image 191
Sarath Kn Avatar answered Oct 15 '22 10:10

Sarath Kn


First of all copy the class path dependency to build.gradle file(Project):-

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

Finally, copy and paste the following code on top of build.gradle(App) :-

apply plugin: 'realm-android'

Note:- The version 1.2.0 is subjected to change on future releases.For more please check https://realm.io/docs/java/latest/

like image 27
WaterRocket8236 Avatar answered Oct 15 '22 12:10

WaterRocket8236