807

I've always programmed Android with Eclipse and decided to start migrating to Android Studio. I decided to use the same SDK I already had for Eclipse, then:

  • Started a new project
  • Set minimum SDK 4.0 (API Level 14)
  • Choose Blank Activity option
  • Used Default names for Activity Name and Layout Name
  • Hit Finish

After a few seconds Gradle finishes the build, and it throws me two errors with the following messages in file Teste4\app\build\intermediates/exploded-aar\com.android.support\appcompat-v7\23.0.0\res\values-v23\values-v23.xml:

Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.

Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'.

Under File -> Project Structure -> Modules: app (left column) -> Properties tab, I have the following versions set up:

  • "Compile Sdk Version": Android 5.1 (API Level 22)
  • "Build Tools Version": 23.0.2

What should I do in order to fix this?

I already tried what was suggested in Stack Overflow question appcompat-v7:21.0.0': No resource found that matches the given name: attr 'android:actionModeShareDrawable', but it didn't work.

Community
  • 1
  • 1
Vini.g.fer
  • 11,639
  • 16
  • 61
  • 90

24 Answers24

1156

Your compile SDK version must match the support library's major version.

Since you are using version 23 of the support library, you need to compile against version 23 of the Android SDK.

Alternatively you can continue compiling against version 22 of the Android SDK by switching to the latest support library v22.

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
  • 1
    How can I change the version for the support library to 22? – Vini.g.fer Aug 18 '15 at 14:49
  • 11
    You can either change it manually in your `build.gradle`, or you can use the GUI by opening up the project properties and going to the "dependencies" tab. – Bryan Herbst Aug 18 '15 at 14:52
  • 2
    Ended up installing v23 of the SDK and that solved the problem. Tried to lower the version to 22, but it wasn't available on the GUI or give me an error on changing build.gradle (I'm a complete newbie about gradle, so please forgive me). Thanks! Did you managed to lower the version "4k3R"? – Vini.g.fer Aug 19 '15 at 17:39
  • I'm confused... I was under the impression that Android apps were forward-compatible, right? So if I target the 4.0 API, and try running it on a 5.1 virtual device (whatever those API levels are), why wouldn't it work? If I raise the API level so that the app works on my 5.1 virtual device, won't the app be incompatible with 5.0 and below? – Daniel Aug 22 '15 at 19:48
  • 12
    This question and answer have nothing to do with what version your app will run on. An app targeting 22 can run just fine on a device running 23. The problem described here is that the support library version 23 requires that you target 23, as the support library references some APIs in the 23 SDK. – Bryan Herbst Aug 22 '15 at 21:13
  • This answer did not help me. I use the v7 support library. In the `project.properties` under `android_sdk_path\extras\android\support\v7\appcompat`, I see `target=android-19`. Setting `compileSdkVersion = 19` in `build.gradle (app)` didn't fix the problem. – Shailen Aug 23 '15 at 10:22
  • Oh, okay, I just figured out there's a difference between the api level you target ant the minimum api level. – Daniel Aug 23 '15 at 19:58
  • 43
    For those like me who are new to Android Studio and are confused about how to "use the GUI by opening up the project properties", in my Android Studio (v1.3.1), I go to File, Project Structure, then in the left-hand pane at the bottom is an entry under Modules (called "app" in my case). I click on that, and then I see a Dependencies tab. – Bryan Aug 27 '15 at 18:43
  • 121
    I still can't believe Android Studio releases stuff without even testing something SO basic!! At least put some meaningful warnings!! – Josh Aug 31 '15 at 11:11
  • 1
    @Josh this is not an Android Studio problem, it's the story library. They could definitely use some documentation surrounding it though. – Bryan Herbst Aug 31 '15 at 12:01
  • 31
    The GUI should have popped up a message "we've detected you're not targeting the right Android API version. Want me to fix it?". Instead, I have to stop working on the airplane and wait until I can search stackoverflow. – Someone Somewhere Sep 02 '15 at 22:31
  • Helped in my scenario, I added compileSdkVersion 22 buildToolsVersion '22.0.1' and then I used 'com.android.support:appcompat-v7:22.0.0' in "dependencies". and it worked fine. – Naveed Ahmad Sep 03 '15 at 07:44
  • 1
    That is funny. If you complile with API23 that also produces errors. And stackoverflow for those error say you should compile with API21. Circle completed. – f470071 Sep 27 '15 at 16:11
  • I have `buildToolsVersion "23.0.1"` `compileSdkVersion 21` and dependency `compile 'com.android.support:appcompat-v7:21.0.1'` I found that I had to clean the project, after changing appcompat version, in order to overcome the error `cannot resolve symbol R` – Someone Somewhere Oct 14 '15 at 13:57
  • Is there a straight forward way to switch to v22 of support library in Eclipse? – Solace Dec 02 '15 at 15:33
  • 2
    @Tanis.7x Even After doing these changes error not solved. Still I have these errors in `v23/values-23.xml` file. I've `compileSdkVersion:22,buildToolsVersion "22.0.1", targetSdkVersion 22,` and dependence `compile 'com.android.support:appcompat-v7:22.2.1'` then rebuild app. But still facing the issue :( – Prabs Jan 07 '16 at 13:05
  • @Prabs You are probably referencing a resource (such as a style) that was introduced in API 23 in that file. This will not work if you compile against API 22. – Bryan Herbst Jan 07 '16 at 13:18
  • 1
    @Tanis.7x That style is auto generated. I'm not using it anyway. And it is not allowing me to delete it. How do I overcome this situation. – Prabs Jan 09 '16 at 05:18
  • @Tanis.7x Problem solved. I've updated to API 23 and to use apache I've followed [this](http://stackoverflow.com/a/32108524/4361127) it's working now :) – Prabs Jan 09 '16 at 05:37
  • Android Studio 2.0, I had to add both the following dependencies in build.gradle (but done through the project structure -- modules -- dependences tab: appcompat-v7:23.3.0 and support:design:23.3.0. Compiling at version 23, buildtools at 23.0.3 with a minsdk version >= 10. – natur3 May 11 '16 at 01:38
  • I am trying to add "com.android.support:appcompat-v7:22.0.0" from the "Dependencies" tab, but I do not see it available for me. I see "com.android.support:appcompat-v7 (com.android.support:appcompat-v7:25.1.1)". Do they only show the latest versions? – Jaime Montoya Feb 19 '17 at 15:44
  • I used http://stackoverflow.com/questions/29284236/failed-to-resolve-com-android-supportappcompat-v722-and-com-android-supportre as a reference. In my file C:\Users\jaimemontoya\Downloads\CouponClub2\app\build.gradle, specifically in the dependencies {} section, I am adding the corresponding dependencies according to the "compileSdkVersion" and "buildToolsVersion" that I want to use. – Jaime Montoya Feb 19 '17 at 16:33
  • @JaimeMontoya the list will only populate with the latest version for each library, but you can always specify the version yourself in the dialog before you hit "ok" – Bryan Herbst Feb 20 '17 at 15:23
  • When I try to enter something invalid, I get this message: "Please enter a valid coordinate, discover it or select one from the list". But if I need an older version of a dependency, I can just type in a valid one, as you mentioned Tanis.7x. – Jaime Montoya Feb 20 '17 at 23:18
  • in my case i was using `compile sdk 23` and `build tools 25.0.0` just changed `compile sdk` to 25 and done.. – Nilesh Deokar Jun 15 '17 at 06:11
142

This happens because after updates Android Studio uses API version 23 by default.

The following worked for me:

Press Ctrl + Shift + Alt + S to get to the project structure page. Go to the properties tab and change 23.0.0 to 22.0.1 (or equivalent to what you were using earlier) in the build tool area and rebuild your project.

If that doesn't work, go to gradle:app and then

compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'

Edit v7:23.0.0 to v7:22.2.1 as shown above and sync gradle. This will definitely work.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sourav Nanda
  • 1,729
  • 1
  • 11
  • 11
  • 10
    For newbies like me who are confused about how to "go to gradele:app and then compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.2.1'", in my Android Studio (version 1.3.1), in the project pane (which I opened by clicking the 1: Project tab on the very left), I see two entries under Gradle Scripts called "build.gradle". The second one has (Module: app) next to it. I double-clicked it to open it. Then in the dependencies section at the bottom, I changed the v7:23.0.0 to v7:22.2.1. I saved (and synced as prompted by Studio) - seemed to compile ok. – Bryan Aug 27 '15 at 18:57
  • 4
    How can I enter project structure page on MAC? – rosu alin Dec 02 '15 at 10:28
  • 4
    @Sourav Even After doing these changes error not solved. Still I have these errors in `v23/values-23.xml` file. I've changed values in project structure page, rebuild app. But still facing the issue :( – Prabs Jan 07 '16 at 13:03
  • On mac the shortcut is ⌘ + ; . Alternatively you can go to File > Project Structure. – Tomanow Dec 19 '16 at 15:20
117

When you update your Android Studio, it uses API version 23 by default, which is the main reason for its occurrence. So,

At first, check your AppCompat version in build.gradle(Module:app) That is,

Enter image description here

If after changing to 23 there occurs an error then just download

Compile Sdk Version to API 23, and Build Tools Version to 23.0.0

from SDK Manager. If already downloaded then:

1. Go to SDK Manager and
2. Under Project Structure, change *Compile SDK Version* to API 23, and *Build Tools Version* to 23.0.0

Click the SDK Manager Button and open the dialog.

Enter image description here

Click SDK Platform and check if Android 6.0 is downloaded or not.

if not, then download that first. After completing the download, click Apply.

Enter image description here

Now you need to apply changes to your project from setting. Then press Ctrl + Alt + Shift + S to open setting

  1. Click the app from the list.
  2. Click properties
  3. Change your Compile SDK Version to API 23
  4. Change your Build Tools Version to 23.0.0

Enter image description here

Don't forget to rebuild your project.

Then your error will be gone.

Ravikant Paudel
  • 2,228
  • 2
  • 17
  • 28
69

If you've tried to change target to a previous GooglePlayServices or AppCompatv7 version and it doesn't work, check if you have any project-libraries dependency, this project will be targeting the latest version of any of these libraries. It happened to me with the Google Maps Utils Library project:

replace:

compile 'com.google.android.gms:play-services:+'

to

compile 'com.google.android.gms:play-services:8.3.0'

Then you can continue full targeting API 22

If it still doesn't compile, sometimes is useful to set compileSdkVersion API to 23 and targetSdkVersion to 22.

Pelanes
  • 3,451
  • 1
  • 34
  • 32
36

I agree with the previous answer. Your compile SDK version must match the support library. Here is what I did.

  1. You can go to SDK Manager and under SDK Platform, install the Android 5.X with API level 23.
  2. Under Project Structure, change compile SDK Version to API 23, and Build Tools Version to 23.0.0

Then it should build without problem.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Stucky
  • 583
  • 3
  • 11
23

You need to set compileSdkVersion to 23.

Since API 23 Android removed the deprecated Apache Http packages, so if you use them for server requests, you'll need to add useLibrary 'org.apache.http.legacy' to build.gradle as stated in this link:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"
    ...

    //only if you use Apache packages
    useLibrary 'org.apache.http.legacy'
}
Sai's Stack
  • 1,345
  • 2
  • 16
  • 29
16

This issue is raised because now the compile SDK version must match the Android Support library's major version.

In my case i have the Android Support Library version 23, so i had to compile against the Android SDK version 23, and I had to change this in my build.gradle file:

enter image description here

Well some of you will need to install the SDK, Android 6.0 (API 23)

enter image description here

and don´t forget to Sync project with gradle files

Community
  • 1
  • 1
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
13
android {
    compileSdkVersion 23
    buildToolsVersion '23.0.1'

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

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.android.support:recyclerview-v7:23.0.0'
compile 'com.android.support:appcompat-v7:23.0.1'
}
piet.t
  • 11,718
  • 21
  • 43
  • 52
dhiku
  • 1,818
  • 2
  • 22
  • 38
10

I found the solution, Problem started when I updated sdk, after that I used different buildToolsVersion ('22.0.1') and I was using different support library like compile 'com.android.support:appcompat-v7:23.0.0', showing you in image below

enter image description here

This was raising problem of "android.widget.Material..." Then I used same version for support library like compile 'com.android.support:appcompat-v7:22.0.1' and its DONE. (Showing you in below screenshot)

enter image description here

Naveed Ahmad
  • 6,627
  • 2
  • 58
  • 83
10

You should compile your project with latest version so update & install from your SDK. Sync your project with sync project with Gradle file Button.
You can also continue with the existing version but check it installed properly below image indicate to API 22 that is properly installed. enter image description here

And sync your project if needed.

enter image description here

it may help.

Inzimam Tariq IT
  • 6,548
  • 8
  • 42
  • 69
9

As pointed out by Tanis.7x, the support library version (23) does not match the targetSdkVersion (22)

You can fix this by doing the following:

In the build.grade file of your app module, change the following line of code

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

To

compile 'com.android.support:appcompat-v7:22.+'

This will use the latest version of the appcompat version that is compatible with SdkVersion 22.

RWIL
  • 8,729
  • 1
  • 28
  • 37
7

Your compile SDK version must match the support library major version. This is the solution to your problem. You can check it easily in your Gradle Scripts in build.gradle file. Fx: if your compileSdkVersion is 23 your compile library must start at 23.

  compileSdkVersion 23
    buildToolsVersion "23.0.0"
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 340
        versionName "3.4.0"
    }
