Style references to Theme.AppCompat… stopped working after updating Xamarin Studio

SteveShaw.5557SteveShaw.5557 USMember ✭✭✭
edited February 2017 in Xamarin.Android

[No response on stackoverflow, so moved the post to here.]

On a Xamarin.Android project that was working fine (on emulators, real devices, released to Google Play Store), recent upgrade of Xamarin Studio and/or referenced Android SDK caused build errors in Resources/values/Styles.xml, on the theme on the main activity.

Styles.xml starts with:

<?xml version="1.0" encoding="UTF-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="MyTheme" parent="Theme.MyTheme">
    </style>
    <style name="Theme.MyTheme" parent="@style/Theme.AppCompat.NoActionBar">
        <item name="windowNoTitle">true</item>
        <item name="android:windowActionBarOverlay">false</item>

Styles.xml generates ten errors on these two elements and their sub-items:

Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.NoActionBar'.
Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.Light.Dark.ActionBar
.. similar errors, referring to Theme.AppCompat.. ThemeOverlay.AppCompat.., Widget.AppCompat..

Project includes up-to-date packages

Xamarin.Android.Support.Compat
Xamarin.Android.Support.Core.. etc
Xamarin.Android.Support.v4
Xamarin.Android.Support.v7.CardView

(not bothering to list exactly all the projects, as this has been working without problems for over a year)

"References / From Packages" also lists all those "Support" packages.

Android SDK Manager:

Android SDK Tools - 25.2.5
Android SDK Platform-tools - 25.0.3
Android 7.1.1 (API 25)
. SDK Platform - API 25, Rev 3
Google APIs Intel x86 Atom System Image - API 25, Rev 3
.. various older stuff ..
Android Support Repository - 44
. NOTE: that wasn't originally installed, as we use Xamarin.Android.Support projects instead; but added it as one attempt to fix these errors.

Minimum SDK: API 21.
Target SDK: API 25.
NOTE: Our minimum is now 21, so we could be referring to "Theme.Material" rather than "Theme.AppCompat". However, that should not matter - and I tried that change, with no improvement. Tried various combinations just in case:

="Theme.AppCompat.NoActionBar"
="@style/Theme.AppCompat.NoActionBar"
="@android:Theme.AppCompat.NoActionBar"
="@android:style/Theme.AppCompat.NoActionBar"

="Theme.Material.NoActionBar"
="@style/Theme.Material.NoActionBar"
="@android:Theme.Material.NoActionBar"

.. no change. So it isn't like some change in configuration or API target changed HOW we need to refer to this (I might have changed minimum or target API while trying to get this to work; I'm a bit vague as to whether should stop using AppCompat; and as you can see, I'm vague on when to use "android:" and "@style/") .. its as if Theme.Material and Theme.AppCompat are not there at all.

Cleaned project, Rebuilt, rebooted pc .. I've done everything except "reinstall" xamarin studio and android. Which I hesitate to do, because that seems to waste half a day or more, getting every detail right, including the paths as we expect them, and associated technologies such as Intel HAXM.

