dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.93k stars 525 forks source link

[.NET 6] Failure building Android project with tools:replace="android:appComponentFactory" #5750

Closed jeromelaban closed 3 years ago

jeromelaban commented 3 years ago

Steps to Reproduce

No clear steps to reproduce, aside from building a larger Xamarin.Android app.

Expected Behavior

No build error.

Actual Behavior

7>\Microsoft.Android.Sdk.win-x64\11.0.200-ci.main.148\tools\Xamarin.Android.Common.targets(1447,3): error AMM0000: obj\Debug\net6.0-android\lp\104\jl\AndroidManifest.xml Warning:
7>SamplesApp.net6mobile\obj\Debug\net6.0-android\lp\104\jl\AndroidManifest.xml warning :
7>\Microsoft.Android.Sdk.win-x64\11.0.200-ci.main.148\tools\Xamarin.Android.Common.targets(1447,3): error AMM0000:     Package name 'android.support.graphics.drawable' used in: AndroidManifest.xml, AndroidManifest.xml.
7>\Microsoft.Android.Sdk.win-x64\11.0.200-ci.main.148\tools\Xamarin.Android.Common.targets(1447,3): error AMM0000: obj\Debug\net6.0-android\lp\1\jl\AndroidManifest.xml Warning:
7>SamplesApp.net6mobile\obj\Debug\net6.0-android\lp\1\jl\AndroidManifest.xml warning :
7>\Microsoft.Android.Sdk.win-x64\11.0.200-ci.main.148\tools\Xamarin.Android.Common.targets(1447,3): error AMM0000:     Package name 'androidx.versionedparcelable' used in: AndroidManifest.xml, AndroidManifest.xml.
7>\Microsoft.Android.Sdk.win-x64\11.0.200-ci.main.148\tools\Xamarin.Android.Common.targets(1447,3): error AMM0000: obj\Debug\net6.0-android\AndroidManifest.xml:19:92-165 Error:
7>\Microsoft.Android.Sdk.win-x64\11.0.200-ci.main.148\tools\Xamarin.Android.Common.targets(1447,3): error AMM0000:     Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from AndroidManifest.xml:19:92-165
7>\Microsoft.Android.Sdk.win-x64\11.0.200-ci.main.148\tools\Xamarin.Android.Common.targets(1447,3): error AMM0000:     is also present at AndroidManifest.xml:24:18-86 value=(androidx.core.app.CoreComponentFactory).
7>\Microsoft.Android.Sdk.win-x64\11.0.200-ci.main.148\tools\Xamarin.Android.Common.targets(1447,3): error AMM0000:     Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:19:3-40:17 to override.

This is a type of error that I've not seen before, and it's a mix of warning and errors for which the resolution path in not obvious, even when adding tools:replace="android:appComponentFactory"

Version Information

.NET 6 Preview 2

Log File

jonathanpeppers commented 3 years ago

Can you attach a .binlog? Thanks.

jeromelaban commented 3 years ago

Here it is: msbuild.zip

Thanks!

jonathanpeppers commented 3 years ago

@jeromelaban it looks like this project is mixing Android Support & AndroidX:

