366

I am trying to implement the new ActionBar support library that was released by Google a couple days ago. In the past, I have successfully implemented ActionBarSherlock without any issues using the same method listed on Google Developer's Support Library Setup page - using the guide on how to include the resources (which is similar to how ActionBarSherlock did it). I have the library project loaded in to my own project as a library as well.

I can tell the library is loading fine. When, instead of extending Activity on my MainActivity.java, I changed it to extend ActionBarActivity (as per Google's instructions), no errors occur - and it imports correctly.

I even tried bypassing the style.xml file and adding @style/Theme.AppCompat.Light directly in to the AndroidManifest.xml for both <application> and <activity> with android:theme="@style/ThemeAppCompat.Light" with all attempts resulting in the same error.

Now the issue is I cannot get it to change the theme, let alone even build without throwing an error. Below is the error I am receiving, followed by the style.xml file I changed to use the new theme.

I have moderate experience working with Android apps and am running Eclipse with the latest version of the Support Libraries and SDK compiling with API 18 (Android 4.3).

Error Received During Build

error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.Light'. styles.xml /ActBarTest/res/values line 3 Android AAPT Problem

style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.ProsoftStudio.ACTest" parent="@style/Theme.AppCompat.Light">
    </style>
</resources>

Any suggestions? This was never an issue with ActionBarSherlock. I want to work on using this new support library. It almost seems like the .jar is loading, but not the resources.

d-cubed
  • 1,034
  • 5
  • 30
  • 58
Brandon Enriquez
  • 3,847
  • 3
  • 18
  • 15
  • 1
    Try to clean the project, maybe you need to reload the dependencies so that the styles from AppCompact can reload as well – TheWizKid95 Jul 26 '13 at 01:03
  • 2
    @TheWizKid95 I did a clean up on my app I am trying to implement and the library. Neither one resulted in any changed code according to Eclipse and it did not fix any of the issues. – Brandon Enriquez Jul 26 '13 at 03:21
  • Have you added support library with Resources? Add jar to libs is not enough. – Gabriele Mariotti Jul 26 '13 at 05:36
  • @GabrieleMariotti Yes I added the resources as well as a project library specially as Google instructed. – Brandon Enriquez Jul 26 '13 at 06:27
  • What worked for me was adding it as a project to the workspace. Just importing the jar and adding them to buildpath did not work. – Johan Jan 23 '14 at 13:38
  • For those troubleshooting similar issues, another thread here maybe helpful: http://stackoverflow.com/questions/18364682/theme-appcompat-light-darkactionbar-no-resource-found/24495047#24495047 – ZenBalance Jul 01 '14 at 01:23
  • refer to the link, it will help https://stackoverflow.com/a/44326032/1252158 – Summved Jain Jun 02 '17 at 10:00

31 Answers31

386

You need to do next:

  1. File->Import (android-sdk\extras\android\support\v7). Choose "AppCompat"
  2. Project-> properties->Android. In the section library "Add" and choose "AppCompat"
  3. That is all!

Note: if you are using "android:showAsAction" in menu item, you need to change prefix android as in the example http://developer.android.com/guide/topics/ui/actionbar.html

W4R10CK
  • 5,502
  • 2
  • 19
  • 30
Svyatoslav Lobach
  • 3,963
  • 1
  • 12
  • 4
  • 66
    This does not work for me. I do exactly what is written here, but end up with hundred of No resource found that matches given name errors. Resources, which missing are styles which are included from API 11 and above, but this thing should work from API 7. Is there some connection which I missing !?! – apocalypz Sep 17 '13 at 12:02
  • 5
    Having a similar problem, the Theme.AppCompat.Light.NoActionBar theme does not exist in my appcompat library. – JMRboosties Jan 14 '14 at 06:43
  • 9
    Under File-Import I can`t find 'android-sdk'. I only see 'andoird'. Anyone? – shahar eldad Feb 07 '14 at 19:59
  • 2
    apocalypz, I think you're missing the resources because you have imported the library without the resources. here is the link for "Adding libraries with resources" https://developer.android.com/tools/support-library/setup.html#libs-with-res – Hades200621 Mar 10 '14 at 18:11
  • @JMRboosties I just ran into the same issue. `Theme.AppCompat.Light.NoActionBar` does not exist. So I checked `Theme.Holo.NoActionBar`. It only sets `android:windowActionBar` and `android:windowNoTitle`. It seems to be simple enough to define it myself :) – lupz May 28 '14 at 14:43
  • 1
    Following above steps + add sdk\extras\android\support\v13android-support-v13.jar to libs directory of project will resolve the issue. – Wasim A. Nov 24 '14 at 17:11
  • 1
    while importing, clicking 'copy project into workspace' worked for me – Shirish Herwade Mar 05 '15 at 12:09
  • I have using the same library for remaing projects it works fine. I had downloaded from github and imported (this project is in android studio) in eclipse. I had added both v4 and v7 jar files also. but no use. Same error – Prasad Mar 23 '15 at 10:07
  • Project appcompat_v7 is automatically created when you create the android project that depends on it. Just re-open it in Eclipse and compile the target project. Eclipse should report a more user-friendly message, and prompt appcompat_v7 should be open. – Danke Xie May 14 '15 at 21:51
  • @shahareldad i added so many referenced prj under properties->android-> add now when i put mycode in bitbucket its not detecting any of my referenced libraries .... how to resolve this issue ? – Erum Jun 09 '15 at 05:01
  • It's really bad idea to import appcompat in such way. Use gradle instead – kandi Sep 26 '15 at 19:36
121

If, like me, you are following the Android tutorial on http://developer.android.com/training/basics/actionbar/setting-up.html and keep getting this error, try to change the AppBaseTheme style in all styles.xml files. In detail:

  1. In file res/values/styles.xml change the line:

    <style name="AppBaseTheme" parent="android:Theme.Light">
    

    to:

    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
    
  2. In file res/values-v11/styles.xml change the line:

    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
    

    to:

    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
    
  3. In file res/values-v14/styles.xml change the line:

    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    

    to:

    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    

Now the application should run fine.

marco110
  • 1,211
  • 1
  • 8
  • 5
  • 11
    Yes this worked for me. The key thing to notice is that in the parent attribute "android:" prefixes built in themes (styles) while a value without this prefix references your own styles, or styles in any libraries you have linked to ... such as android-support-v7-appcompat. – John Bentley Jan 18 '14 at 11:00
  • There is no `res/values/styles.xml` in a new Android project. At least not when you create it with `android create project`. – weberc2 Apr 06 '14 at 19:31
  • You get the styles.xml when you create the project with wizard select full screen app and hide controls – JJ_Coder4Hire Apr 16 '14 at 20:16
  • 8
    Nothing works for me... 4 hours already wasted. I still get No resource found that matches the given name (at 'theme' with value '@style/Theme.AppCompat.Light'). Just about to give up. – c.fogelklou Aug 07 '14 at 03:49
  • 2
    I'd just changed those the other way, and indeed that was how things had to be in my project. – John Oct 06 '14 at 00:31
  • @John That backfired for me later on when I tried to run the final product in the "Starting Another Activity" section (http://developer.android.com/training/basics/firstapp/starting-activity.html). I ended up having to use the values that marco110 shows above – nikodaemus Dec 20 '14 at 22:31
30

This is an issue that can happen in Android Studio if you modify Project Structure Modules. In this case you may need to add the dependencies again. In a text editor edit the 'build.gradle' file to include the required dependencies:

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

This should update your '{your_project_name}.iml' file with lib components:

<orderEntry type="library" exported="" name="appcompat-v7-19.0.1" level="project" />
David Douglas
  • 10,377
  • 2
  • 55
  • 53
  • 1
    Bear in mind there are 2 *.iml files. The one with the library entries is contained in the project's subfolder and has a lowercase filename. – David Douglas Mar 16 '14 at 10:42
  • 2
    This fixed my problem. adding the appcompat to the dependencies in the inner build.gradle worked. I regret to say I did edit manually to match another project which broke things! – JJ_Coder4Hire Apr 16 '14 at 20:19
28

I will share my experience with this problem. I was going crazy because of this, but I found out that the problem was a bug with Eclipse itself, rather than my code: In eclipse, unable to reference an android library project in another android project

So, if you have the Android Support Library in your C: drive and your project in the D: drive on your computer, Eclipse won't function correctly and won't know where the Android Support Library is (green tick turns into red cross). To solve this, you need to move both projects onto the same hard drive.

Community
  • 1
  • 1
DrFred
  • 461
  • 3
  • 6
  • 4
    Thank you. That was the case of my situation. On step 1 (File->Import (android-sdk\extras\android\support\v7). Choose "appcompat"), one needs to check "copy to workspace". – Hong Nov 12 '13 at 04:43
  • I faced with similar problem. Thanks a lot, it was really tricky – SILINIK Feb 04 '14 at 19:46
  • Same issue in AndroidStudio. I just spent like 3 hours trying to figure this out. Thanks! – Ruben Martinez Jr. Apr 22 '14 at 01:42
  • Jup. Can confirm this..IntellJ has exactly the same problem, at least with AppCompat...wasted 4 hours on this problem. – puelo Oct 31 '14 at 23:03
  • This was the solution for me as well. Copying the appcompat_v7 project to the same drive as the target project and adding it as lib made it work without issues. – MayaPosch Jun 07 '15 at 18:49
23

I did the following in Eclipse with the Android Support Library (APL) project and the Main Project (MP):

  1. Ensured both APL and MP had the same minSdkVersion and targetSdkVersion.

  2. Added APL as a build dependency for MP:

    1. Going into "Properties > Java Build Path" of MP, and then

    2. Selecting the "Projects" tab and adding APL.

  3. In the properties of MP, under "Android", added a reference to APL under library.

1 and 2 got the references to Java classes working fine...however I still saw the error in the manifest.xml for MP when trying to reference @style/Theme.AppCompat.Light from APL. This only went away when I performed step 3.

nikodaemus
  • 1,918
  • 3
  • 21
  • 32
yogi
  • 231
  • 1
  • 2
  • 10
    Definitely use "@style/Theme.AppCompat..." rather than "@android:style/Theme.AppCompat...". This plus #3 from this answer solved my problem. – BeccaP Sep 10 '13 at 21:58
  • Point 2 seems to be incorrect. It leads to a build error log message as described and fixed here: http://stackoverflow.com/questions/18421274/android-could-not-find-android-support-v7-appcompat-apk-error – OneWorld Nov 12 '14 at 12:09
18

Its bit late but here is how I get it done in AndroidStudio !

Right click on app to goto properties Right click on app to goto properties

Go to Dependencies and click on '+' sign and choose library dependency Go to Dependencies and click on '+' sign and choose library dependency Choose appcompat-v7 Choose appcompat-v7

Rahul
  • 4,699
  • 5
  • 26
  • 38
12

IntelliJ IDEA solution.

1. Run Android SDK Manager and install the latest SDK and Android Support Libarary. The version of SDK and Android Support Libarary should be the same! 23 in my case. Another variants will give you the errors.
enter image description here
2. Change SDK version of your IDEA project to the last one you installed in previous step. (ps. you may not use Maven).
enter image description here

3. Add new Module from existing sourse to your IDEA project.
enter image description here

4. Add AppCompat project. !!! Should be under the last SDK too! (ps. Say "Yes" anywhere in process of this step)
enter image description here

5. Open settings of your main Project Module and add to it next 3 dependecies:

5.1. Module Dependency. Chose android-support-v7-appcompat
enter image description here

5.2. 2 pc. Library Dependencies. Add android-sdk\extras\android\support\v7\appcompat\libs\android-support-v4.jar and android-support-v4\android-support-v7-appcompat.jar
enter image description here

In total it will be:
enter image description here

6. Very important!!!
Add theme with prefix @style (not another!).
enter image description here



Android Studio solution.

1. Run Android SDK Manager and install the latest SDK and Android Support Libarary. The version of SDK and Android Support Libarary should be the same! 23 in my case. Another variants will give you the errors.
enter image description here

2. Add next to build.gradle

dependencies {
    compile 'com.android.support:appcompat-v7:23.0.1'
} 

P.S. If you are new in Android developing, I strongly recomend you move to Android Studio & Gradle right now - you will get the simplest way of managing your android app.

Community
  • 1
  • 1
Yuliia Ashomok
  • 8,336
  • 2
  • 60
  • 69
10

For Android Studio 1.2.2

Drop "android" from the parent attribute value:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"></style>
Ghasem
  • 14,455
  • 21
  • 138
  • 171
mumush
  • 650
  • 6
  • 14
7

you need reference $ANDROID_SDK/extras/android/support/v7/appcompat

Crossle Song
  • 10,104
  • 2
  • 29
  • 38
  • You mind going in to more detail in how exactly to reference it? I have already referenced that exact folder as a the instructions on Android Developers stated. Followed the directions exactly as stated on their website. I can tell it is being referenced at least partially because ActionBarActivity is being extended without errors. – Brandon Enriquez Jul 26 '13 at 06:31
  • 3
    reference `appcompat` as Android Library, your main project resource can found theme from appcompat – Crossle Song Jul 26 '13 at 06:43
  • That did the trick. I was previously doing it within the Java Build Path. – Brandon Enriquez Jul 26 '13 at 06:58
5

For IntelliJ IDEA or Android Studio:

Add this to app.gradle build file

dependencies {
    compile "com.android.support:appcompat-v7:21.0.+"
} 

Replace -v:xx.0+, with your build target, if you have 19 platform then it must be like:

dependencies {
    compile "com.android.support:appcompat-v7:19.0.+"
}
Allan Pereira
  • 2,572
  • 4
  • 21
  • 28
geniushkg
  • 706
  • 9
  • 21
3

Follow the steps of @rcdmk. Delete the android support v4.jar in YOUR project. It conflicts with the new updated version found in appcompat.

back2back
  • 113
  • 11
3

I had same problem and waste my 4-5 hours for solution. My problem solved with;

  1. From SDK manager delete packages "Android Support Library" and " Android Support Repository".
  2. Reinstall "Android Support Library" and " Android Support Repository"
  3. Remove "android-support-v7-appcompat" or "appcompat_v7 what else you have in your project.
  4. Import android-support-v7-appcompat from "adt-bundle-windows-x86_64-20140702\sdk\extras\android\support\v7\appcompat"
  5. Select your project and from file choose properties and find Java Build Path and then from "Project" tab delete what else there and then Add. and you must see "android-support-v7-appcompat" , select and add it to Project tab.
  6. Check your project.properties file below your Project files, you will see like this; target=android-21 android.library.reference.1=../android-support-v7-appcompat then check AndroidManifest.xml file if target is 21 or what else you choosed. Also check for library reference same as your library that choosed before.

Hope you will find your solution.

syildizeli
  • 51
  • 4
  • 1
    What helped me was to upgrade my Android Support Library using SDK manager, delete the old appcompat library from the workspace, re-import the newly updated appcompat library (and copy into workspace) and then build. – Varun Aug 05 '15 at 19:28
3

My issue resolve via following Steps

  1. File->Import (android-sdk\extras\android\support\v7\appcompat)

  2. Right Click Project-> properties->Android. In the section library "Add" and choose library appcompat that's include in step 1

  3. Delete all files from project's libs directory

  4. add following file to project's libs directory <SDK-PATH>\extras\android\support\v13android-support-v13.jar

    Restart Eclipse if required. That's it. Your problem should be disappeared.

Community
  • 1
  • 1
Wasim A.
  • 9,660
  • 22
  • 90
  • 120
2

works:

<style name="MyApp" parent="Theme.AppCompat.Light">
</style>
<style name="MyApp" parent="@style/Theme.AppCompat.Light">
</style>
<style name="Theme.AppCompat.Light.MyApp">
</style>
Yin
  • 43
  • 6
2

Since the Import dialouge is different in Android Studio 1.0.1, I could't get Svyatoslav Lobachs version to work.

Instead I downloaded "Android Support Repository" in the SDK Manager. Then added

dependencies {
...
compile "com.android.support:appcompat-v7:18.0.+"
}

to build.gradle. Worked for me.

qwertz
  • 315
  • 1
  • 4
  • 14
1

http://developer.android.com/tools/support-library/setup.html has a bug. In Property->Java build path->'Project' and 'Order and Export', there should not be any jar's. Removing them, and checking 'Android Private Libraries' and 'Android Dependencies' solved my problem.

Joe C
  • 2,757
  • 2
  • 26
  • 46
1

I experienced the same problem as the OP after right-clicking on my project and selecting Close Unrelated Projects.

In my case, I resolved the problem by re-opening the appcompat_v7 project and cleaning/rebuilding both projects.

ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253
1

It happened to me when Eclipse(Luna)/AndroidSDK(not Android Stduio) were used with the latest tools and library as of Jan. 14, 2015 during the project like HelloWorld. When I installed those tools and made HelloWorld the first app, I accepted all the defaults. - This is the problem in my case.

First, check whether or not the "Android Support Library" library is installed. If not, install it. It is not installed by default. You may do it all in "Android SDK manager" available in the menu.

(Android SDK Manager -> Extra -> Android Support Library)

Blessings, (a debtor)<><

Youngsup Kim
  • 2,235
  • 5
  • 13
  • 18
1

Quickest solution :

right click on the project - > Android tools -> Add support library..

enter image description here

Jesus Dimrix
  • 4,378
  • 4
  • 28
  • 62
0

I made a really silly mistake for this. When I was getting same error every time i could not figure out what was wrong. then it clicked me that once I have closed all the projects in my work space and that was the time since all the problems started. SO just check whether your "appcompat_v7" is not closed. If it is then open the project by double click and then clean and build your project again. In my case the errors were gone. Happy coding!

Riddhi Dudani
  • 107
  • 1
  • 1
  • 10
0

I am not sure whether v13 support library was available when this question was posted, but in case someone is still struggling, I have seen that adding android-support-v13.jar will fix everything. This is how I did it:

  1. Right click on the project -> Properties
  2. Select Java Build Path from from the left hand side table of content
  3. Go to Libraries tab
  4. Add External jars button and select <your sdk path>\extras\android\support\v13\android-support-v13.jar
sdevikar
  • 437
  • 6
  • 20
0

For Android Studio or IntelliJ, all you need to do is update your dependencies in gradle.build. I used the following:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.2'
}
BostonGeorge
  • 3,092
  • 1
  • 17
  • 12
0

I dont know how many of you noticed this. Support library "appcompat_v7" and your project should be in a same directory(I mean workspace directory). Dont clean your project until its error free else you will have tough time with R.java

Isham
  • 424
  • 4
  • 14
0

You had better make new project with any name , then use appcompat_v7 that program make new .

Right Click Project-> properties->Android

In the section library Add and choose library appcompat.

Robert
  • 25,425
  • 8
  • 67
  • 81
Sale
  • 11
0

in eclipse right click on your project-> select build path and then select configure build path. from the window select the jar file that you want and refresh your project

Rahul
  • 45
  • 9
0

The accepted solution used to work for me once, but not now. I had to re-create a hello-world of the same kind (!) in a new workspace, made it compile, and then copied all directories, including .hg and .hgignore. hg diff shows:

-        android:targetSdkVersion="19" />
+        android:targetSdkVersion="21" />

Binary file libs/android-support-v4.jar has changed

It looks like Eclipse wants to compile for API 21 and fails to do anything with API 19. Darkly.

18446744073709551615
  • 16,368
  • 4
  • 94
  • 127
0

If you have added appCompat Library and also have given proper reference of appCompat from SDK location, try "invalidate caches/Restart".
You can find it from "File" menu in Android Studio.

Suraj Dubey
  • 536
  • 6
  • 11
0

In my case the problem occurred since I wanted to use a SDK that doesnt include the required library. When I increased the min. SDK level the problem dissappeared. Of course directly including the library's itself, should remove the error as well.

0

Forget everything. Just use the appcompat library downloaded using the Android Studio. It has all the missing definitions. No matter whether you are using in Eclipse or not.

Rohit Rokde
  • 622
  • 2
  • 8
  • 16
0

I had the same issue and even after importing/adding a jar/library as mentioned in the answers it would not solve the error. Out of frustration, I just created a new workspace and created a fresh android project and it automatically imported appcompat_v7 and there were no errors on clean and build. Didn't have to import a single jar/ library manually. Just FYI I am using eclipse Mars.1 Release (4.5.1) and was facing the exact same issue everytime I created a new android project.

API
  • 449
  • 3
  • 12
0

I have the error message:

Error:(18) Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.NoActionBar'.

with this configuration :

  compileSdkVersion 23
  buildToolsVersion "23.0.1"

I have to change the theme from:

 <style name="AppTheme" parent="Theme.AppCompat.NoActionBar"/>

to:

 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"/>
Jorgesys
  • 124,308
  • 23
  • 334
  • 268