The question:
I used ActionBar Style Generator, and now trying to use into my app, but getting :
error: Error retrieving parent for item: No resource found that matches the given name ‘@style/
Theme.AppCompat.Light.DarkActionBar’.
i am using android-support-v7-appcompat.jar lib inside libs folder
my target is to make my app compatible 2.3 or above
The Solutions:
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
Method 1
AppCompat
is a library project. You need to reference the library project in your android project.
Check the topic Adding libraries with resources.
Update
Adding material theme should be the way. Check https://material.io/develop/android/docs/getting-started for more details.
Method 2
If you’re using Eclipse, then add the reference library
into your project as the following steps:
- Right-click your project in the
Project Explorer
View. - Click
Properties
. - Click
Android
in theProperties
window. - In the
Library
group, clickAdd...
- See the image below.
- Select the library. Click
OK
. - Click the
OK
button again in the Properties window.
Method 3
If you are using Android Studio then just add the dependency
dependencies {
implementation 'com.android.support:appcompat-v7:25.0.1'
}
to app/build.gradle
. And that will work
Method 4
For anyone out there using VS2015, I was getting this error too, and it turns out I hadn’t added the library to the project…
Install-Package Xamarin.Android.Support.v7.AppCompat
Method 5
If you are using Eclipse just copying android-support-v7-appcompat.jar to libs folder will not work if you are going to use resources.
Follow steps from here for “Adding libraries with resources“.
Method 6
A simple solution – replace contents this file (/res/values/styles.xml) to this is text:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
Method 7
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
}
compile has been replaced by implementation, don’t know why.
Method 8
dependencies {
compile 'com.android.support:appcompat-v7:23.0.0'
}
This worked for me… in Android Studio…
Method 9
In my case, I took an android
project from one computer to another and had this problem. What worked for me was a combination of some of the answers I’ve seen:
- Remove the copy of the appcompat library that was in the libs folder
of the workspace - Install sdk 21
- Change the project properties to use that sdk build
- Set up and start an emulator compatible with sdks 21
- Update the Run Configuration to prompt for device to run on & choose
Run
Mine ran fine after these steps.
Method 10
Using Visual Studio 2015 (Windows7) + Xamarin had this error and after trying multiple things (installing packages, download android_m2repository_r10.zip…) ended removing the full Xamarin folder inside
C:Users<my user>AppDataLocal
After that, Rebuild the application in VS and errors disappeared.
Method 11
make sure there is a v7 directory in your sdk, I thought having the ‘Android Support Library’ (in Extras) was sufficient. Turns out I was missing the ‘Local Maven repository for Support Libraries (extras;android;m2repository)’ Studio found that actually and fixed the gradle dependencies. using gradle to build then worked.
$ cat app/build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "pat.example.com.gdbdemo"
minSdkVersion 15
targetSdkVersion 23
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:23.2.1'
}
Method 12
If you are using the Android.mk to build then use the USE_AAPT2, which link in the built resource from the AAR.
Add below line in Android.mk file:
LOCAL_USE_AAPT2 := true
Method 13
- Update your SDK in the manager and be sure to include
Android
in extra’s
support library - Go to SDK in file explorer (Finder on mac) track down the extra’s
folder (..sdkextrasandroidsupportv7appcompatresvalues
on
Windows). Somewhere in there is athemes.xml
and
themes_base.xml
. Copy both of these files. - In your project paste the files into ‘values’ directory
Method 14
If you are using Visual Studio for MAC, fix the problem clicking on Project > Restoring Nutget packages
Method 15
In Eclipse: When importing a support library as a project library following the instructions at Adding Support Libraries, don’t forget to check the option “Copy proyects into workspace”!
Method 16
I had this same problem. None of the solutions listed here helped my situation. As it turns out, I was importing the parent folder for a project into Android Studio 1.5, rather than the project folder itself. This threw Gradel into a tizzy. Solution was to import the project folder instead.
Method 17
In xamarin if you face this issue when you add any new sdk.
The simple solution is Open your styles file and add
this line.
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar"></style>
It’s better solution rather than adding appcompat.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0