Android在gradle中添加库

时间:2015-09-18 09:50:05

标签: android android-studio gradle android-recyclerview build.gradle

注意:我的项目是eclipse,使用gradle迁移到android studio

我尝试使用this库,我在链接中添加了以下代码:

repositories {
        jcenter()
    }

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':Library-PullToRefresh')
    compile project(':google-play-services_lib')
    compile project(':Library-UniversalImageLoader')
    compile 'com.android.support:support-v4:19.0.+'
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.android.support:cardview-v7:22.0.0'
    compile 'com.android.support:recyclerview-v7:22.0.0'
    compile 'com.marshalchen.ultimaterecyclerview:library:0.3.17' //here
}

之后,我尝试同步gradle。这需要将近30分钟,最后给了我一个错误:

  

无法解析com.marshalchen.ultimaterecyclerview:library:0.3.17

我该怎么办?

这是我的gradle文件的其余部分,它是标准文件:

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

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

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

感谢您的时间。

1 个答案:

答案 0 :(得分:4)

此工件在jcenter中不存在。

com.marshalchen.ultimaterecyclerview

您可以登记:https://bintray.com/bintray/jcenter

您可以尝试使用maven central而不是jcenter。

repositories {
        mavenCentral()
}

dependencies{
   compile 'com.marshalchen.ultimaterecyclerview:library:0.3.11
}

您可以查看已发布的版本here