【问题标题】:Gradle could not resolve otto libraryGradle 无法解析 otto 库
【发布时间】:2013-12-30 15:37:17
【问题描述】:

我尝试嵌入 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),但没有帮助。

【问题讨论】:

    标签: android dependencies repository gradle maven-central


    【解决方案1】:

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

    repositories {
        mavenCentral()
    }
    

    请注意,buildscript { ... } 中现有的repositories { ... } 仅用于配置构建类路径本身的存储库,而不是您的项目,因此将这个新元素放在apply plugin ... 下方

    【讨论】:

      【解决方案2】:

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

      希望这会有所帮助。

      【讨论】:

      • 我不使用 Intellij(AndroidStudio) 或 Eclipse。
      • 对不起,我的错误。我假设你这样做了,因为它看起来很像我在 IntelliJ 中看到的错误消息,还试图让 Gradle 依赖项正常工作。因此,如果您不使用 Android Studio 或 Eclipse,我假设您正在从命令行编译等?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-08
      • 1970-01-01
      相关资源
      最近更新 更多