如何安装域作为gradle依赖?

dev*_*dev 11 android realm

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

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

这是他们在文档中给出的.但这对我不起作用.它给出了错误说法Plugin with id 'realm-android' not found.

这是我的build.gradle文件

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'
  }
Run Code Online (Sandbox Code Playgroud)

我的配置是否正确?

Sar*_* Kn 24

移动buildscript到您的主build.gradle文件(Project),它不应该在build.gradle(模块:app)中

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

这应该转到main build.gradle

  • 从领域文档现在最新的版本是`3.3.1`就是`类路径"io.realm:境界 - gradle这个-插件:3.3.1"`编号:https://realm.io/docs/java/latest/ #安装 (2认同)

Wat*_*236 20

首先将类路径依赖项复制到build.gradle文件(Project): -

    buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "io.realm:realm-gradle-plugin:1.2.0"
    }
}
Run Code Online (Sandbox Code Playgroud)

最后,将以下代码复制并粘贴到build.gradle(App)之上: -

apply plugin: 'realm-android'
Run Code Online (Sandbox Code Playgroud)

注意: - 版本1.2.0将在未来发布时更改.有关更多信息,请访问https://realm.io/docs/java/latest/