Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Android: Error APT0000: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.AppCompat'

I'm trying to use the CoordinatorLayout in my Xamarin.Android app. I've been using a custom theme with Theme.Material.Light as its parent, which worked fine before I added the CoordinatorLayout. When I add it, I get an error telling me I have to use a Theme.AppCompat theme, but as soon as I do the app fails to build and gives me the following error:

/{project directory}/Resources/values/Styles.xml(0,0):
Error APT0000: Error retrieving parent for item:
No resource found that matches the given name 
'@android:style/Theme.AppCompat'. (APT0000) (TnpApp.Android)

This answer suggests installing the major version of the support library that matches the Android SDK I'm using. I've tried this (I think I did everything correctly), but it doesn't help.

Does anyone have any ideas?

I'm using Xamarin Studio on Mac.

UPDATE 1

I tried the following code in MainActivity.cs in a clean Xamarin.Android project, and build fails with the same error.

namespace ThemeTest
{
    [Activity(Label = "ThemeTest", MainLauncher = true, Icon = "@mipmap/icon", Theme = "@android:style/Theme.AppCompat.Light")]
    public class MainActivity : Activity
    {
        // ...
    }
}

UPDATE 2

I removed all the folders from /user/.local/share/Xamarin except for Mono for Android and zips as suggested in this answer. I closed Xamarin Studio and reopened it. I tried to deploy the app, and Xamarin reinstalled all the packages but the build failed with the original error.

like image 763
Jonathan Avatar asked Jan 13 '17 19:01

Jonathan


1 Answers

I was able to fix this problem by simply removing @android:style/ from the style element's parent tag in my Styles.xml file. So what looked like this...

<style name="MyCustomTheme" parent="@android:style/Theme.AppCompat">

Now looks like this...

<style name="MyCustomTheme" parent="Theme.AppCompat">

I'm shocked the solution is this simple, but it works. :) I got the idea from this code.

like image 89
Jonathan Avatar answered Sep 19 '22 15:09

Jonathan