12

我想使用 AndroidX 库,下面是我为 Butterknife 设置的 Gradle

应用:模块依赖

implementation 'com.jakewharton:butterknife:9.0.0-SNAPSHOT'
 annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT'

插入

apply plugin: 'com.jakewharton.butterknife'

项目依赖

dependencies {
      classpath 'com.android.tools.build:gradle:3.3.0-alpha09'
      classpath 'com.google.gms:google-services:4.0.1'
      classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-SNAPSHOT'
      // NOTE: Do not place your application dependencies here; they belong
      // in the individual module build.gradle files
    }

项目存储库

repositories {
        google()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
        jcenter()
    }
4

8 回答 8

18

更新: 您现在可以简单地使用 ButterKnife 9-rc02 而不是上述解决方案:

...
dependencies {
    implementation 'com.jakewharton:butterknife:9.0.0-rc2'
    annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc2'
...

根据 Naveen 的回答,解决方案在这里
但是,缺少细节。请参考以下 Gradle 配置以获得完整的解决方案:

buildscript {
    repositories {
        jcenter()
        google()
        maven { url "https://jitpack.io" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0-alpha10'
    }
}

allprojects {
    repositories {
        jcenter()
        google()
        maven { url "https://jitpack.io" }
        mavenCentral()
        maven {
            name 'Sonatype SNAPSHOTs';
            url 'https://oss.sonatype.org/content/repositories/snapshots/'
        }
    }
}

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



...
dependencies {
    implementation 'com.jakewharton:butterknife:9.0.0-SNAPSHOT'
    annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT'
...

基本上,不要使用apply plugin: 'com.jakewharton.butterknife'and classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-SNAPSHOT'from这里的建议。

此外,此 Android Studio 设置 > 编译器配置: Android Studio 设置 > 编译器配置

于 2018-09-13T07:45:22.690 回答
8

请注意,Butterknife 现在已经达到 10.1.0,不再需要 SNAPSHOT 版本或任何其他 maven 库。AndroidX 迁移很有魅力。只需包括:

dependencies {
    implementation 'com.jakewharton:butterknife:10.1.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
}

或者,如果由于某种原因您将 Kotlin 和黄油刀结合使用,请替换annotationProcessorkapt.

欲了解更多信息,请访问: https ://github.com/JakeWharton/butterknife

于 2019-03-07T19:59:16.617 回答
4

添加 name 'Sonatype SNAPSHOTs';

dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3' //3.1.4

    }

    buildscript {
            repositories {
                google()
                jcenter()
                mavenCentral()
                // TODO remove after butterknife 9 graduates to stable
                maven {
                    name 'Sonatype SNAPSHOTs';
                    url 'https://oss.sonatype.org/content/repositories/snapshots/'
                }

            }

供参考

您可以使用

   implementation 'com.jakewharton:butterknife:8.8.1'
   annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

Butter Knife

于 2018-09-12T11:49:32.580 回答
4

首先,我想感谢@intellij-amiya 和@Nabster 的宝贵贡献,因为这个答案是基于他们提供的答案。

我的 Gradle 设置如下

...
apply plugin: 'com.jakewharton.butterknife'
....
dependencies{
    implementation 'com.jakewharton:butterknife:9.0.0-SNAPSHOT'
    annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT'
}
...

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        mavenCentral()
        maven {
            name 'Sonatype SNAPSHOTs'
            url 'https://oss.sonatype.org/content/repositories/snapshots/'
        }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0-alpha09'
        classpath 'com.google.gms:google-services:4.0.1'
        classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-SNAPSHOT'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven {
            name 'Sonatype SNAPSHOTs'
            url 'https://oss.sonatype.org/content/repositories/snapshots/'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
于 2018-09-13T14:40:10.080 回答
1

请参阅关于 Butter Knife 9.0.0-SNAPSHOT 和 Android studio 3.0 之间冲突的对话。
https://github.com/JakeWharton/butterknife/issues/1145

于 2018-09-12T11:47:20.327 回答
0

还在android部分的build.gradle中添加对 Java 1_8 的支持

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
于 2018-11-21T14:42:13.010 回答
0

遵循 GitHub 存储库的说明,该存储库对我来说 100% 使用最新 版本

于 2019-09-22T15:16:39.553 回答
-1
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'

它在androidx中工作

于 2019-09-24T14:48:23.507 回答