为什么 butterknife 9.0.0-SNAPSHOT 无法解析?

Why is butterknife 9.0.0-SNAPSHOT not resolving?

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

设置

app:模块依赖

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()
    }

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

添加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

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

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

根据 Naveen 的回答,解决方案是 here
但是,缺少细节。完整解决方案请参考以下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'
...

基本上,不要使用建议 here 中的 apply plugin: 'com.jakewharton.butterknife'classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-SNAPSHOT'

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

首先,我要感谢@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
}

也添加支持Java 1_8 build.gradleandroid 部分

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_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 和 butterknife,请将 annotationProcessor 替换为 kapt

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

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

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

它在 androidx 中工作