1
votes

I have encountered this issue multiple time whenever I setup a new project or degraded the targetSdkVersion in Android Studio.

Gradle build system start complaining about dependencies "Failed to resolve: com.android.support:recyclerview-v7:21.1.2" or something else. 

My question here is:

Is there any relation between version of gradle dependencies and targetSdkVersion/compileSdkVersion/buildToolsVersion? If yes then how it is calculated and how do I configure and figure out correct dependencies without googling every time?

In my current project my build.gradle file

apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"



defaultConfig {
    applicationId "com.mukesh.manageinvestment"
    minSdkVersion 8
    targetSdkVersion 23
    versionCode 1
    versionName "1.0.0"
}

def siteURL = '"'+WebsiteURL+'"'
def gameURL = '"'+GamesURL+'"'

signingConfigs{
    debug{

    }

    release{

    }
}

buildTypes {
    debug{
        minifyEnabled false
        buildConfigField "String", "BaseURL", siteURL
        buildConfigField "String", "GameURL", gameURL
        signingConfig signingConfigs.release
    }

    release {
        minifyEnabled true
        buildConfigField "String", "BaseURL", siteURL
        buildConfigField "String", "GameURL", gameURL
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
    }
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.squareup.picasso:picasso:2.4.0'
}

I have changed targetSdkVersion 23 to 21 and my current build.gradle is looking like this

apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"



defaultConfig {
    applicationId "com.devendraprasad.manageinvestment"
    minSdkVersion 8
    targetSdkVersion 21
    versionCode 1
    versionName "1.0.0"
}

def siteURL = '"'+WebsiteURL+'"'
def gameURL = '"'+GamesURL+'"'

signingConfigs{
    debug{

    }

    release{

    }
}

buildTypes {
    debug{
        minifyEnabled false
        buildConfigField "String", "BaseURL", siteURL
        buildConfigField "String", "GameURL", gameURL
        signingConfig signingConfigs.release
    }

    release {
        minifyEnabled true
        buildConfigField "String", "BaseURL", siteURL
        buildConfigField "String", "GameURL", gameURL
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
    }
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:21.1.2'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.android.support:recyclerview-v7:21.1.2'
compile 'com.squareup.picasso:picasso:2.4.0'
}

Every thing looks good dependencies version is matching with targetSdkVersion and buildToolsVersion but application is still not compiling. It gives this error

Information:Gradle tasks [:app:assembleDebug]

Error:A problem occurred configuring project ':app'.

Could not resolve all dependencies for configuration ':app:_debugCompile'. Could not find com.android.support:appcompat-v7:21.1.2. Searched in the following locations: file:/C:/Program Files/Android/Android Studio1/gradle/m2repository/com/android/support/appcompat-v7/21.1.2/appcompat-v7-21.1.2.pom file:/C:/Program Files/Android/Android Studio1/gradle/m2repository/com/android/support/appcompat-v7/21.1.2/appcompat-v7-21.1.2.jar https://jcenter.bintray.com/com/android/support/appcompat-v7/21.1.2/appcompat-v7-21.1.2.pom https://jcenter.bintray.com/com/android/support/appcompat-v7/21.1.2/appcompat-v7-21.1.2.jar file:/F:/Software/android-sdk-windows/extras/android/m2repository/com/android/support/appcompat-v7/21.1.2/appcompat-v7-21.1.2.pom file:/F:/Software/android-sdk-windows/extras/android/m2repository/com/android/support/appcompat-v7/21.1.2/appcompat-v7-21.1.2.jar file:/F:/Software/android-sdk-windows/extras/google/m2repository/com/android/support/appcompat-v7/21.1.2/appcompat-v7-21.1.2.pom file:/F:/Software/android-sdk-windows/extras/google/m2repository/com/android/support/appcompat-v7/21.1.2/appcompat-v7-21.1.2.jar Required by: ManageInvestment:app:unspecified Could not find com.android.support:recyclerview-v7:21.1.2. Searched in the following locations: file:/C:/Program Files/Android/Android Studio1/gradle/m2repository/com/android/support/recyclerview-v7/21.1.2/recyclerview-v7-21.1.2.pom file:/C:/Program Files/Android/Android Studio1/gradle/m2repository/com/android/support/recyclerview-v7/21.1.2/recyclerview-v7-21.1.2.jar https://jcenter.bintray.com/com/android/support/recyclerview-v7/21.1.2/recyclerview-v7-21.1.2.pom https://jcenter.bintray.com/com/android/support/recyclerview-v7/21.1.2/recyclerview-v7-21.1.2.jar file:/F:/Software/android-sdk-windows/extras/android/m2repository/com/android/support/recyclerview-v7/21.1.2/recyclerview-v7-21.1.2.pom file:/F:/Software/android-sdk-windows/extras/android/m2repository/com/android/support/recyclerview-v7/21.1.2/recyclerview-v7-21.1.2.jar file:/F:/Software/android-sdk-windows/extras/google/m2repository/com/android/support/recyclerview-v7/21.1.2/recyclerview-v7-21.1.2.pom file:/F:/Software/android-sdk-windows/extras/google/m2repository/com/android/support/recyclerview-v7/21.1.2/recyclerview-v7-21.1.2.jar Required by: ManageInvestment:app:unspecified Information:BUILD FAILED Information:Total time: 7.733 secs Information:1 error Information:0 warnings Information:See complete output in console

PS: attached is my sdk manager screenshot

enter image description here

1

1 Answers

1
votes

It happens since the support libraries with 21.1.2 don't exist.

Use one of these:

21.0.0
21.0.2
21.0.3
22.0.0
22.1.0
22.1.1
22.2.0
22.2.1
23.0.0
23.0.1
23.1.0
23.1.1
23.2.0
23.3.0
23.4.0
24.0.0
24.1.0
24.1.1
24.2.0
24.2.1

Is there any relation between version of gradle dependencies and targetSdkVersion/compileSdkVersion/buildToolsVersion? If yes then how it is calculated and how do I configure and figure out correct dependencies without googling every time?

There is a relation between the compileSdkVersion and the major version of the support libraries.

Use compileSdkVersion=21 with support libraries v21.
Use compileSdkVersion=22 with support libraries v22.
Use compileSdkVersion=23 with support libraries v23.
Use compileSdkVersion=24 with support libraries v24.

In general a new version of the Support Library is released alongside a new platform version, providing compatibility shims to newly added APIs as well as new features.