Android / gradle:无法使用存储库

时间:2014-04-07 12:09:00

标签: java android maven gradle

我试图删除我的jar *库并将它们添加为maven-repository-dependencies。它看起来很有希望,但我无法做到。我用一个库(gson)测试了它,现在我的gradle.build看起来像这样:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.google.code.gson:gson:2.2.4'
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.1.0"

    defaultConfig {
    minSdkVersion 10
    targetSdkVersion 18
}

sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        instrumentTest.setRoot('tests')
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

但是一个简单的sudo gradle build会返回以下错误:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> Failed to notify project evaluation listener.
   > Could not resolve all dependencies for configuration ':_DebugCompile'.
      > Could not find com.google.code.gson:gson:2.2.4.
        Required by:
            :android:unspecified

* Try:
Run with --stacktrace option to get the stack trace. Run with 
--info or --debug option to get more log output.

BUILD FAILED

Total time: 3.541 secs

我已连接到互联网,我正在使用ubuntu。

1 个答案:

答案 0 :(得分:14)

尝试添加:

repositories {
    mavenCentral()
}

apply plugin: 'android'处于同一级别。