Error while deploying on device in Xamarin.Android after upgrade to AndroidX in Visual Studio 2019

vitthalpatilvitthalpatil USMember ✭✭
edited October 16 in Xamarin.Android

I recently updated Xamarin Android project to support AndroidX. I migrated PreferenceManager and few mandatory APIs/methods like ExternalStorageDirectory, SetColorFilter only, to have successful compilation.

As, there are few third party libraries, which are still using old v4/v7 support libraries. Meaning, I can not start migration of support libraries.

With this, build is working fine. I can deploy to device and run the app. But, While deploying to device in debug mode, getting below error:

Severity    Code    Description Project File    Line    Suppression State
Error       MSB4018: The "GenerateJavaStubs" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load assembly 'Xamarin.Android.Support.v7.AppCompat, Version=1.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'Xamarin.Android.Support.v7.AppCompat.dll'
   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference)
   at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
   at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type)
   at Mono.Cecil.TypeReference.Resolve()
   at Java.Interop.Tools.Cecil.TypeDefinitionRocks.<GetTypeAndBaseTypes>d__1.MoveNext()
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at Java.Interop.Tools.Cecil.TypeDefinitionRocks.IsSubclassOf(TypeDefinition type, String typeName)
   at Java.Interop.Tools.JavaCallableWrappers.JavaTypeScanner.AddJavaTypes(List`1 javaTypes, TypeDefinition type)
   at Java.Interop.Tools.JavaCallableWrappers.JavaTypeScanner.GetJavaTypes(IEnumerable`1 assemblies, IAssemblyResolver resolver)
   at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res)
   at Xamarin.Android.Tasks.GenerateJavaStubs.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

Did someone also, found this issue?

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited October 23

    Try the follows:
    1.What's the version of the nuget package? Update Xamarin.Android.Support.v7.AppCompat package and Xamarin.Forms to the lastest stable version.
    2.Check the target framework version.

  • vitthalpatilvitthalpatil USMember ✭✭

    Its Xamarin.Android project.
    Xamarin.Android.Support.v7.AppCompat package is already updated.
    target framework is set to latest(29)

    I am able to deploy with two workarounds:

    • If I set Linking to "None". Here Android app stucks at loader
    • "Sdk and User Assemblies" (breakpoint not working in PCL)

    My question is, this should work with default linker settings, as it was working previously.

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited October 17

    Try to uninstall the Xamarin.Android.Support packages like Xamarin.Android.Support.v7.AppCompat etc. Android X has the new Android Support library: Xamarin.Android.Support.Core.Utils.
    Check the link:
    https://github.com/xamarin/AndroidSupportComponents

    Or upgrate your Visual Studio and create a new project. Then move the code to the new sample.

  • vitthalpatilvitthalpatil USMember ✭✭

    @Jarvan said:
    Try to uninstall the Xamarin.Android.Support packages like Xamarin.Android.Support.v7.AppCompat etc. Android X has the new Android Support library: Xamarin.Android.Support.Core.Utils.
    Check the link:
    https://github.com/xamarin/AndroidSupportComponents

    Or upgrate your Visual Studio and create a new project. Then move the code to the new sample.

    Yeah, migration of Support libraries is optional. There is no stable version of AndroidX support library available. Also, many third party libraries including google maps for Xamarin, does not have AndroidX support library integration. Meaning, this is delayed.

    VS 2019 is at its latest version.

Sign In or Register to comment.