...\.nuget\packages\xamarin.android.arch.core.common\1.1.1.1\lib\monoandroid90\Xamarin.Android.Arch.Core.Common.dll
...\.nuget\packages\xamarin.android.arch.core.runtime\1.1.1.1\lib\monoandroid90\Xamarin.Android.Arch.Core.Runtime.dll
...\.nuget\packages\xamarin.android.arch.lifecycle.common\1.1.1.1\lib\monoandroid90\Xamarin.Android.Arch.Lifecycle.Common.dll
...\.nuget\packages\xamarin.android.arch.lifecycle.livedata\1.1.1.1\lib\monoandroid90\Xamarin.Android.Arch.Lifecycle.LiveData.dll
...\.nuget\packages\xamarin.android.arch.lifecycle.livedata.core\1.1.1.1\lib\monoandroid90\Xamarin.Android.Arch.Lifecycle.LiveData.Core.dll
...\.nuget\packages\xamarin.android.arch.lifecycle.runtime\1.1.1.1\lib\monoandroid90\Xamarin.Android.Arch.Lifecycle.Runtime.dll
...\.nuget\packages\xamarin.android.arch.lifecycle.viewmodel\1.1.1.1\lib\monoandroid90\Xamarin.Android.Arch.Lifecycle.ViewModel.dll
...\.nuget\packages\xamarin.android.support.animated.vector.drawable\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.Animated.Vector.Drawable.dll
...\.nuget\packages\xamarin.android.support.annotations\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.Annotations.dll
...\.nuget\packages\xamarin.android.support.asynclayoutinflater\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.AsyncLayoutInflater.dll
...\.nuget\packages\xamarin.android.support.collections\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.Collections.dll
...\.nuget\packages\xamarin.android.support.compat\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.Compat.dll
...\.nuget\packages\xamarin.android.support.coordinaterlayout\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.CoordinaterLayout.dll
...\.nuget\packages\xamarin.android.support.core.ui\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.Core.UI.dll
...\.nuget\packages\xamarin.android.support.core.utils\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.Core.Utils.dll
...\.nuget\packages\xamarin.android.support.cursoradapter\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.CursorAdapter.dll
...\.nuget\packages\xamarin.android.support.customview\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.CustomView.dll
...\.nuget\packages\xamarin.android.support.documentfile\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.DocumentFile.dll
...\.nuget\packages\xamarin.android.support.drawerlayout\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.DrawerLayout.dll
...\.nuget\packages\xamarin.android.support.fragment\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.Fragment.dll
...\.nuget\packages\xamarin.android.support.interpolator\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.Interpolator.dll
...\.nuget\packages\xamarin.android.support.loader\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.Loader.dll
...\.nuget\packages\xamarin.android.support.localbroadcastmanager\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.LocalBroadcastManager.dll
...\.nuget\packages\xamarin.android.support.print\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.Print.dll
...\.nuget\packages\xamarin.android.support.slidingpanelayout\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.SlidingPaneLayout.dll
...\.nuget\packages\xamarin.android.support.swiperefreshlayout\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.SwipeRefreshLayout.dll
...\.nuget\packages\xamarin.android.support.v7.appcompat\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.v7.AppCompat.dll
...\.nuget\packages\xamarin.android.support.vector.drawable\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.Vector.Drawable.dll
...\.nuget\packages\xamarin.android.support.versionedparcelable\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.VersionedParcelable.dll
...\.nuget\packages\xamarin.android.support.viewpager\28.0.0.1\lib\monoandroid90\Xamarin.Android.Support.ViewPager.dll
...\.nuget\packages\xamarin.androidx.activity\1.2.0.1-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Activity.dll
...\.nuget\packages\xamarin.androidx.annotation\1.1.0.9-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Annotation.dll
...\.nuget\packages\xamarin.androidx.annotation.experimental\1.0.0.9-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Annotation.Experimental.dll
...\.nuget\packages\xamarin.androidx.appcompat\1.2.0.7-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.AppCompat.dll
...\.nuget\packages\xamarin.androidx.appcompat.appcompatresources\1.2.0.7-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.AppCompat.AppCompatResources.dll
...\.nuget\packages\xamarin.androidx.arch.core.common\2.1.0.8-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Arch.Core.Common.dll
...\.nuget\packages\xamarin.androidx.arch.core.runtime\2.1.0.8-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Arch.Core.Runtime.dll
...\.nuget\packages\xamarin.androidx.asynclayoutinflater\1.0.0.7-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.AsyncLayoutInflater.dll
...\.nuget\packages\xamarin.androidx.collection\1.1.0.7-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Collection.dll
...\.nuget\packages\xamarin.androidx.coordinatorlayout\1.1.0.7-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.CoordinatorLayout.dll
...\.nuget\packages\xamarin.androidx.core\1.3.2.3-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Core.dll
...\.nuget\packages\xamarin.androidx.cursoradapter\1.0.0.7-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.CursorAdapter.dll
...\.nuget\packages\xamarin.androidx.customview\1.1.0.6-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.CustomView.dll
...\.nuget\packages\xamarin.androidx.documentfile\1.0.1.7-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.DocumentFile.dll
...\.nuget\packages\xamarin.androidx.drawerlayout\1.1.1.2-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.DrawerLayout.dll
...\.nuget\packages\xamarin.androidx.fragment\1.3.0.1-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Fragment.dll
...\.nuget\packages\xamarin.androidx.interpolator\1.0.0.7-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Interpolator.dll
...\.nuget\packages\xamarin.androidx.legacy.support.core.ui\1.0.0.8-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Legacy.Support.Core.UI.dll
...\.nuget\packages\xamarin.androidx.legacy.support.core.utils\1.0.0.7-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Legacy.Support.Core.Utils.dll
...\.nuget\packages\xamarin.androidx.legacy.support.v4\1.0.0.7-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Legacy.Support.V4.dll
...\.nuget\packages\xamarin.androidx.lifecycle.common\2.3.0.1-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Lifecycle.Common.dll
...\.nuget\packages\xamarin.androidx.lifecycle.livedata\2.3.0.1-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Lifecycle.LiveData.dll
...\.nuget\packages\xamarin.androidx.lifecycle.livedata.core\2.3.0.1-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Lifecycle.LiveData.Core.dll
...\.nuget\packages\xamarin.androidx.lifecycle.runtime\2.3.0.1-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Lifecycle.Runtime.dll
...\.nuget\packages\xamarin.androidx.lifecycle.viewmodel\2.3.0.1-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Lifecycle.ViewModel.dll
...\.nuget\packages\xamarin.androidx.lifecycle.viewmodelsavedstate\2.3.0.1-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Lifecycle.ViewModelSavedState.dll
...\.nuget\packages\xamarin.androidx.loader\1.1.0.7-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Loader.dll
...\.nuget\packages\xamarin.androidx.localbroadcastmanager\1.0.0.7-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.LocalBroadcastManager.dll
...\.nuget\packages\xamarin.androidx.media\1.2.1.2-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Media.dll
C:\Program Files (x86)\Microsoft\Xamarin\NuGet\xamarin.androidx.multidex\2.0.1.5\lib\monoandroid90\Xamarin.AndroidX.MultiDex.dll
...\.nuget\packages\xamarin.androidx.print\1.0.0.7-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.Print.dll
...\.nuget\packages\xamarin.androidx.recyclerview\1.1.0.8-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.RecyclerView.dll
...\.nuget\packages\xamarin.androidx.savedstate\1.1.0.1-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.SavedState.dll
...\.nuget\packages\xamarin.androidx.slidingpanelayout\1.1.0.2-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.SlidingPaneLayout.dll
...\.nuget\packages\xamarin.androidx.swiperefreshlayout\1.1.0.2-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.SwipeRefreshLayout.dll
...\.nuget\packages\xamarin.androidx.vectordrawable\1.1.0.7-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.VectorDrawable.dll
...\.nuget\packages\xamarin.androidx.vectordrawable.animated\1.1.0.7-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.VectorDrawable.Animated.dll
...\.nuget\packages\xamarin.androidx.versionedparcelable\1.1.1.7-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.VersionedParcelable.dll
...\.nuget\packages\xamarin.androidx.viewpager\1.0.0.7-net6preview02.4535000\lib\net6.0-android30.0\Xamarin.AndroidX.ViewPager.dll

