Android Theme.AppCompat not found - but Google instructions respected - android

I am fighting against Android and compatibility library AppCompat and I am loosing. I come here crying for help.
Since I would like to use a NavigationDrawer (using the code automatically generated by Android Studio) I have to start using the AppCompat library. My app does not work any more because the builder cannot find the theme AppCompat.
I followed all the steps here: https://developer.android.com/tools/support-library/setup.html#add-library
This is the gradle file "Module:app":
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "19.1"
defaultConfig {
applicationId "it.misc.application"
minSdkVersion 19
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':another-library-here.')
}
And this is the res/values/style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
The error is:
Error:Error retrieving parent for item: No resource found
that matches the given name
'android:Theme.AppCompat.Light.DarkActionBar'.
Since I did everything the doc says and I also removed/reinstalled the compatibility library as suggested in an answer to another StackOverflow question, I do not know what else I could try.
Could it be related to the fact that I am using API and build tools ver. 19 and the the Android Support Library 21.0.3? (I think not, but ...)
This is the new gradle, but building keeps failing:
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "it.autostradetech.orchestra.negoziante"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':orchestra.autostradetech.it.')
}
Nothing changes if I set minSdkVersion to 14, 7, 8, or any other random number.

It's not android:Theme.AppCompat just Theme.AppCompat. Only resources from framework have the prefix.
Also change the compile SDK version to 21. The support library version, target SDK and compile SDK versions should correspond.

Replace:
<style name="AppTheme" parent="android:Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
with:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>

Try changing compileSdkVersion and targetSdkVersion to 21, and change this in your Project Settings also. If you really want to use the appcompat-v7 library, then I suppose minSdkVersion should be at least 14.
EDIT: And it needs to be Theme.AppCompat.Light.DarkActionBar, not android:Theme.AppCompat.Light.DarkActionBar.

Try this solution as suggested in this question.
File->Import (android-sdk\extras\android\support\v7). Choose
"appcompat"
Project-> properties->Android. In the section library "Add" and
choose "appCompat"

Related

android.support.v7.internal.app.WindowsDecorActionBar Rendering Problems

Hello developers friends!
I am studying development for Android in recent months.
But just this last week came the question . How can I solve the problem of the image below ?
ActionBar is deprecated in the latest android api... If you need to use it make sure your theme read as follow:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
you can find this in:
res > values > styles.xml
I was also getting these errors.
Solved by setting similar versions to the fields in gradle file as below
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.intplus.hijackid"
minSdkVersion 16
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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.0'
}
Observe the versions compileSdkVersion, buildToolsVersion, targetSdkVersion also the support v7 version.
I was having appcompat-v7:21.0.3. Changes as shown above fixed the issues!

Android ActionBar - style error, but AppCompat added

I'm new to Android programming. I want to use Android Studio (I have the newest one, version 0.8.2), and style my Action Bar.
The Gradle throws the following error during the build process:
Error:Error retrieving parent for item: No resource found that matches the given name '#android:style/Theme.AppCompat.Light.DarkActionBar'.
Here's my style.xml file:
<resources>
<!-- Base application theme. -->
<style
name="AppTheme"
parent="#android:style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/SocialExitActionBar</item>
</style>
<style
name="SocialExitActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/tranparent</item>
</style>
</resources>
It's the same as the Google's documentation. In every question, I found, the answer was to add the appcompat Library. But I have the appcompat library added in my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.procode.socialexit"
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
}
Here's on pic:
link
Thanks for your help!
I had to remove the #android:style/ before each parent value.

AppCompat / Chromecast in Android-L Preview

Situation:
I'm currently building a new version of my app for Android L and am also in the process of Chromecast integration.
The app works fine, as long as I extend Theme.Material with my custom style, but doesn't show the Cast button.
Problem:
As soon as I change to Theme.AppCompat, it gives me the error:
Error:Error retrieving parent for item: No resource found that matches the given name '#android:style/Theme.AppCompat.Light.DarkActionBar'.
and the same goes for the the Holo Theme as well.
Here's my build.gradle (The libs folder is empty btw.):
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-L'
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.myapp.myapp"
minSdkVersion 'android-L'
targetSdkVersion 'android-L'
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:support-v4:+'
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:mediarouter-v7:+'
compile 'com.google.android.gms:play-services:+'
}
Here is the relevant part of the values/styles.xml:
<style name="SK" parent="android:Theme.AppCompat.Light.DarkActionBar">
used to work with Theme.Holo.Light.DarkActionBar
and the values-v21/styles.xml:
<style name="SK" parent="#android:style/Theme.AppCompat.Light.DarkActionBar">
used to wirk with Theme.Material.Light.DarkActionBar
I already cleaned and rebuild the project, but it always goes back to showing me errors about a missing parent.
As far as I could gather from similar questions, all relevant libraries are included and all use the newest version available.
I also tried manually adding the libraries to the libs/ folder with no success.
My SDK manager shows that everything is installed and up to date.
What am I missing here?
Thanks in advance for your time.
Solution:
It was actually rather simple. I referred to Theme.AppCompat with the android namespace, but should have left it out, so, instead of
#android:style/Theme.AppCompat
it should be
#style/Theme.AppCompat
This did show another error initially, about "Theme" not being found, but it compiled non the less.

