Gradle构建错误:使用Realm时无法访问ParametersAreNonnullByDefault类文件



我正在写一个Android库项目,我有一个依赖于Realm。由于某种原因,当我在Gradle文件中添加Realm作为依赖项时,我得到了一个构建错误。具体来说:

Error:cannot access ParametersAreNonnullByDefault
class file for javax.annotation.ParametersAreNonnullByDefault not found

我只是在看Realm网站的入门指南。

我的项目级别构建。Gradle是这样的:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'
        classpath 'io.realm:realm-gradle-plugin:1.2.0'
    }
}
allprojects {
    repositories {
        jcenter()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

我的应用级gradle。构建看起来像这样:

apply plugin: 'com.android.library'
apply plugin: 'realm-android'
android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"
    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 24
        versionCode 9
        versionName "1.2.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError false
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:support-annotations:24.2.0'
    compile 'com.android.support:support-v4:24.2.0'
    compile 'com.google.code.gson:gson:2.4'
    //Puree
    compile 'com.cookpad.puree:puree:4.1.1'
    //Square
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
    compile 'com.squareup:tape:1.2.3'
}

我不知道出了什么问题。起初我认为这可能是其他依赖关系之间的一些冲突,但我创建了一个新项目,一个接一个地添加相同的依赖关系,我没有编译问题。

您可以尝试添加以下依赖项:

// https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305
compile 'com.google.code.findbugs:jsr305:1.3.9' //try also provided

最新更新