2013-12-12 65 views
3

我尝试嵌入Otto库,which exists at the Maven CentralGradle无法解析otto库

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),但它并不能帮助。

回答

10

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

repositories { 
    mavenCentral() 
} 

注意里面buildscript { ... }现有repositories { ... }仅仅是配置构建类路径本身的存储库,而不是你的项目,所以就把这个新元素略低于apply plugin ...

1

我相信你错过的是Tools->Android->Sync Project with Gradle Files。我测试了你的代码,它对我来说工作得很好。

希望这会有所帮助。

+0

我不使用的IntelliJ(AndroidStudio)或Eclipse。 – eleven

+0

对不起,我的错。我认为你做了,因为它看起来很像我在IntelliJ中看到的错误消息,也试图让Gradle依赖项正常工作。所以,如果你不使用Android Studio或Eclipse,我假设你正在编译等命令行? – Grimeh

相关问题