找不到com.android.support:support-v13:19.0.0

时间:2014-07-10 11:41:05

标签: java android gradle

自上一轮更新以来,我遇到了这个错误。 Gradle绝对拒绝找到v13支持库。我尝试过以下方法:

  • 安装最新的Android支持存储库以及最新的Android支持库
  • 来自here
  • 的前两条建议
  • 在构建脚本中指定最新的gradle(0.12。+)
  • 指定v13库的不同版本

我可以在m2repository文件夹中看到它的罐子。事实上,我可以看到我尝试过的所有替代版本。

这是我的build.gradle:

    buildscript {
        repositories {
            def androidHome = System.getenv("ANDROID_HOME")
            mavenCentral()
            maven {
                url "$androidHome/extras/android/m2repository/"
            }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.12.+'
            classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.9.4'
        }
        ext.compileSdkVersion = 19
        ext.buildToolsVersion = "19.0.3"
        ext.minSdkVersion = 14
        ext.targetSdkVersion = 18
        ext.buildVersion = 8
        ext.codeVersion = 5
    }

    allprojects {
        repositories {
            mavenCentral()
        }
    }

...然后在主项目中:

    apply plugin: 'android'
    apply plugin: 'android-test'

    tasks.withType(Compile) {
        options.encoding = 'UTF-8'
    }

    def getVersionCode = { ->
        return getDate()
    }

    def getDate() {
        def date = new Date()
        return date.getTime().toInteger() + 1000000000
    }

    def getVersionName = { ->
        try {
            def stdout = new ByteArrayOutputStream()
            exec {
                commandLine 'git', 'describe', '--tags', '--dirty'
                standardOutput = stdout
            }
            return stdout.toString().trim()
        }
        catch (ignored) {
            return null;
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: '*.jar')
        compile 'com.android.support:support-v13:19.0.0'
        compile 'com.android.support:support-v4:19.1.0'
        compile 'com.fasterxml.jackson.core:jackson-databind:2.3.0'

        compile project(':lib-volley')
        compile project(':lib-pulltorefresh')
        compile project(':lib-player')

        androidTestCompile 'org.hamcrest:hamcrest-all:1.3'
        androidTestCompile 'org.mockito:mockito-core:1.9.5'
        androidTestCompile 'junit:junit:4.11'
        androidTestCompile('org.robolectric:robolectric:2.3:jar-with-dependencies') {
            exclude module: 'classworlds'
            exclude module: 'maven-artifact'
            exclude module: 'maven-artifact-manager'
            exclude module: 'maven-error-diagnostics'
            exclude module: 'maven-model'
            exclude module: 'maven-plugin-registry'
            exclude module: 'maven-profile'
            exclude module: 'maven-project'
            exclude module: 'maven-settings'
            exclude module: 'nekohtml'
            exclude module: 'plexus-container-default'
            exclude module: 'plexus-interpolation'
            exclude module: 'plexus-utils'
            exclude module: 'wagon-file'
            exclude module: 'wagon-http-lightweight'
            exclude module: 'wagon-http-shared'
            exclude module: 'wagon-provider-api'
        }
        androidTestCompile 'com.squareup:fest-android:1.0.7'

        testCompile 'org.hamcrest:hamcrest-all:1.3'
        testCompile 'org.mockito:mockito-core:1.9.5'
        testCompile 'junit:junit:4.11'
        testCompile('org.robolectric:robolectric:2.3:jar-with-dependencies') {
            exclude module: 'classworlds'
            exclude module: 'maven-artifact'
            exclude module: 'maven-artifact-manager'
            exclude module: 'maven-error-diagnostics'
            exclude module: 'maven-model'
            exclude module: 'maven-plugin-registry'
            exclude module: 'maven-profile'
            exclude module: 'maven-project'
            exclude module: 'maven-settings'
            exclude module: 'nekohtml'
            exclude module: 'plexus-container-default'
            exclude module: 'plexus-interpolation'
            exclude module: 'plexus-utils'
            exclude module: 'wagon-file'
            exclude module: 'wagon-http-lightweight'
            exclude module: 'wagon-http-shared'
            exclude module: 'wagon-provider-api'
        }
        testCompile 'com.squareup:fest-android:1.0.7'
    }

    android {
        compileSdkVersion rootProject.compileSdkVersion
        buildToolsVersion rootProject.buildToolsVersion

        defaultConfig {
            minSdkVersion rootProject.minSdkVersion
            targetSdkVersion rootProject.targetSdkVersion
            versionCode getVersionCode()
            versionName getVersionName()
        }

    ... # signingConfigs and productFlavors removed

        buildTypes {
            debug {
                packageNameSuffix ".debug"
                versionNameSuffix " debug"
                debuggable true
                jniDebugBuild true
            }
            trial {
                packageNameSuffix ".trial"
                versionNameSuffix " trial"
                signingConfig signingConfigs.debug
                debuggable true
                jniDebugBuild true
            }
            release {
                runProguard false
                proguardFile 'proguard-android.txt'
                proguardFile getDefaultProguardFile('proguard-android.txt')
                debuggable false
                jniDebugBuild false
                signingConfig signingConfigs.release
                zipAlign true
            }
        }

        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                res.srcDirs = ['res']
            }
            trial {
                assets.srcDirs = ['assets']
            }
            release {
                assets.srcDirs = ['assets-release']
            }
            debug {
                assets.srcDirs = ['assets']
            }
            androidTest.setRoot('src/test')
        }

        packagingOptions {
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/DEPENDENCIES'
        }

        lintOptions {
            disable 'ValidFragment'
        }
    }

    if (project.hasProperty('keyAlias')) {
        android.signingConfigs.release.keyAlias = keyAlias
    }

    androidTest {
        include '**/*Test.class'
    }

    apply plugin: 'idea'

    idea {
        module {
            testOutputDir = file(rootProject.testOutputDir)
        }
    }

    task copyDependencies(type: Copy) {
        description = 'Copy dependencies to a libraries folder. Useful for Eclipse'
        ext.libDir = new File(project.projectDir, '/libraries')
        println libDir
        ext.srclibDir = new File(project.projectDir, '/libs')
        println srclibDir
        println 'Adding dependencies from lib directory'
        copy
        {
            from srclibDir
            into libDir
        }
        println 'Adding dependencies from compile configuration'
        for (file in configurations.compile) {
            copy
                    {
                        from file
                        into libDir
                    }
        }
        println 'Adding dependencies from releaseCompile configuration'
        for (file in configurations.releaseCompile) {
            copy
                    {
                        from file
                        into libDir
                    }
        }
        println 'Adding dependencies from debugCompile configuration'
        for (file in configurations.debugCompile) {
            copy
                    {
                        from file
                        into libDir
                    }
        }

        println 'Adding dependencies from androidTestCompile configuration'
        for (file in configurations.androidTestCompile) {
            copy
                    {
                        from file
                        into libDir
                    }
        }
    }

如何让Gradle看到v13库的任何想法都将不胜感激。

1 个答案:

答案 0 :(得分:2)

解决了它。

错误发生在for循环开始时的copyDependencies任务中。似乎gradle不会使用sdk / extras / m2repository来解决依赖关系。以下应该有效...

repositories {
     def androidHome = System.getenv("ANDROID_HOME")
     mavenCentral()
     maven {
         url "$androidHome/extras/android/m2repository/"
     }
}

......但没有。我认为gradle没有拿起ANDROID_HOME存在问题。最后,我将整个android / m2repository复制到.m2 / repository中,然后在父构建脚本中使用mavenLocal(),而不是尝试访问sdk存储库。

另一种方法可能是将exclude module: 'support-v13'添加到robolectric依赖项排除项目中,但项目需要在其他地方使用它。