构建时出现此错误:
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
}
答案 0 :(得分:8)
从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'
}
答案 1 :(得分: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'
查找最新版本