Hi. The following are the steps that I have taken to upgrade an app to Xamarin Forms 4.5+ and AndroidX.
It looks OK until near the end where I get errors but I do not know why. I did not get them before. Are they due to AndroidX or something else.
I have:
1) installed VS 2019 16.5.1
2) installed XF 4.5.0.495
3) in Tools->Options->Xamarin->Android Settings, I have checked Enable AndroidX Migrator (Experimental)
3) right click on the android project and select Migrate to AndroidX
That is all looking good. Now try:
4) run in debug in droid on a real phone.
get the following message:
Severity Code Description Project File Line Suppression State
Error Could not find 3 Android X assemblies, make sure to install the following NuGet packages:
- Xamarin.AndroidX.MediaRouter
You can also copy-and-paste the following snippet into your .csproj file:
<PackageReference Include="Xamarin.AndroidX.MediaRouter" Version="1.1.0" />
Hmmm... my droid.csproj file does not have lines with PackageReference on them. So, I will try to install the nuget.
The nuget installed fine. When I checked the droid.csproj file, it had the following new lines:
<Reference Include="Xamarin.AndroidX.MediaRouter, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xamarin.AndroidX.MediaRouter.1.0.0\lib\monoandroid90\Xamarin.AndroidX.MediaRouter.dll</HintPath>
</Reference>
So maybe those replace the PackageReference lines.
Try running again.
Now I get the message:
Severity Code Description Project File Line Suppression State
Error Could not find 1 Android X assemblies, make sure to install the following NuGet packages:
- Xamarin.AndroidX.AppCompat.Resources
You can also copy-and-paste the following snippet into your .csproj file:
<PackageReference Include="Xamarin.AndroidX.AppCompat.Resources" Version="1.1.0" /> i_TraxMobile.Droid
Ok. Try installing the nuget.
But wait! it is installed already - according to the nuget installer.
Looking in the .csproj, it is not there.
I do find
<Reference Include="Xamarin.AndroidX.AppCompat,...
and so I make a copy of the three lines and make it look like it belongs to Xamarin.AndroidX.AppCompat.Resources.
<Reference Include="Xamarin.AndroidX.AppCompat.Resources, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xamarin.AndroidX.AppCompat.Resources.1.1.0\lib\monoandroid90\Xamarin.AndroidX.AppCompat.Resources.dll</HintPath>
</Reference>
Close VS.
Reopen the solution in VS.
Run it.
Get a bunch of errors.
Severity Code Description Project File Line Suppression State
Error resource style/Theme.AppCompat.Light.NoActionBar (aka com.itraxonline.itraxmobile:style/Theme.AppCompat.Light.NoActionBar) not found. i_TraxMobile.Droid
Error resource style/Theme.AppCompat.Light.Dialog (aka com.itraxonline.itraxmobile:style/Theme.AppCompat.Light.Dialog) not found. i_TraxMobile.Droid
Error failed linking references. i_TraxMobile.Droid
Error resource style/Theme.AppCompat.Light.DarkActionBar (aka com.itraxonline.itraxmobile:style/Theme.AppCompat.Light.DarkActionBar) not found. i_TraxMobile.Droid
Error resource style/Theme.AppCompat.Light.NoActionBar (aka com.itraxonline.itraxmobile:style/Theme.AppCompat.Light.NoActionBar) not found. i_TraxMobile.Droid
Error style attribute 'attr/windowNoTitle (aka com.itraxonline.itraxmobile:attr/windowNoTitle)' not found. i_TraxMobile.Droid C:\Users\Will\source\repos\main\i-TraxMobile\i_TraxMobile.Droid\Resources\values\styles.xml 2
Error style attribute 'attr/colorPrimaryDark (aka com.itraxonline.itraxmobile:attr/colorPrimaryDark)' not found. i_TraxMobile.Droid C:\Users\Will\source\repos\main\i-TraxMobile\i_TraxMobile.Droid\Resources\values\styles.xml 2
Error style attribute 'attr/windowActionBar (aka com.itraxonline.itraxmobile:attr/windowActionBar)' not found. i_TraxMobile.Droid C:\Users\Will\source\repos\main\i-TraxMobile\i_TraxMobile.Droid\Resources\values\styles.xml 2
Error style attribute 'attr/colorPrimary (aka com.itraxonline.itraxmobile:attr/colorPrimary)' not found. i_TraxMobile.Droid C:\Users\Will\source\repos\main\i-TraxMobile\i_TraxMobile.Droid\Resources\values\styles.xml 2
Error style attribute 'attr/colorAccent (aka com.itraxonline.itraxmobile:attr/colorAccent)' not found. i_TraxMobile.Droid C:\Users\Will\source\repos\main\i-TraxMobile\i_TraxMobile.Droid\Resources\values\styles.xml 3
Error style attribute 'attr/colorAccent (aka com.itraxonline.itraxmobile:attr/colorAccent)' not found. i_TraxMobile.Droid C:\Users\Will\source\repos\main\i-TraxMobile\i_TraxMobile.Droid\Resources\values\styles.xml 4
Error style attribute 'attr/windowActionModeOverlay (aka com.itraxonline.itraxmobile:attr/windowActionModeOverlay)' not found. i_TraxMobile.Droid C:\Users\Will\source\repos\main\i-TraxMobile\i_TraxMobile.Droid\Resources\values\styles.xml 4
Where did they come from? Ok - so they came from styles.xml. But why??
Here is the styles.xml file.
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="MainTheme" parent="MainTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
<item name="windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#2196F3</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#1976D2</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<!--<item name="colorAccent">#FF4081</item>-->
<item name="colorAccent">#00CC00</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight and colorSwitchThumbNormal. -->
<item name="windowActionModeOverlay">true</item>
<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
</style>
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#FF4081</item>
</style>
<!-- Following added for splash screen-->
<!-- from http://lukealderton.com/blog/posts/2016/august/xamarin-forms-splash-screen-on-android-and-ios.aspx -->
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
</style>
<style name="MyTheme" parent="MyTheme.Base">
</style>
<style name="MyTheme.Splash" parent="Theme.AppCompat.Light.NoActionBar">
<!--<item name="android:windowBackground">@drawable/splash</item>-->
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
Any insight regarding the AndroidX migration steps or how to fix these final errors are greatly appreciated.