安卓找不到Realm Gradle依赖

7

我在构建过程中遇到了这个错误:

Failed to sync Gradle project 'myapp'
Error:Could not find io.realm:realm-android:0.88.3.
Required by:
    myapp:app:unspecified

Search in build.gradle files

在我的项目级Gradle中,我已经添加了以下内容:
classpath "io.realm:realm-gradle-plugin:0.88.3"

在我的模块级别:

compile 'io.realm:realm-android:0.88.3'

如何修复此错误?

项目级别的Gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0'
        classpath 'io.realm:realm-gradle-plugin:0.88.3'
    }
}

模块级别:

apply plugin: 'com.android.application'
apply from: '../config/quality/quality.gradle'
apply plugin: 'realm-android'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "xxxxx"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    buildTypes {
        debug {
            applicationIdSuffix ".debug"
            versionNameSuffix "-debug"
            debuggable true
        }
        release {
            minifyEnabled true
            debuggable false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}



dependencies {
    compile 'io.realm:realm-android:0.88.3'
    //more dependencies here
}

将该模块添加到您的项目中。 - M D
1
将realm-android插件应用于应用程序级别的build.gradle文件顶部。应用插件:'realm-android' - Dharmaraj
@M D 我已经添加了。 - Nongthonbam Tonthoi
仅显示Gradle。 - Dharmaraj
1
移除以下依赖项 { compile 'io.realm:realm-android:0.88.3' //更多依赖项在此处 } - Dharmaraj
显示剩余5条评论
2个回答

11

从0.88版本开始,Realm是一个插件而不是编译依赖项,因此您需要应用插件realm-android。这里也有描述:https://realm.io/docs/java/latest/#installation

顶层构建文件

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

应用级别的构建文件

apply plugin: 'realm-android'

在你的情况下,你应该移除

dependencies {
    compile 'io.realm:realm-android:0.88.3'
}

当前最新版本:classpath "io.realm:realm-gradle-plugin:1.0.1"请持续关注最新版本:https://realm.io/docs/java/latest/ - Pratik Butani
1
嗯,我将插件从0.84.1更新到了1.0.1,但现在Realm完全找不到了。我已经在build.gradle中定义了classpath,并在我的模块中应用了插件。这个模块是一个库,可能会有问题吗? - Orbit

3
步骤1:将以下类路径依赖项添加到项目级别的build.gradle文件中。
buildscript {
repositories {
    jcenter()
}
dependencies {
   //check & update 3.0.0 with latest version
    classpath "io.realm:realm-gradle-plugin:3.0.0"
}
}

步骤2:将realm-android插件应用于应用程序级别的build.gradle文件顶部。
apply plugin: 'realm-android'

https://realm.io/docs/java/latest/找到最新版本。

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接