【问题标题】:Why is butterknife 9.0.0-SNAPSHOT not resolving?为什么butterknife 9.0.0-SNAPSHOT 没有解决?
【发布时间】:2019-02-17 01:03:55
【问题描述】:

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

app:module 依赖

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

【问题讨论】:

    标签: android androidx butterknife


    【解决方案1】:

    更新: 您现在可以简单地使用 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 设置 > 编译器配置:

    【讨论】:

    • 这个解决方案需要在butterknife 9生产时更新。
    【解决方案2】:

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

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

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

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

      • 您好,感谢您的回复。我现在收到此错误。错误:包android.support.annotation不存在错误:找不到符号类UiThread错误:找不到符号类CallSuper
      • @Ismail 使用 :butterknife:8.8.1 ?
      • 是的。生成的 ViewBinding 类不断从 android 包而不是 androidx 包导入注解
      【解决方案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
      }
      

      【讨论】:

        【解决方案5】:

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

        【讨论】:

          【解决方案6】:

          还添加了对 Java 1_8 的支持 build.gradleandroid 部分

          compileOptions {
              sourceCompatibility JavaVersion.VERSION_1_8
              targetCompatibility JavaVersion.VERSION_1_8
          }
          

          【讨论】:

            【解决方案7】:

            按照最新版本here 100% 为我工作的 GitHub 存储库的说明:

            【讨论】:

              【解决方案8】:
              implementation 'com.jakewharton:butterknife:8.8.1'
              annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
              

              它在 androidx 中工作

              【讨论】:

                猜你喜欢
                • 2015-07-18
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2018-03-28
                • 1970-01-01
                • 2016-09-15
                • 2017-03-04
                • 2015-05-31
                相关资源
                最近更新 更多