We won't be supporting Android Support libraries in .NET 6. Is there a dependency you're using that brings these in?

I think what's happening is there is a AndroidManifest.xml that conflicts between a library in Support vs. AndroidX.

jeromelaban commented 3 years ago

Thanks for the update. Yes there was a dependency (Com.Airbnb.Android.Lottie) that was bringing this, yet after removing it, the error is the same. The only non-AndroidX references that I could find are coming from the android migration package.

Here's an update of the logs: 2021-03-24-net6-android-msbuild.zip

jonathanpeppers commented 3 years ago

Yeah, it looks like Support is completely removed now, but the error message still mentions android.support.v4:

Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from AndroidManifest.xml:19:92-165

If you git clean -dxf and try again, does the problem go away?

jeromelaban commented 3 years ago

I tried a full rebuild after a clean, but still the same error. Tracking down android.support led me to this:

image

Which only appears when referencing this package:

<PackageReference Include="Xamarin.AndroidX.Loader" Version="1.1.0.7-net6preview02.4535000" />

that I have transitively through Xamarin.AndroidX.Fragment.

jeromelaban commented 3 years ago

FYI, I'm still getting this error with pre3

jonathanpeppers commented 3 years ago

I don't think we have any changes in preview 3 that would fix this.

Are you able to make a smaller project where it fails? Maybe one that uses the same AndroidX packages you have?

jeromelaban commented 3 years ago

I've tried to do so without much success yet. I'll try again :)

jeromelaban commented 3 years ago

Ok, so for some reason, my manifest had android:appComponentFactory="android.support.v4.app.CoreComponentFactory" which may have come from a generated manifest.

Removing this fixed it.

Thanks for the troubleshooting!