.NET MAUI Android Error: Type androidx.collection.ArrayMapKit is defined multiple times

One common challenge is AndroidX dependency conflicts. In this blog post, we’ll guide you through resolving compilation errors related to AndroidX in .NET MAUI. Before we proceed, let’s take a look at the error message that may have troubled you:

/Users/Username/Documents/src/ProjectFolder/Project: Error JAVA0000: Error in /Users/Username/.nuget/packages/xamarin.androidx.collection.jvm/1.3.0.1/buildTransitive/net6.0-android31.0/../../jar/androidx.collection.collection-jvm.jar:androidx/collection/ArrayMapKt.class:
Type androidx.collection.ArrayMapKt is defined multiple times: /Users/Username/.nuget/packages/xamarin.androidx.collection.jvm/1.3.0.1/buildTransitive/net6.0-android31.0/../../jar/androidx.collection.collection-jvm.jar:androidx/collection/ArrayMapKt.class, /Users/Username/.nuget/packages/xamarin.androidx.collection.ktx/1.2.0.5/buildTransitive/net6.0-android31.0/../../jar/androidx.collection.collection-ktx.jar:androidx/collection/ArrayMapKt.class
Compilation failed
java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: /Users/Username/.nuget/packages/xamarin.androidx.collection.jvm/1.3.0.1/buildTransitive/net6.0-android31.0/../../jar/androidx.collection.collection-jvm.jar
androidx/collection/ArrayMapKt.class

In my case the meaning of this error message is: Type androidx.collection.ArrayMapKt is defined multiple times

Examine Dependencies and Manually Delete bin and obj Folders:

Start by inspecting your project’s dependencies. Ensure that you have the same versions of .NET MAUI packages and other libraries. Dependency mismatches can often lead to compilation errors.

Sometimes, cleaning your project isn’t enough.
To ensure a fresh build, you might need to manually delete the bin and obj folders. You can find these folders in your project directory. They contain build artifacts and removing them helps clear cached data.

Verify NuGet Packages:

Review your NuGet packages. Look out for multiple versions of the same library, as this can lead to conflicts. If you find any conflicting packages, remove the outdated or conflicting versions. You may need to edit your project’s .csproj file to resolve these package issues.

Additionally, if you’ve recently installed a new NuGet package with has an Android dependency, make sure you have the correct version. A different version might introduce incompatibilities with the already installed pacakages.

This content has 6 months. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Android: Get keys signature from keystore

On Windows change directory to:

C:\Program Files (x86)\Java\jre1.8.0_271\bin

Give out the following command for keytool

keytool -list -keystore "C:\source_to_keystorw\keystorefilename.keystore" -storepass supersecurepassword

Results the following:

Keystore type: jks
Keystore provider: SUN

Your keystore contains 1 entry

com.companyname.projectname.appdeliverykey, 2021.05.20., PrivateKeyEntry,
Certificate fingerprint (SHA-256): 44:58:C2:B6:84:0A:9C:E0:09:8A:DD:ED:8C:EC:E7:BD:3D:0F:CC:17:32:BC:77:D6:BB:32:E8:5B:43:25:84:DF

This content has 2 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Xamarin.Android: R.java error APT2258 invalid symbol name fix

If you are facing this issue:

R.java : error APT2258: invalid symbol name 'com.companyname.appname:drawable/xxxx'.

You should check for your Resources folder, and look for files with name like a C# or Java keyword. For example: new, public, private, static, class, and so on.

If you rename the file, it will solve your problem.

This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Xamarin.Android: Missing aapt.exe

When trying to deploy an application to simulator or device, Visual Studio gives the following error:

Cannot find `aapt.exe`. Please install the Android SDK Build-Tools package with the `C:\Program Files (x86)\Android\android-sdk\tools\android.bat` program.

To solve this problem you sould go to Visual Studio’s Tools then Android and select SDK Manager option.

Navigate to this option

It will give an error dialog, that the SDK tool files are corrupted. Click repair.

Click on Repair

The mentioned batch command in the error message is deprecated by the way.

Microsoft Windows [Version 10.0.19042.804]
(c) 2020 Microsoft Corporation. All rights reserved.

C:\Users\banditoth>cd C:\Program Files (x86)\Android\android-sdk\tools\

C:\Program Files (x86)\Android\android-sdk\tools>android.bat
**************************************************************************
The "android" command is deprecated.
For manual SDK, AVD, and project management, please use Android Studio.
For command-line tools, use tools\bin\sdkmanager.bat
and tools\bin\avdmanager.bat
**************************************************************************

Invalid or unsupported command ""

Supported commands are:
android list target
android list avd
android list device
android create avd
android move avd
android delete avd
android list sdk
android update sdk

C:\Program Files (x86)\Android\android-sdk\tools>

This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.