如何将Realm安装为Gradle依赖项? [英] How to install realm as a gradle dependency?

查看:91
本文介绍了如何将Realm安装为Gradle依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对领域完全陌生.我想在我的android项目中使用realm db.我已经阅读了官方的领域文档.我需要在我的android项目中设置领域.为此,我将gradle依赖项添加为

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'

这是他们在文档中给出的.但这对我不起作用.出现错误,提示Plugin with id 'realm-android' not found.

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.

这是我的build.gradle文件

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'
  }

我的配置正确吗?

推荐答案

buildscript移动到主build.gradle文件(项目)中,该文件不应位于build.gradle(模块:应用程序)中

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>"
   }
 }

这应该转到主build.gradle

This should go to main build.gradle

这篇关于如何将Realm安装为Gradle依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