我完全不知道发生了什么。我已尝试在SO中发布的每个解决方案,但问题仍然存在。
同步Gradle文件时,一切顺利:
Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies]
Parallel execution with configuration on demand is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2421Library UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportCompat2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportCoreUi2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportCoreUtils2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportFragment2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportMediaCompat2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportVectorDrawable2421Library UP-TO-DATE
:app:prepareComGetkeepsafeRelinkerRelinker121Library UP-TO-DATE
:app:prepareComJakewhartonButterknife840Library UP-TO-DATE
:app:prepareIoRealmRealmAndroidLibrary120Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareDebugAndroidTestDependencies
:app:compileDebugAndroidTestAidl UP-TO-DATE
:app:processDebugAndroidTestManifest UP-TO-DATE
:app:compileDebugAndroidTestRenderscript UP-TO-DATE
:app:generateDebugAndroidTestBuildConfig UP-TO-DATE
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources UP-TO-DATE
:app:mergeDebugAndroidTestResources UP-TO-DATE
:app:processDebugAndroidTestResources
:app:generateDebugAndroidTestSources
:app:mockableAndroidJar UP-TO-DATE
:app:preDebugUnitTestBuild UP-TO-DATE
:app:prepareDebugUnitTestDependencies
BUILD SUCCESSFUL
Total time: 2.906 secs
然后问题是当我点击"播放"按钮运行应用程序,抛出这个恼人的错误:
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.NullPointerException
在控制台中运行gradle build --stacktrace
,我收到以下消息:
FAILURE: Build failed with an exception.
* Where:
Build file '.../project-name/app/build.gradle' line: 1
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.application']
> Minimum supported Gradle version is 2.14.1. Current version is 2.11. If using the gradle wrapper, try editing the distributionUrl in /Users/jozan/projects/krimturstudios/adventures/gradle/wrapper/gradle-wrapper.properties to gradle-2.14.1-all.zip
有趣的是,我已经将gradle 2.11设置为无处...它始终是2.14.1。
在我的Android Studio设置中,我检查了选项"使用默认的gradle包装器(推荐)"。
在我的项目设置中,我将Gradle版本设置为2.14.1。
这是我的 gradle-wrapper.properties 文件:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
这是我的项目 build.gradle 文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
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.application"
apply plugin: "android-apt"
apply plugin: "realm-android"
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "..."
minSdkVersion 17
targetSdkVersion 24
versionCode 1
versionName "0.2"
}
buildTypes {
debug {
applicationIdSuffix ".debug"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
}
dependencies {
// Local
compile fileTree(include: ["*.jar"], dir: "libs")
// Testing
testCompile "junit:junit:4.12"
// Android
compile "com.android.support:appcompat-v7:24.2.1"
compile "com.android.support:support-v4:24.2.1"
// Butterknife
compile "com.jakewharton:butterknife:8.4.0"
apt "com.jakewharton:butterknife-compiler:8.4.0"
}
请任何人,这让我发疯了!
答案 0 :(得分:0)
在cmd类型的gradlew中。它应该下载2.14版本。
答案 1 :(得分:0)
删除并克隆我的仓库后,逐步添加每个更改,我终于解决了问题。
Gradle和Android Studio都没有造成这种情况,但 Realm !。
我在模型类中声明了这个字段:
private RealmList<? extends Item> items;
以某种方式阻止gradle正确构建。删除允许构建和部署。
有趣的是,Realm不会给我任何错误或警告......也许是一个错误。