简体   繁体   English

gradle无法解决Android项目的依赖关系

[英]gradle cannot resolve dependencies for android project

The Problem is that gradle cant find the jars for the dependencies, but gradle is looking on the wrong place. 问题是gradle无法找到依赖项的jar,但是gradle在错误的位置上查找。 Gradle keeps searching for the files in the wrong directory ( the directory where the Google & Android support libary resides.... Gradle会继续在错误的目录(Google和Android支持库所在的目录下)中搜索文件。

Searched in the following locations: file:/D:/Programme/androis-sdks/extras/android/m2repository/org/springframework/android/spring-android-rest-template/1.0.1.RELEASE/spring-android-rest-template-1.0.1.RELEASE.pom file:/D:/Programme/androis-sdks/extras/android/m2repository/org/springframework/android/spring-android-rest-template/1.0.1.RELEASE/spring-android-rest-template-1.0.1.RELEASE.jar file:/D:/Programme/androis-sdks/extras/google/m2repository/org/springframework/android/spring-android-rest-template/1.0.1.RELEASE/spring-android-rest-template-1.0.1.RELEASE.pom file:/D:/Programme/androis-sdks/extras/google/m2repository/org/springframework/android/spring-android-rest-template/1.0.1.RELEASE/spring-android-rest-template-1.0.1.RELEASE.jar Required by: 在以下位置搜索:文件:/ D:/Programme/androis-sdks/extras/android/m2repository/org/springframework/android/spring-android-rest-template/1.0.1.RELEASE/spring-android-rest- template-1.0.1.RELEASE.pom文件:/ D:/Programme/androis-sdks/extras/android/m2repository/org/springframework/android/spring-android-rest-template/1.0.1.RELEASE/spring-android -rest-template-1.0.1.RELEASE.jar文件:/ D:/Programme/androis-sdks/extras/google/m2repository/org/springframework/android/spring-android-rest-template/1.0.1.RELEASE/ spring-android-rest-template-1.0.1.RELEASE.pom文件:/ D:/Programme/androis-sdks/extras/google/m2repository/org/springframework/android/spring-android-rest-template/1.0.1 .RELEASE / spring-android-rest-template-1.0.1.RELEASE.jar需由:

Shouldn't gradle look in the local Maven Repository or try to download it from jcenter or mavencentral ? 不应该在本地Maven存储库中查找或尝试从jcenter或mavencentral下载它吗?

"~/.m2/repository/org/springframework/android/spring-android-rest-template/1.0.1.RELEASE/spring-android-rest-template-1.0.1.RELEASE.jar " “〜/ .m2 / repository / org / springframework / android / spring-android-rest-template / 1.0.1.RELEASE / spring-android-rest-template-1.0.1.RELEASE.jar”

I've already tried to empty the gradle caches and also tried different repositories - but no success so far! 我已经尝试清空gradle缓存,还尝试了其他存储库-但到目前为止没有成功!

Thanks for your help! 谢谢你的帮助!

Error Message 错误信息

 D:\Progs\JAVA\jdk1.7.0_80\bin\java -Dgradle.home=D:\Progs\gradle-2.4
        -Dtools.jar=D:\Progs\JAVA\jdk1.7.0_80\lib\tools.jar -Didea.launcher.port=7540 "-Didea.launcher.bin.path=D:\Progs\JetBrains\IntelliJ IDEA 15.0.3\bin"
        -Dfile.encoding=UTF-8 -classpath "D:\Progs\gradle-2.4\lib\groovy-all-2.3.10.jar;D:\Progs\gradle-2.4\lib\ant-1.9.4.jar;D:\Progs\gradle-2.4\lib\ant-launcher-1.9.4.jar;D:\Progs\gradle-2.4\lib\gradle-base-services-2.4.jar;D:\Progs\gradle-2.4\lib\gradle-base-services-groovy-2.4.jar;D:\Progs\gradle-2.4\lib\gradle-cli-2.4.jar;D:\Progs\gradle-2.4\lib\gradle-core-2.4.jar;D:\Progs\gradle-2.4\lib\gradle-docs-2.4.jar;D:\Progs\gradle-2.4\lib\gradle-launcher-2.4.jar;D:\Progs\gradle-2.4\lib\gradle-messaging-2.4.jar;D:\Progs\gradle-2.4\lib\gradle-model-core-2.4.jar;D:\Progs\gradle-2.4\lib\gradle-model-groovy-2.4.jar;D:\Progs\gradle-2.4\lib\gradle-native-2.4.jar;D:\Progs\gradle-2.4\lib\gradle-open-api-2.4.jar;D:\Progs\gradle-2.4\lib\gradle-resources-2.4.jar;D:\Progs\gradle-2.4\lib\gradle-tooling-api-2.4.jar;D:\Progs\gradle-2.4\lib\gradle-ui-2.4.jar;D:\Progs\gradle-2.4\lib\gradle-wrapper-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-announce-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-antlr-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-build-comparison-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-build-init-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-code-quality-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-dependency-management-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-diagnostics-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-ear-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-ide-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-ide-native-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-ivy-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-jacoco-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-javascript-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-jetty-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-language-groovy-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-language-java-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-language-jvm-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-language-native-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-language-scala-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-maven-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-osgi-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-platform-base-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-platform-jvm-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-platform-native-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-platform-play-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-plugin-development-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-plugin-use-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-plugins-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-publish-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-reporting-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-resources-http-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-resources-s3-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-resources-sftp-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-scala-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-signing-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-sonar-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-testing-native-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\gradle-tooling-api-builders-2.4.jar;D:\Progs\gradle-2.4\lib\plugins\ivy-2.2.0.jar;D:\Progs\JetBrains\IntelliJ IDEA 15.0.3\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.gradle.launcher.GradleMain --build-file C:\Users\pk\Documents\IntelliJProjetcs2\app\build.gradle



        FAILURE: Build failed with an exception.

        * What went wrong: A problem occurred configuring root project 'app'.
        > Could not resolve all dependencies for configuration ':_debugCompile'.
           > Could not find org.springframework.android:spring-android-rest-template:1.0.1.RELEASE.
             Searched in the following locations:
                 file:/D:/Programme/androis-sdks/extras/android/m2repository/org/springframework/android/spring-android-rest-template/1.0.1.RELEASE/spring-android-rest-template-1.0.1.RELEASE.pom
                 file:/D:/Programme/androis-sdks/extras/android/m2repository/org/springframework/android/spring-android-rest-template/1.0.1.RELEASE/spring-android-rest-template-1.0.1.RELEASE.jar
                 file:/D:/Programme/androis-sdks/extras/google/m2repository/org/springframework/android/spring-android-rest-template/1.0.1.RELEASE/spring-android-rest-template-1.0.1.RELEASE.pom
                 file:/D:/Programme/androis-sdks/extras/google/m2repository/org/springframework/android/spring-android-rest-template/1.0.1.RELEASE/spring-android-rest-template-1.0.1.RELEASE.jar
             Required by:
                 :app:unspecified
           > Could not find any matches for org.springframework.android:spring-android-auth:1.+ as no versions of org.springframework.android:spring-android-auth are available.
             Searched in the following locations:
                 file:/D:/Programme/androis-sdks/extras/android/m2repository/org/springframework/android/spring-android-auth/maven-metadata.xml
                 file:/D:/Programme/androis-sdks/extras/android/m2repository/org/springframework/android/spring-android-auth/
                 file:/D:/Programme/androis-sdks/extras/google/m2repository/org/springframework/android/spring-android-auth/maven-metadata.xml
                 file:/D:/Programme/androis-sdks/extras/google/m2repository/org/springframework/android/spring-android-auth/
             Required by:
                 :app:unspecified
           > Could not find any matches for org.springframework.android:spring-android-core:1.+ as no versions of org.springframework.android:spring-android-core are available.
             Searched in the following locations:
                 file:/D:/Programme/androis-sdks/extras/android/m2repository/org/springframework/android/spring-android-core/maven-metadata.xml
                 file:/D:/Programme/androis-sdks/extras/android/m2repository/org/springframework/android/spring-android-core/
                 file:/D:/Programme/androis-sdks/extras/google/m2repository/org/springframework/android/spring-android-core/maven-metadata.xml
                 file:/D:/Programme/androis-sdks/extras/google/m2repository/org/springframework/android/spring-android-core/
             Required by:
                 :app:unspecified
           > Could not find com.google.code.gson:gson:2.5.
             Searched in the following locations:
                 file:/D:/Programme/androis-sdks/extras/android/m2repository/com/google/code/gson/gson/2.5/gson-2.5.pom
                 file:/D:/Programme/androis-sdks/extras/android/m2repository/com/google/code/gson/gson/2.5/gson-2.5.jar
                 file:/D:/Programme/androis-sdks/extras/google/m2repository/com/google/code/gson/gson/2.5/gson-2.5.pom
                 file:/D:/Programme/androis-sdks/extras/google/m2repository/com/google/code/gson/gson/2.5/gson-2.5.jar
             Required by:
                 :app:unspecified
           > Could not find com.fasterxml.jackson.core:jackson-databind:2.5.
             Searched in the following locations:
                 file:/D:/Programme/androis-sdks/extras/android/m2repository/com/fasterxml/jackson/core/jackson-databind/2.5/jackson-databind-2.5.pom
                 file:/D:/Programme/androis-sdks/extras/android/m2repository/com/fasterxml/jackson/core/jackson-databind/2.5/jackson-databind-2.5.jar
                 file:/D:/Programme/androis-sdks/extras/google/m2repository/com/fasterxml/jackson/core/jackson-databind/2.5/jackson-databind-2.5.pom
                 file:/D:/Programme/androis-sdks/extras/google/m2repository/com/fasterxml/jackson/core/jackson-databind/2.5/jackson-databind-2.5.jar
             Required by:
                 :app:unspecified
           > Could not find javax.persistence:persistence-api:1.0.1.
             Searched in the following locations:
                 file:/D:/Programme/androis-sdks/extras/android/m2repository/javax/persistence/persistence-api/1.0.1/persistence-api-1.0.1.pom
                 file:/D:/Programme/androis-sdks/extras/android/m2repository/javax/persistence/persistence-api/1.0.1/persistence-api-1.0.1.jar
                 file:/D:/Programme/androis-sdks/extras/google/m2repository/javax/persistence/persistence-api/1.0.1/persistence-api-1.0.1.pom
                 file:/D:/Programme/androis-sdks/extras/google/m2repository/javax/persistence/persistence-api/1.0.1/persistence-api-1.0.1.jar
             Required by:
                 :app:unspecified

        * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

        BUILD FAILED

        Total time: 5.085 secs

        Process finished with exit code 1

my Gradle build script: 我的Gradle构建脚本:

buildscript {
    repositories {
   //     def androidHome = System.getenv("ANDROID_HOME")
   //     def userProfile = System.getenv("USERPROFILE")
        //maven { url "$androidHome/extras/android/m2repository/" }
        //maven { url "$androidHome/extras/google/m2repository/"}
      //  maven { url "$userProfile/.m2/repository/"}
        jcenter()
       mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
    }
}
apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }

    defaultConfig {
        applicationId "com.pekam"
        minSdkVersion 17
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
    compile('org.springframework.android:spring-android-auth:1.+') {
        exclude group: 'org.springframework', module: 'spring-core'
    }
    compile('org.springframework.android:spring-android-core:1.+') {
        exclude group: 'org.springframework', module: 'spring-core'
    }
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.google.android.gms:play-services:8.4.0'
    compile 'com.google.code.gson:gson:2.5'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.5'
    compile files('libs/slf4j-android-1.6.1-RC1.jar')
    compile 'javax.persistence:persistence-api:1.0.1'
    compile files('libs/ent.jar')
}

