我在构建时遇到这个错误:
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.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'
}
关于android 找不到 Realm gradle 依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36711792/