【发布时间】: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