No resource found that matches the given name '#android:style/theme.AppCompat

I've viewed a ton of posts regarding this issue, but everything here checks out.
Code:
Actionbar:
<style name="CustomActionBarTheme"
parent="#android:style/Theme.AppCompat">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
Gradle:
compileSdkVersion 'android-L'
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 8
targetSdkVersion 'android-L'
versionCode 1
versionName '1.0'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:21+'
compile 'com.android.support:support-v4:20+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.http-client:google-http-client-jackson2:1.18.0-rc'
compile 'com.google.apis:google-api-services-calendar:v3-rev75-1.17.0-rc'
compile 'com.google.api-client:google-api-client-android:1.17.0-rc'
compile 'com.google.http-client:google-http-client-gson:1.17.0-rc'
compile 'com.google.apis:google-api-services-oauth2:v2-rev63-1.17.0-rc'
compile 'com.google.android.gms:play-services:3.1.+'
compile files('libs/app-AppEngine-endpoints-android.jar')
}
Using Android Studio
YES I have support library installed
YES I have tried moving SDK versions all the way up to sdk-18
EDIT
Ctrl-Clicking on the ".../Theme.AppCompat" takes me to the correct lines in values.xml, see below:
<style name="Theme.AppCompat" parent="Theme.Base.AppCompat">
<item name="isLightTheme">false</item>
<!-- Required for use of support_simple_spinner_dropdown_item.xml -->
<item name="spinnerDropDownItemStyle"> #style/Widget.AppCompat.DropDownItem.Spinner</item>
<item name="dropdownListPreferredItemHeight">?attr/listPreferredItemHeightSmall</item>
<item name="searchResultListItemHeight">58dip</item>
Changing this to parent="#style/Theme.AppCompat" causes an error, but by defining that theme in "styles" I managed to fix it at it worked as intended.
I think it's your use of the #android prefix that's causing the problem. I struggled with it for ages until I found this answer:
https://stackoverflow.com/a/19507892/1123654

No resource found that matches the given name 'android:Theme.Material.Light.DarkActionBar'

I try to change my HelloWorld Application holo theme to Material.Light.DarkActionBar theme(As said by What's new Android Development tools session). But I got following error. I try to change target SDK version is 21. But We didn't have 21 SDK in SDK Manager. In that session,they said,set style xml for v-21.
values/styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
values-v21/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.ramapps.helloworld"
minSdkVersion 15
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Error:
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material.Light.DarkActionBar'.
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Applications/Android Studio.app/sdk/build-tools/android-4.4W/aapt package -f --no-crunch -I /Applications/Android Studio.app/sdk/platforms/android-20/android.jar -M /Users/Ram_PC/Ram/MyDrive/My_Workspaces/Android_Studio_Workspace_L/HelloWorld/app/build/intermediates/manifests/debug/AndroidManifest.xml -S /Users/Ram_PC/Ram/MyDrive/My_Workspaces/Android_Studio_Workspace_L/HelloWorld/app/build/intermediates/res/debug -A /Users/Ram_PC/Ram/MyDrive/My_Workspaces/Android_Studio_Workspace_L/HelloWorld/app/build/intermediates/assets/debug -m -J /Users/Ram_PC/Ram/MyDrive/My_Workspaces/Android_Studio_Workspace_L/HelloWorld/app/build/generated/source/r/debug -F /Users/Ram_PC/Ram/MyDrive/My_Workspaces/Android_Studio_Workspace_L/HelloWorld/app/build/intermediates/libs/app-debug.ap_ --debug-mode --custom-package com.ramapps.helloworld -0 apk
Error Code:
1
Output:
/Users/Ram_PC/Ram/MyDrive/My_Workspaces/Android_Studio_Workspace_L/HelloWorld/app/build/intermediates/res/debug/values-v21/values.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material.Light.DarkActionBar'.
You can try to set the values in the build.gradle like this (updated for API 25):
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 21 //oldest version you would like to support
targetSdkVersion 25
versionCode 1
versionName "1.0"
...
}
}
We can not install apps that target L Preview on anything but L devices.
Changing res/values/styles.xml, Theme.Material.Light to Theme.Light and following build.gradle worked for me.
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
defaultConfig {
applicationId 'com.example.android.market.licensing'
minSdkVersion 13
targetSdkVersion 20
versionCode 1
versionName '1.0'
}
Although Theme.Material.Light is part of the 20sdk version but somehow it is not working for me.
Set Target of Your Application to API Level 21 from AssemblyMenifest.xml or add <uses-sdk android:targetSdkVersion="21" android:minSdkVersion="19" /> tag to your AssemblyMenifest.xml
I changed Theme.Material.Light to Theme.Light and it worked for me.
I think the problem here is that you need to set your buildToolsVersion to pre Android L version.
Here my gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "com.mayuonline.ribbit"
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile 'com.android.support:support-v13:19.+'
}
Also make sure to change the styles.xml as below
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Light">
</style>
</resources>
This should resolve the problem.

Categories

Resources