Android Gradle依赖解析顺序

时间:2014-10-20 20:04:24

标签: android maven gradle android-gradle

我的app模块的build.gradle文件中有一个远程maven存储库。当我从命令行运行assembleDebug -info时,我可以看到gradle正在尝试通过在我的远程maven仓库中查找它们来解析支持库依赖项,并且我收到此错误:

    Resource missing. [HTTP GET: https://raw.githubusercontent.com/me/releases-android/master/releases/com/android/support/appcompat-v7/maven-metadata.xml]
Failed to get resource: GET. [HTTP HTTP/1.1 400 Bad Request: https://raw.githubusercontent.com/me/releases-android/master/releases/com/android/support/appcompat-v7/]
Resource missing. [HTTP GET: https://raw.githubusercontent.com/me/releases-android/master/releases/com/android/support/cardview-v7/maven-metadata.xml]
Failed to get resource: GET. [HTTP HTTP/1.1 400 Bad Request: https://raw.githubusercontent.com/me/releases-android/master/releases/com/android/support/cardview-v7/]
Resource missing. [HTTP GET: https://raw.githubusercontent.com/me/releases-android/master/releases/com/android/support/palette-v7/maven-metadata.xml]
Failed to get resource: GET. [HTTP HTTP/1.1 400 Bad Request: https://raw.githubusercontent.com/me/releases-android/master/releases/com/android/support/palette-v7/]
Resource missing. [HTTP GET: https://raw.githubusercontent.com/me/releases-android/master/releases/com/android/support/recyclerview-v7/maven-metadata.xml]
Failed to get resource: GET. [HTTP HTTP/1.1 400 Bad Request: https://raw.githubusercontent.com/me/releases-android/master/releases/com/android/support/recyclerview-v7/]
Resource missing. [HTTP GET: https://raw.githubusercontent.com/me/releases-android/master/releases/com/google/android/gms/play-services/maven-metadata.xml]
Failed to get resource: GET. [HTTP HTTP/1.1 400 Bad Request: https://raw.githubusercontent.com/me/releases-android/master/releases/com/google/android/gms/play-services/]

问题:有没有办法配置gradle文件停止尝试连接到我的远程maven repo来解决Android特定的依赖项?这是我的build.gradle文件:

apply plugin: 'com.android.application'

    android {
        ...

        dependencies {
            compile fileTree(dir: 'libs', include: ['*.jar'])
            compile 'com.android.support:appcompat-v7:21.0.+'
            compile 'com.android.support:cardview-v7:21.0.+'
            compile 'com.android.support:palette-v7:21.0.+'
            compile 'com.android.support:recyclerview-v7:21.0.+'
            compile 'com.google.android.gms:play-services:6.1.+'
            compile 'com.android.support:support-v4:21.0.0'
            compile 'com.android.support:support-v13:21.0.0'
        }
    }

    repositories {
        //My personal repo
        maven { url 'https://raw.githubusercontent.com/me/releases-android/master/releases/'}
    }

    dependencies {
        //My App's Dependencies here       
    }

2 个答案:

答案 0 :(得分:1)

请勿在版本号中使用+。如果您使用+,那么构建系统需要定期检查是否有更新的版本可用。如果您指定一个没有+的显式版本号,并且该版本已缓存,则永远不必为此命中网络。

它正在查找您的自定义存储库,因为要评估+版本规范,它需要扫描所有存储库以找到具有最新版本的存储库。如果您明确指定版本号,它将按照它们在构建文件中出现的顺序扫描存储库,并在它获得所需内容时停止。

答案 1 :(得分:0)

那是因为您的私人存储库中没有Android支持库。我会将mavenCentral()添加到存储库中,以便Gradle首先尝试通过maven central repo解析依赖关系,然后在中央存储库中找不到依赖关系时通过您的私人存储库。

repositories {
    mavenCentral()
    //My personal repo
    maven { url 'https://raw.githubusercontent.com/me/releases-android/master/releases/'}
}