Gradle无法解析otto库

时间:2013-12-12 09:43:52

标签: android dependencies repository gradle maven-central

我尝试嵌入Otto库,which exists at the Maven Central

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.3'

    }
}

apply plugin: 'android'

dependencies {
    compile 'com.google.android.gms:play-services:4.0.30'
    compile 'com.android.support:support-v13:19.0.0'
    compile 'com.squareup:otto:1.3.4'
}

但我得到了例外:

A problem occurred configuring root project 'sample-project'.
> Failed to notify project evaluation listener.
   > Could not resolve all dependencies for configuration ':_DebugCompile'.
      > Could not find com.squareup:otto:otto:1.3.4.
        Required by:
            :sample-project:unspecified

我尝试刷新依赖项(gradle --refresh-dependencies),但它没有帮助。

2 个答案:

答案 0 :(得分:10)

你需要告诉gradle在哪里找到它。

repositories {
    mavenCentral()
}

请注意,repositories { ... }内的buildscript { ... }只是为构建类路径本身而不是项目配置存储库,因此将此新元素放在apply plugin ...

下面

答案 1 :(得分:1)

我相信你所遗忘的是Tools->Android->Sync Project with Gradle Files。我在上面测试了你的代码,它对我来说效果很好。

希望这有帮助。