- 3 minutes to read
DevExpress controls now use the AndroidX library instead of the Android Support Library in our v20.2 release cycle. This means that you should assign corresponding dependencies (NuGet packages or assembly references) to the project. To learn more about the AndroidX library, see the following topic on developer.android.com: AndroidX Overview.
This topic shows how to migrate from the Android Support Library to the AndroidX library in an application that uses Xamarin.Forms. For general information about migration to AndroidX, see the following topic on docs.microsoft.com: AndroidX migration in Xamarin.Forms.
The application should meet the following requirements to be able to use the AndroidX library:
- Target Android API version 29 or greater.
- Use the Xamarin.Forms package v4.5 or greater.
You can check the target Android API version in the project settings. In Solution Explorer, right-click the Android project. In the context menu, click Properties.
In the opened window, select Android Manifest and check Target Android version.
In Solution Explorer, check the main project’s Xamarin.Forms version.
To update the Xamarin.Forms package, right-click Packages, and click Manage NuGet Packages.
In the opened NuGet window, find the Xamarin.Forms package, select the required version, and click Update.
Use AndroidX Migrator to switch the Android Support Library to AndroidX automatically. Before you migrate, update your project to use Android Support Library 28.0.0 and ensure you have the latest version of Visual Studio 2019 installed.
We recommend that you back up your project before migration to AndroidX.
In Visual Studio’s Tools menu, open the Options window.
In the Android Settings section, check the Enable AndroidX Migrator option.
In Solution Explorer, right-click the Android project and click Migrate to AndroidX.
The migration process replaces the Android Support Library with the AndroidX library.
After the migration is completed, you can remove the Xamarin.AndroidX.Migration package.
Update the Code
After the migration is completed, you may need to remove the
using statements that refer to namespaces in the Android Support Library.
You can use Quick Actions to remove unnecessary lines. Click the light bulb and then click Remove Unnecessary Usings.
You can also press Ctrl+. when your cursor is on the line of code to invoke Quick Actions.
You should also update your code so it refers to classes in the AndroidX library instead of classes in the Android Support Library.
For example, the
android.support.v7.widget.Toolbar class is replaced with
androidx.appcompat.widget.Toolbar. In the image below, the code is updated accordingly.
See the following topic on developer.android.com for more information: Class Mappings.