7

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.

Community
  • 1
  • 1
Jonathan
  • 648
  • 4
  • 13
  • 34

3 Answers3

3

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.

Jonathan
  • 648
  • 4
  • 13
  • 34
2

I'm developing in Visual Studio 2015/Xamarin and saw this same problem. While I still don't understand the cause or the fix for this problem, this thread did point me in the right direction which seems to have more to do with resaving styles.xml (for my development environment) than anything else.

My styles.xml did not have @android:style/ and I still had the error mentioned above. As described in another proposed solution, I added

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

before <style name="MyCustomTheme" parent="Theme.AppCompat">, saved styles.xml and rebuilt my project without errors. I then removed

<style name="MyCustomTheme.Base" parent="Theme.AppCompat" />,

resaved styles.xml and rebuilt with no errors. Visually, my styles.xml is unchanged, but the error is gone.

Tony
  • 363
  • 2
  • 8
1

If you recently installed a google play service related package (firebase for example , but there are many others) , it is possible that this installation messed up with your CSproj and your package.json files (look at your version control history to see if these files were changed), and modified your target api version : Going from target Api 25 to Target 26 for exemple etc.

If this is the case , you should adresse this problem one of two ways :

  • make sure you download the sdk version that you are now targeting , to do this , go to TOOLS > SDK manager.

  • or revert back to your old target , by discarding the change the package made to you csproj and package.json files and clean and rebuild.

ezzou
  • 2,348
  • 1
  • 15
  • 16