4

我正在使用 Android Studio 1.0.0。我正在尝试添加黄油刀的依赖项。

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.jakewharton:butterknife:6.0.0'
compile 'com.google.android.gms:play-services:6.1.11'
compile 'com.android.support:recyclerview-v7:21.0.2'
}

但我收到以下 Gradle 错误:

错误:找不到:com.jakewharton:butterknife:6.0.0

4

4 回答 4

4

我有同样的问题!最后,当我尝试清理项目时,我得到了更具体的 gradle 错误:No cached version of com.jakewharton:butterknife:6.0.0 available for offline mode。所以问题是启用了gradle离线模式!您需要做的就是取消选中Settings -> Gradle -> Offline work ...

于 2014-12-30T21:35:58.820 回答
1

我补充说,在三行以下,它得到了修复。感谢大家。

repositories {
     mavenCentral()
}
于 2015-01-15T13:54:21.807 回答
0

我试过我的build.gradle,它有效。

build.gradle。您可以尝试将repositories { mavenCentral() }其放在构建脚本之外,然后它会起作用。

编辑

应用程序中的 build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.2'
    compile 'com.jakewharton:butterknife:6.0.0'
}

根目录下的 build.gradle

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

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0-rc4'

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

allprojects {
    repositories {
        jcenter()
    }
}

设置.gradle

include ':app'
于 2014-12-15T18:38:49.223 回答
0

转到您的项目目录。

./gradlew clean

这下载了依赖项并解决了“找不到:”依赖项问题

于 2015-01-11T17:34:19.920 回答