简体   繁体   中英

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 keeps searching for the files in the wrong directory ( the directory where the Google & Android support libary resides....

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:

Shouldn't gradle look in the local Maven Repository or try to download it from jcenter or mavencentral ?

"~/.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!

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:

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. ... the others libaries (Appcombat & GooglePlay ) compile just fine.....

I use IntelliJ 15.0.3 and 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-

在此处输入图片说明

From the Android SDK Manager tool, you need to install the " Android Support Repository " and " Google Repository " from " Extras ". These install special local Maven repositories (not located at ~/.m2/ but inside your SDK installation) that should make your dependencies resolve fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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