如何修复“Failed to resolve: support-compat”问题

4

为什么不帮助我?

在我的应用程序中,我想使用ButterKnife库,我添加了这个库的依赖项。但是当我添加这个库并点击同步按钮时,项目没有同步,会显示错误。

gradle.Build (project) :

buildscript {

    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

gradle.build (app) :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.mohammad.ncistutorial"
        minSdkVersion 14
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    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'
    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}

错误信息:

Failed to resolve: support-compat

我该如何解决这个问题?

1
你的 Gradle 文件在我的演示项目中可以工作。请检查你是否连接到互联网,尝试清理/构建项目并运行。 - Kruti Parekh
我建议不要使用ButterKnife,而是使用Android数据绑定。 - mallaudin
3个回答

7
请尝试添加依赖行,并排除支持App Compact的组件。
implementation 'com.jakewharton:butterknife:8.8.1',{
        exclude group: 'com.android.support'
    })

1
谢谢,为我工作。但是为什么显示这个错误?为什么你添加了排除组:'com.android.support' 并修复它?这是什么?谢谢。 - WoW.j
1
你能告诉我更多的信息和描述吗? - WoW.j
3
我遇到了一些库的相同问题。这是因为我们的buildToolsVersion与它们的库不兼容。库已经更新了他们的buildToolsVersion而我们没有。这就是我认为问题所在的原因。具体的原因我也不知道。 - Grishma Ukani

0

检查你的 .gradle 文件版本。更新或更改为最新的 gradle 版本。


0
请使用以下代码。
   implementation 'com.jakewharton:butterknife:9.0.0-rc2',{
        exclude group: 'com.android.support'
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接