EDIT: 编辑:

below are the libaries that cannot be resolved by gradle, if i remove them from my gradle.build the project compiles fine. 下面是不能由gradle解析的库,如果我从gradle中删除它们的话。build项目可以正常编译。 ... the others libaries (Appcombat & GooglePlay ) compile just fine..... ...其他库(Appcombat和GooglePlay)都可以编译。

I use IntelliJ 15.0.3 and gradle 2.4 我使用IntelliJ 15.0.3和gradle 2.4

> compile
> ('org.springframework.android:spring-android-rest-template:1.0.1.RELEASE')
>     compile ('org.springframework.android:spring-android-auth:1.+') {
>         exclude group: 'org.springframework', module: 'spring-core'
>     }
>     compile ('org.springframework.android:spring-android-core:1.+') {
>         exclude group: 'org.springframework', module: 'spring-core'
>     }
> 
> 
>     compile 'com.google.code.gson:gson:2.5'
>     compile 'com.fasterxml.jackson.core:jackson-databind:2.5'
> 
>     compile 'javax.persistence:persistence-api:1.0.1'

Screenshot of Libaries in IntelliJ show no errors- IntelliJ中的库屏幕快照未显示任何错误-

在此处输入图片说明

From the Android SDK Manager tool, you need to install the " Android Support Repository " and " Google Repository " from " Extras ". 从Android SDK Manager工具中,您需要从“ Extras ”安装“ Android Support Repository ”和“ Google Repository ”。 These install special local Maven repositories (not located at ~/.m2/ but inside your SDK installation) that should make your dependencies resolve fine. 这些将安装特殊的本地Maven存储库(不在SDK目录中,位于~/.m2/但应位于您的SDK的内部),可以使依赖项很好地解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM