Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XF Android project does not build after adding Xamarin.Forms.Visual.Material nuget

I have a Xamarin Forms project and now I'd like to improve it with the new Visual / Material features.

On IOS, it works like a charm.

On Android I have strange problems: after adding Xamarin.Forms.Visual.Material nuget I get weird error messages and my project does not build:

\res\values\values.xml(6): error APT0000: Attribute "statusBarBackground" already defined with incompatible format.
\res\values\values.xml(2): error APT0000: Original attribute defined here.
\res\values\values.xml(10): error APT0000: Attribute "layout_anchorGravity" already defined with incompatible format.
\res\values\values.xml(2): error APT0000: Original attribute defined here.
\res\values\values.xml(17): error APT0000: Attribute "layout_insetEdge" already defined with incompatible format.
\res\values\values.xml(2): error APT0000: Original attribute defined here.
\res\values\values.xml(17): error APT0000: Attribute "layout_dodgeInsetEdges" already defined with incompatible format.
\res\values\values.xml(2): error APT0000: Original attribute defined here.
\res\values\styles.xml(2): error APT0000: Error retrieving parent for item: No resource found that matches the given name 'Theme.MaterialComponents.Light.DarkActionBar'.
\res\values\styles.xml(2): error APT0000: No resource found that matches the given name: attr 'materialButtonStyle'.
\res\values\styles.xml(2): error APT0000: Error retrieving parent for item: No resource found that matches the given name 'Widget.MaterialComponents.Button'.
\res\values\styles.xml(2): error APT0000: Error retrieving parent for item: No resource found that matches the given name 'Widget.MaterialComponents.Button.OutlinedButton'.
\res\values\styles.xml(2): error APT0000: Error retrieving parent for item: No resource found that matches the given name 'Widget.MaterialComponents.TextInputLayout.FilledBox'.
\res\values\styles.xml(2): error APT0000: No resource found that matches the given name: attr 'boxCollapsedPaddingTop'.

I use Visual Studio 2017 Professional on Windows, I don't use any prerelease nuget.

Xamarin.Forms version is 3.6.0.293080. Minimum Android API level is 21, target is 28, and compiled with 28. Xamarin Android support libraries version is 28.0.0.1.

I tried the usual tricks (delete bin, obj dir, restart Visual Studio, run it in admin mode, delete Xamarin app data...) but neither helped.

The same thing happens if I create a new project from schratch, and don't do anything with it, just add visual.material nuget to the Android project.

Do you have any suggestions? Thanks a lot!

like image 319
Tom Avatar asked Dec 07 '22 12:12

Tom


1 Answers

I had the same issue a few days ago where I first had TargetFramework set to Android 8.1, installed same packages and later changed it to Android9 and installed a new package.

The Xamarin.Forms.Visual.Material requires Android 9 to be set in Android project options and you previously had 8.1 configured and installed nuget packages for Android 8.1.

If you still use old packages.config like me to add NuGet packages, make sure you always see same monodroid string in hint path in the csproj and don't mix 81 with 90 and always have monoandroid90.

<Reference Include="Xamarin.Forms.Visual.Material , Version=3.6.0.293080, Culture=neutral, processorArchitecture=MSIL">
     <HintPath>..\..\packages\Xamarin.Forms.Material.3.6.0.293080\lib\monoandroid90\Xamarin.Forms.Material.dll</HintPath>
</Reference>

After changing TargetFramework to 9, open Package Manager Console and run

Update-Package -Reinstall -IgnoreDependencies

to let VS update the packages.config and csproj.

like image 152
magicandre1981 Avatar answered Dec 11 '22 12:12

magicandre1981