Android 在 gradle 中添加库

发布时间: 2016/6/26 8:54:13
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

注意 ︰ 我的项目是 eclipse,迁移到 android 与 gradle studio

我试图使用库,像他们建议链接中添加以下代码 ︰

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')
    }
}

谢谢你 time

解决方法 1:

这个工件不存在的 jcenter。

com.marshalchen.ultimaterecyclerview

您可以签入 ︰ https://bintray.com/bintray/jcenter

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

repositories {
        mavenCentral()
}

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

您可以检查版本已发布在这里

官方微信
官方QQ群
31647020