添加黄油刀库时,清单合并失败

时间:2019-02-05 14:01:52

标签: android xml build.gradle butterknife android-gradle-3.0

dependencies {
    implementation 'com.jakewharton:butterknife:10.0.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

}

这些是build.gradle中的依赖项

  

清单合并失败:属性application @ appComponentFactory   值=(android.support.v4.app.CoreComponentFactory)来自   [com.android.support:support-compat:28.0.0]   AndroidManifest.xml:22:18-91也位于   [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86   值=(androidx.core.app.CoreComponentFactory)。意见建议:添加   'tools:replace =“ android:appComponentFactory”'转换为元素   在AndroidManifest.xml:7:5-21:19进行覆盖。

我希望将一个库添加到我的项目中,该库称为Butterknife库,在添加该库之前,该项目很好,但是随着我添加该库。清单合并失败发生错误。

我尝试了什么? 我将这些行添加到了AndroidManifest.xml:

tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"

但这会产生另一组错误

  

原因:com.android.tools.r8.utils.AbortException:错误:静态   仅从Android N开始支持接口方法   (--min-api 24):void butterknife.Unbinder.lambda $ static $ 0()

我尝试删除黄油刀库,然后构建良好。

我还尝试仅添加其中一行:

tools:replace="android:appComponentFactory"

这什么都不做,又产生了另一个错误:

  

清单合并失败,并出现多个错误,请参阅日志

我尝试了Refractor->迁移到androidx, 这在Java文件中造成了一个新问题,该文件现在说“无法解析符号R”

那我该怎么办,我正在网上学习一些应用开发课程。而且教这门课程的人似乎没有这些错误。

3 个答案:

答案 0 :(得分:2)

com.jakewharton:butterknife:10.0.0使用的是AndroidX。选中here

但是您还依赖com.android.support:appcompat-v7:28.0.0

您不应将AndroidX与非AndroidX的依赖关系混在一起。

您有两个选择:

  1. 为Butterknife使用较低版本。
  2. 迁移到AndroidX。

要迁移到AndroidX:

使用androidx.appcompat:appcompat:1.0.0代替com.android.support:appcompat-v7:28.0.0

将以下内容添加到您的gradle.properties

android.useAndroidX=true
android.enableJetifier=true

查看迁移指南here

答案 1 :(得分:1)

问题

我认为当前版本(最新)的黄油刀有问题。我针对此问题找到的最简单的解决方案是更改黄油刀适用的版本。

一种可能的解决方案

我改变了

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

对此

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

为什么这样做?

我们所做的是,我们现在将使用较旧的黄油刀版本,该版本适用。

答案 2 :(得分:0)

当我尝试将黄油刀应用于现有应用程序中的一个时,我遇到了同样的问题。

gradle文件上没有任何AndroidX实现的应用程序

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

这可以正常工作。

由于最新版的Butterknife使用AndroidX,因此您的项目也应迁移到AndroidX,如果要在现有项目上进行,这似乎是额外的工作。 如果新项目具有AndroidX实现,则可以转到最新版本:

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

如果您愿意将旧的应用程序迁移到AndroidX,请进行link