dependencies {
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:recyclerview-v7:23.0.1'
}

And always check that your Android Studoi has the supported API Level. You can check it in your Android SDK, like this: enter image description here

Oskar
  • 2,522
  • 32
  • 37
6

In my case it was an higher version of Google-play-services. I set them to 7.0.0 (not 8.x) and all was ok.

Alecs
  • 2,900
  • 1
  • 22
  • 25
5

I wanted to downgrade from API 23 to 22 and got this error. I had to change all build.gradle files in a project in order to compile.

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.yourapp.app"
        minSdkVersion 14
        targetSdkVersion 22
    }
...
dependencies {
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:support-v4:22.2.1'
    compile 'com.android.support:design:22.2.1'
    compile 'com.google.android.gms:play-services-gcm:10.0.1'
}
CoolMind
  • 26,736
  • 15
  • 188
  • 224
4

This is what helped me: Adding specific android platform

What should be done is the following... In my case it was cordova but the same is relevant for ionic, phonegap and other frameworks like these:

  1. list all platforms installed for your project: cordova platform list. You'll see something like this:

enter image description here

  1. remove the android platform: cordova platform remove android.

  2. then add the specific android platform: cordova platform add android@5.0.0.

Good luck! :)

Lentyai
  • 968
  • 1
  • 10
  • 25
