3

I recently changed my mindSdkVersion to 17 and targetSdkVersion to 21, and got lots of errors. I fixed some of them, but I can't fix this one:

Error:(28, 13) Failed to resolve: com.android.support:appcompat-v7:21.0.1

I'm using Android Studio on Mac and I have Android Support repositories.

My build.gradle file:

apply plugin: 'com.android.application'


android {
    compileSdkVersion 21
    buildToolsVersion "24.0.3"
    defaultConfig {
        applicationId "com.swit.sedamaker"
        minSdkVersion 17
        targetSdkVersion 21
        versionCode 2
        versionName "1.01"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {

    compile 'com.android.support:appcompat-v7:21.0.1'

    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    testCompile 'junit:junit:4.12'
}
Amir Amini
  • 51
  • 1
  • 1
  • 7

3 Answers3

1

The error occur because 21.0.1 for support libraries doesn't exist.

dependencies{

//it requires compileSdkVersion 21
  compile 'com.android.support:appcompat-v7:21.0.3'
  compile 'com.android.support:appcompat-v7:21.0.2'
  compile 'com.android.support:appcompat-v7:21.0.0'

}
vinod
  • 1,126
  • 13
  • 18
1

You're better to match the API version for compileSdkVersion, buildToolsVersion, targetSdkVersion. Try to use the latest SDK

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.3"
    defaultConfig {
        ...
        minSdkVersion 17
        targetSdkVersion 24
        ...
    }
    ...
}

dependencies {

    compile 'com.android.support:appcompat-v7:24.2.0'
    ...
}

Of course you can set targetSdkVersion to 21 if you want. targetSdkVersion is used to inform the system that you have test the app against the target version like the documentation said.

android:targetSdkVersion

An integer designating the API Level that the application targets. If not set, the default value equals that given to minSdkVersion. This attribute informs the system that you have tested against the target version and the system should not enable any compatibility behaviors to maintain your app's forward-compatibility with the target version. The application is still able to run on older versions (down to minSdkVersion).

Read more at What is the difference between compileSdkVersion and targetSdkVersion? forcompileSdkVersion and targetSdkVersion.

Community
  • 1
  • 1
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
0

Try Replace with:

implementation 'com.android.support:appcompat-v7:23.3.0'
Syed Md. Kamruzzaman
  • 979
  • 1
  • 12
  • 33
W4R10CK
  • 5,502
  • 2
  • 19
  • 30
  • @AmirAmini, Sure u want to keep `targetSdkVersion 21` at 21, try to upgrade to 23 – W4R10CK Jan 28 '17 at 09:17
  • thanks it worked, got other errors but I fixed them. but now I can't install it on the Emulator. it says there is another version of my app installed but it's the first time I'm running my app on this emulator. – Amir Amini Jan 28 '17 at 09:30
  • @AmirAmini, Consider accepting answer if helped. Clean your project. – W4R10CK Jan 28 '17 at 09:31
  • 1
    found out the emulator's storage was full. thanks for your help – Amir Amini Jan 28 '17 at 09:36