【问题标题】:Butterknife gradle error on Android Studio 3.0 due to android-apt plugin由于 android-apt 插件,Android Studio 3.0 上的 Butterknife gradle 错误
【发布时间】:2017-10-26 13:27:50
【问题描述】:

升级到 Android Studio 3.0 后,我遇到了一些 gradle 问题,我能够修复检查开发人员website

但是,我无法找到如何解决 apply plugin: 'android-apt' 的问题。我尝试了几件事,例如将其从项目 gradle 中删除并将其作为 annotationProcessor 'com.neenbedankt.gradle.plugins:android-apt:1.8' 添加到应用程序 gradle 中。还删除了apt等。

无论如何,Studio 都在抱怨它。任何帮助是极大的赞赏。谢谢!

    // 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:3.0.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'com.google.gms:google-services:3.1.1'

    }
}

allprojects {
    repositories {
        jcenter()
        google()
        maven { url "https://jitpack.io" }
    }

    ext {
        supportLibVersion = '27.0.0'
        firebaseLibVersion = '11.4.2'
    }
}

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

应用分级

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.0"
    defaultConfig {
        applicationId "xxxxxxxxxxxxxxxxxxxx"
        minSdkVersion 17
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"

        vectorDrawables.useSupportLibrary = true

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    apply plugin: 'android-apt'
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')

    compile "com.android.support:appcompat-v7:${supportLibVersion}"
.....

    compile 'com.google.android.gms:play-services-auth:11.4.2'

    compile 'com.jakewharton:butterknife:8.4.0'
    apt 'com.jakewharton:butterknife-compiler:8.4.0'

}
apply plugin: 'com.google.gms.google-services'

【问题讨论】:

  • 而不是 apt 使用 annotationProcessor 并删除 classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
  • 有关它为什么不起作用的更多背景信息。 apt 不再受支持。

标签: android android-gradle-plugin build.gradle butterknife android-studio-3.0


【解决方案1】:

不要使用apt插件,像这样添加依赖:

compile "com.jakewharton:butterknife:8.8.1"
annotationProcessor "com.jakewharton:butterknife-compiler:8.8.1"

Reference

【讨论】:

【解决方案2】:

如果你赶时间,你可以禁用那个东西。

根据文档

如果您在迁移到新依赖项时遇到问题 解决策略,您可以将行为恢复到 Android 的行为 插件 2.3.0 通过将 includeCompileClasspath 设置为 true。然而, 不建议将行为恢复到 2.3.0 版。

android {
    ...
    defaultConfig {
        ...
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath false
            }
        }
    }
}

还有一件事你必须在 gradle 文件的 buildTypes 标签中定义 flavorDimensions "default" 属性。

你可以查看更多关于这个here的信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-20
    • 1970-01-01
    • 2018-04-10
    • 1970-01-01
    相关资源
    最近更新 更多