VS2017 15.5.5配置Xamarin Android4.1项目遇错误求解决方案
Hey there, let's work through this step by step to get your Xamarin Android project running smoothly for Android 4.1+ on VS2017 15.5.5. Here's a straightforward configuration plan tailored to your situation:
Start with a fresh slate to eliminate cached issues:
- Right-click your solution → Select
Clean Solution - Manually delete the
binandobjfolders from your Android project directory (these hold compiled artifacts that often cause conflicts) - Restart Visual Studio to clear any in-memory cache
The mistake here was lowering the target framework to Android 4.1—modern support libraries don't work with such old frameworks. Instead:
- Right-click your Android project → Open
Properties - Go to the
Applicationtab:- Minimum Android version: Set to
Android 4.1 (API Level 16)(this covers your required compatibility) - Target framework: Choose
Android 8.1 (API Level 27)(this is a stable version that works well with VS2017 15.5.5 and maintains backward compatibility with 4.1) - Target Android version: Select "Use compile using Android version (API 27)" (matches your target framework)
- Minimum Android version: Set to
The Xamarin.Android.Support.Design package error comes from mismatched or outdated support library versions. Here's how to fix it:
- Open NuGet Package Manager (right-click project →
Manage NuGet Packages) - Go to the
Installedtab, uninstall allXamarin.Android.Support.*packages (including Design, Library, AppCompat, etc.) - Switch to the
Browsetab, search forXamarin.Android.Support.Libraryand install version 27.0.2.1 (this version is fully compatible with VS2017 15.5.5 and API 27)- Ensure all support packages you install are the same version—never mix different versions
- If you still see NU1202 errors, open the NuGet Package Console and run:
This forces a fresh install of all packages with correct dependencies.Update-Package -reinstall
You deleted some critical files earlier—let's bring back the basics without extra bloat:
- Create a new
Toolbar.axmlfile inResources/layoutwith this default content:<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorPrimary" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" android:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> - Ensure
Resources/values/styles.xmlhas a basic AppCompat theme:<resources> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> </resources> - Check that
Resources/values/colors.xmlexists with defined color values (e.g.,<color name="colorPrimary">#3F51B5</color>) to avoid "resource not found" errors.
- Right-click your solution → Select
Rebuild Solution - If you still see resource identifier errors, double-check all layout files for typos in control IDs, then run
Clean Solutionagain before rebuilding.
This setup keeps your project compatible with Android 4.1+ while using a modern enough framework to support necessary libraries, eliminating the compatibility and resource errors you're facing.
内容的提问来源于stack exchange,提问作者Jiri Stepanek

