【问题标题】:android cannot find realm gradle dependencyandroid找不到领域gradle依赖
【发布时间】:2016-04-19 07:45:34
【问题描述】:

我在构建时收到此错误:

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'

如何解决这个错误?

项目级分级:

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
}

【问题讨论】:

  • 将该模块添加到您的项目中
  • 将 realm-android 插件应用到应用层 build.gradle 文件的顶部。应用插件:'realm-android'
  • @M D 我已经添加了
  • @Dhamaraj 我已经这样做了
  • 移除这个依赖{ compile 'io.realm:realm-android:0.88.3' //这里有更多依赖}

标签: android gradle realm


【解决方案1】:

从 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" 继续关注最新版本:realm.io/docs/java/latest
  • 嗯从 0.84.1 更新到 1.0.1 插件,但现在完全找不到 Realm。我在 build.gradle 中定义了类路径并在我的模块中应用插件。该模块是一个库,这可能是个问题吗?
【解决方案2】:

第一步:在项目级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/查找最新版本

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-22
    • 1970-01-01
    • 1970-01-01
    • 2015-09-16
    • 2016-07-11
    • 2015-11-11
    • 2015-02-17
    相关资源
    最近更新 更多