5

我正在使用 Android Studio 3.0 Beta 7、Kotlin 1.4-2 和Room Persistence Library 1.0.0-beta1 编译 Android 项目。

这是我在其中添加 Room 依赖项的 Gradle 文件的一部分:

implementation "android.arch.persistence.room:runtime:1.0.0-beta1"
kapt "android.arch.persistence.room:compiler:1.0.0-beta1"

编译时出现以下错误:

警告:警告:注释处理器'android.arch.persistence.room.RoomProcessor'支持的源版本'RELEASE_7'小于-source'1.8'

将堆栈跟踪/调试标志添加到编译选项后,这是我得到的错误:

错误:org.jetbrains.kotlin.kapt3.diagnostic.KaptError:注释处理时出错

10:08:03.727 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] 10:08:03.727 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] 失败:构建失败并出现异常。10:08:03.727 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] 10:08:03.727 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] * 出了什么问题:10:08:03.727 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] 任务“:app:kaptDebugKotlin”执行失败。10:08:03.727 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] > 内部编译器错误。有关详细信息,请参阅日志 10:08:03.728 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 10:08:03.728 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * 例外是:10:08 :03.728 [错误] [org。gradle.internal.buildevents.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException:任务':app:kaptDebugKotlin'的执行失败。10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100) 10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] 在 org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70) 10:08:03.728 [错误] [org.gradle.internal.buildevents .BuildExceptionReporter] 在 org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63) 10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] 在 org.gradle。 api.internal。DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99) 10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java: 63) 10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46) 10:08:03.729 [错误] [ org.gradle.internal.buildevents.BuildExceptionReporter] 在 org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55) 10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]原因:org.gradle.api.GradleException:内部编译器错误。有关更多详细信息,请参阅日志 10:08:03.729 [错误] [org.gradle.internal.buildevents.https://help.gradle.org 10:08:03.730 [错误] [org.gradle.internal.buildevents.BuildResultLogger] 10:08:03.730 [错误] [org.gradle.internal.buildevents.BuildResultLogger] 内置失败8s

清理/重建没有帮助。什么可能导致此错误?临时解决方案似乎是用标准的“annotationProcessor”替换“kapt”,重建然后用“kapt”再次构建。但在项目进一步更改后,错误再次出现。

[编辑]

我的 Gradle 文件(应用程序模块):

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.mydomain.myapp"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

androidExtensions {
    experimental = true
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

    // Anko Commons
    implementation "org.jetbrains.anko:anko-commons:$anko_version"

    // Timber logging
    implementation "com.jakewharton.timber:timber:$timber_version"

    // Architecture components - Lifecycle
    implementation "android.arch.lifecycle:extensions:$arch_version"
    kapt "android.arch.lifecycle:compiler:$arch_version"

    // Architecture components - Room ORM
    implementation "android.arch.persistence.room:runtime:$arch_version"
    kapt "android.arch.persistence.room:compiler:$arch_version"

    // Retrofit
    implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
    implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"

    // Picasso
    implementation "com.squareup.picasso:picasso:$picasso_version"
}

Gradle(项目模块):

buildscript {
    ext.kotlin_version = '1.1.4-2'
    ext.anko_version = '0.10.1'
    ext.timber_version = '4.5.1'
    ext.retrofit_version = '2.3.0'
    ext.picasso_version = '2.5.2'
    ext.constraint_layout_version = '1.0.2'
    ext.support_library_version = '26.1.0'
    ext.arch_version = '1.0.0-beta1'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-beta7'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
4

2 回答 2

7

我也在使用 kapt 插件和房间,并且有类似的错误。就我而言,我通过将这条线 apply plugin: 'kotlin-kapt'从块移动app build.gradle到块top build.gradle外来解决它buildscript{},然后错误就消失了。 我在这里找到了

于 2017-10-07T04:15:14.973 回答
1

而不是依赖版本1.0.0-beta1使用1.0.0-beta2并尝试编译。

于 2017-10-06T11:51:21.080 回答