3

I got the same problems. I solved my problem by updating gradle.build for each sub-module to latest compiler version.

A P
  • 2,131
  • 2
  • 24
  • 36
sonida
  • 4,411
  • 1
  • 38
  • 40
2

Another solution : navigate to

\sdk\extras\android\m2repository\com\android\support\appcompat-v7\23.x.x

open .aar file with 7-zip or winrar , in res folder remove values-23 folder and save changes .

Ali Zarei
  • 3,523
  • 5
  • 33
  • 44
2

on module: app (Gradle)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.namepack.nameappxxxxx"
        minSdkVersion 16
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
}

project: nameAppXXXX (Gradle)

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'

    }
}

allprojects {
    repositories {
        jcenter()
    }
}

and edit your activity of AppCompatActivity to for example Activity:

package com.namepack.nameappxxxxx;


import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;

public class NameClass extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);
    }


}
Alex Zaraos
  • 6,443
  • 2
  • 26
  • 21
2

Everything is great but none of you explained where to download the SDK build tools

Everything is greate but none of you explained where to download the SDK build tools

Stav Bodik
  • 2,018
  • 3
  • 18
  • 25
1

SDK Manager

Make sure that all these are in upto date.

Ganesh Kanna
  • 2,269
  • 1
  • 19
  • 29
