【问题标题】:Gradle build error: cannot access ParametersAreNonnullByDefault class file when using RealmGradle 构建错误:使用 Realm 时无法访问 ParametersAreNonnullByDefault 类文件
【发布时间】:2016-09-15 13:50:40
【问题描述】:

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

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

我只是关注 Realm 网站上的入门。

我的项目级 build.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.build 如下所示:

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'
}

我不知道出了什么问题。一开始我还以为是其他依赖有冲突,后来新建了一个项目,把同样的依赖一一添加,编译没有问题。

【问题讨论】:

  • 我能够构建项目。具有完全相同的配置。您是否尝试过清理和构建?
  • 是的,清理并构建了几次。没有运气:(
  • 你在混淆你的应用吗?
  • minifyEnabled 为假
  • 你能添加堆栈跟踪吗? ./gradlew build --stacktrace

标签: android gradle realm


【解决方案1】:

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

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

【讨论】:

  • 由于某种奇怪的原因,它在添加此依赖项时起作用。你能解释一下为什么吗?谢谢你的答案!
  • 老实说:我不知道。它是只适用于compile,还是也适用于provided 而不是compile
  • 很好,至少这意味着你不必添加任何额外的东西:) 我不知道你的结果是什么。这不是 Realm afaik 的依赖项
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-05
  • 1970-01-01
  • 2023-03-22
相关资源
最近更新 更多