(Reinstall will be my next attempt, but I'd rather find out WHAT has happened. Besides, reinstall won't fix it, if it is a problem with updated stuff, or with some configuration detail I've overlooked.)

What else can I check/update/try-different-settings?

Tagged:

Best Answers

  • SteveShaw.5557SteveShaw.5557 US ✭✭✭
    edited February 2017 Accepted Answer

    Thanks for the suggestions.

    It turned out that the .csproj no longer had some references that it used to have.

    I discovered this by SVN-checkout of an older version of my project in a new folder. That version built and ran (with older package references), AND it continued to build+run after those packages were updated. Proving that it wasn't something messed up in either Android SDK or updated packages. Comparing working to non-working project files, I was able to find the difference.

    (I was going to link to the stackoverflow post, but I decided that wasn't the best place to get an answer to this, so I deleted that question.)

    (Re minimum API 21 - yes, I mentioned in my post that since that was now our minimum, we no longer needed to use AppCompat, BUT that I tried replacing references to AppCompat with equivalent references to Material, without success.)

  • SteveShaw.5557SteveShaw.5557 US ✭✭✭
    edited February 2017 Accepted Answer

    [Somehow accidentally deleted my answer. Even though I had already posted it, and then accepted it as the answer! It did not ask me to confirm that deletion, nor is there a way to get back a deleted answer. So posting it again, but without all the interesting details.]

    Thanks for the suggestions. Resolved it by SVN checkout of older versions of project, until found one that worked, then comparing files between working and non-working versions. Somehow the project .csproj no longer had some references that were needed.

    So, the update of xamarin was a red herring. Next time I will clean/rebuild before ANY update, to make sure everything is working. Having lost a day to this, I will also COPY the entire project folder before updating anything I am dependent on, so I have something working to compare to. I haven't been bothering, because I know SVN has a working copy.

    (No link only because I had already removed the stackoverflow post, because there were no responses in 24 hours, so I decided whatever the problem turned out to be, it wasn't likely to be of broad interest, so better on this xamarin forum.)

Answers

  • JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai
    edited February 2017

    First off, please post your Stack Overflow question in your forum post just so other people can prevent duplicate work in-case it gets answered.

    There's a couple of thoughts that I would like you to think about here:

    Minimum SDK: API 21.
    Target SDK: API 25.

    1. If your minimum SDK is API 21 and the Material Theme was introduced in Lollipop (API 21), why is there a need to use AppCompat themes given you aren't supporting any API older than that?

    2. How do you think items get compiled in for each SDK? Do you think APIs >= 21 need to include much from the AppCompat packages?

    In other words, read this section:

    https://developer.android.com/topic/libraries/support-library/index.html#framework-apis

    There is a pretty extensive sample that gets updated normally that should show these concepts here:

    https://github.com/xamarin/monodroid-samples/tree/master/android5.0/Cheesesquare

    Some things to look at:

    1. Is the resource being generated in your Resource.designer.cs file?

    2. Do you have all of the proper .csproj properties? (Compare to a sample like cheesesquare)

    3. Ensure you do a deep clean in terms of nuking the bin/obj folders and rebuilding.

  • SteveShaw.5557SteveShaw.5557 USMember ✭✭✭
    edited February 2017 Accepted Answer

    Thanks for the suggestions.

    It turned out that the .csproj no longer had some references that it used to have.

    I discovered this by SVN-checkout of an older version of my project in a new folder. That version built and ran (with older package references), AND it continued to build+run after those packages were updated. Proving that it wasn't something messed up in either Android SDK or updated packages. Comparing working to non-working project files, I was able to find the difference.

    (I was going to link to the stackoverflow post, but I decided that wasn't the best place to get an answer to this, so I deleted that question.)

    (Re minimum API 21 - yes, I mentioned in my post that since that was now our minimum, we no longer needed to use AppCompat, BUT that I tried replacing references to AppCompat with equivalent references to Material, without success.)

  • SteveShaw.5557SteveShaw.5557 USMember ✭✭✭
    edited February 2017 Accepted Answer

    [Somehow accidentally deleted my answer. Even though I had already posted it, and then accepted it as the answer! It did not ask me to confirm that deletion, nor is there a way to get back a deleted answer. So posting it again, but without all the interesting details.]

    Thanks for the suggestions. Resolved it by SVN checkout of older versions of project, until found one that worked, then comparing files between working and non-working versions. Somehow the project .csproj no longer had some references that were needed.

    So, the update of xamarin was a red herring. Next time I will clean/rebuild before ANY update, to make sure everything is working. Having lost a day to this, I will also COPY the entire project folder before updating anything I am dependent on, so I have something working to compare to. I haven't been bothering, because I know SVN has a working copy.

    (No link only because I had already removed the stackoverflow post, because there were no responses in 24 hours, so I decided whatever the problem turned out to be, it wasn't likely to be of broad interest, so better on this xamarin forum.)

Sign In or Register to comment.