1

Upgrade Android Studio.

I had this issue with Android Studio 1.3.1 and none of the other answers worked for me, but after updating to 1.5.1 there were no problems.

Matthew Read
  • 1,365
  • 1
  • 30
  • 50
1

If you are using phonegap(cross-platform) and got same issue above, just remove the android platform using below command.

phonegap platform remove android

And add it again.

phonegap platform add android

Then problem solved for me.

Community
  • 1
  • 1
Edukondalu Thaviti
  • 575
  • 1
  • 5
  • 16
0

If you are getting errors even after downloading the newest SDK and Android Studio, here is what I did:

  1. Download the most recent SDK
  2. Open file-Project structure (Ctrl + Alt + Shift + S)
  3. In modules, select app
  4. In the properties tab: Change compile SDK version to API 23 Android 6.0 marshmallow (latest)

I hope it helps someone so that he won't suffer like I did for these couple of days.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
xsushil
  • 37
  • 1
0

As others have already mentioned your compile sdk version must match your support library's major version. This is however, also relevant for subprojects should you have any.

In case you do, you can set your subprojects compile sdk versions with the following script:

subprojects { subproject ->
afterEvaluate{
    if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
        android {
            compileSdkVersion rootProject.ext.compileSdkVersion
            buildToolsVersion rootProject.ext.buildToolsVersion
        }
      }
   }
}

Add this script in your root build.gradle file.

Agilanbu
  • 2,747
  • 2
  • 28
  • 33
TheBaj
  • 1,091
  • 1
  • 10
  • 22