Android 在 gradle 中添加库

Android add library in gradle

注意:我的项目是eclipse,用gradle

迁移到android studio

我尝试使用 this 库,我按照他们在 link 中建议的方式添加了以下代码:

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 分钟,最后给了我一个错误:

unable to resolve 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')
    }
}

感谢您的宝贵时间。

jcenter 中不存在此工件。

com.marshalchen.ultimaterecyclerview

您可以签到:https://bintray.com/bintray/jcenter

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

repositories {
        mavenCentral()
}

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

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