cereal310
cereal310

Reputation: 43

Android Studio gradle failed to resolve for SDK version 16

I just installed Android Studio for a new class and I can't even run a HelloWorld program. There are no third party dependencies as I literally just installed Android Studio, SDK version 16, the latest support repository, latest build tools, and created a Nexus 5 AVD running 4.1.2 (16). I keep getting

"Error:(24,13) Failed to resolve: com.android.support.appcompat-v7:16.+"

Here is my build.gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 16
buildToolsVersion '23.0.2'

defaultConfig {
    applicationId "edu.usna.mobileos.hellooooworld"
    minSdkVersion 16
    targetSdkVersion 16
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:16.+' // line giving me the error
}

I've tried many other solutions I've found online, but none have worked so far. I need to work with API version 16 (Android 4.1.2) in this class, so using a newer API isn't an option.

Upvotes: 2

Views: 3202

Answers (2)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364035

It happens because the 'com.android.support:appcompat-v7:16.+' doesn't exist.

Use the latest version and pay attention using the + because it is not a good option.In this way you will not be able to replicate the build in the future.

I need to work with API version 16 (Android 4.1.2) in this class, so using a newer API isn't an option.

Don't confuse minSdk and the compileSdk.

The compileSdkVersion is your way to tell Gradle what version of the Android SDK to compile your app with.
If compileSdkVersion sets the newest APIs available to you, minSdkVersion is the lower bound for your app. The minSdkVersion is one of the signals the Google Play Store uses to determine which of a user’s devices an app can be installed on.

More info here.

You can use one of these versions.
Check your sdk for updated version:

  //it requires compileSdkVersion 23
  compile 'com.android.support:appcompat-v7:23.1.1'
  compile 'com.android.support:appcompat-v7:23.1.0'
  compile 'com.android.support:appcompat-v7:23.0.1'
  compile 'com.android.support:appcompat-v7:23.0.0'

  //it requires compileSdkVersion 22
  compile 'com.android.support:appcompat-v7:22.2.1'
  compile 'com.android.support:appcompat-v7:22.2.0'
  compile 'com.android.support:appcompat-v7:22.1.1'
  compile 'com.android.support:appcompat-v7:22.1.0'
  compile 'com.android.support:appcompat-v7:22.0.0'

  //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'

Also there are very old version:

  compile 'com.android.support:appcompat-v7:20.0.0'
  compile 'com.android.support:appcompat-v7:19.1.0'
  compile 'com.android.support:appcompat-v7:19.0.1'
  compile 'com.android.support:appcompat-v7:19.0.0'
  compile 'com.android.support:appcompat-v7:18.0.0'

Upvotes: 1

Joe
Joe

Reputation: 2659

Inside Android Studio click the icon below to open the SDK Manager:

enter image description here

From there you should see something like this:

enter image description here

You want to update and/or install Android Support Library. You also may need to update the version your build.gradle file is pointing to. For example, the version I have is 23.1.0, so my reference would look like this:

compile 'com.android.support:appcompat-v7:23.1.+' // line giving me the error

Upvotes: 0

Related Questions