0

我有一个 Xamarin Android 应用程序,它可以在 DEBUG 模式下编译并运行良好,但不会在 RELEASE 模式下编译。

我得到的错误是:

Mono.Linker.MarkException: Error processing method: 'System.String Microsoft.CodeAnalysis.SQLite.Interop.NativeMethods::sqlite3_errmsg(Microsoft.CodeAnalysis.SQLite.Interop.SafeSqliteHandle)' in assembly: 'Microsoft.CodeAnalysis.Workspaces.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.String SQLitePCL.raw::sqlite3_errmsg(SQLitePCL.sqlite3)
   at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference)
   at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
   at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
   at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
   at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
   at Mono.Linker.Steps.MarkStep.ProcessQueue()
   --- End of inner exception stack trace ---
   at Mono.Linker.Steps.MarkStep.ProcessQueue()
   at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
   at Mono.Linker.Steps.MarkStep.Process()
   at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
   at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context)
   at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
   at Mono.Linker.Pipeline.Process(LinkContext context)
   at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
   at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
   at Xamarin.Android.Tasks.LinkAssemblies.RunTask()
   at Xamarin.Android.Tasks.AndroidTask.Execute()   MedLemnMobile.Android   C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets    366     

我已经为 Microsoft.CodeAnalysis.Workspaces.dll 尝试过“跳过链接”

我已经为 SQLitePCLRaw.core 尝试过“跳过链接”

上述“跳过链接”尝试都没有解决问题。如果我将 Linking 设置为“None”,则该应用程序可以正常编译,但不建议在 RELEASE 模式下这样做。

任何帮助将不胜感激。

2021 年 2 月 22 日 - 我在构建输出上调高了详细程度并搜索了 System.String。这是我发现的:

Activator call 'System.Object System.Reflection.Assembly::CreateInstance(System.String)' inside 'System.ValueTuple`2<System.Int32,System.Reflection.MethodInfo> CompilerClassLibNETStandard.Compiler::CompileInMemory(System.String)' is not yet supported (TaskId:466)
5>  Reflection call 'System.Reflection.FieldInfo System.Type::GetField(System.String,System.Reflection.BindingFlags)' inside 'Xamarin.Forms.BindableProperty Xamarin.Forms.VisualElement::Xamarin.Forms.StyleSheets.IStylable.GetProperty(System.String,System.Boolean)' was detected with argument which cannot be analyzed (TaskId:466)
5>  Reflection call 'System.Type System.Type::GetType(System.String)' inside 'System.Void MedLemnMobile.ViewModels.GraphViewModel::MethodBeginModeReduce(System.String)' was detected with type name `MedLemnMobile.Classes.` which can't be resolved. (TaskId:466)
5>  Activator call 'System.Object System.Activator::CreateInstance(System.Type)' inside 'System.Void MedLemnMobile.ViewModels.GraphViewModel::MethodBeginModeReduce(System.String)' was detected with 1st argument expression which cannot be analyzed (TaskId:466)
5>  Expression call 'System.Linq.Expressions.MemberExpression System.Linq.Expressions.Expression::Property(System.Linq.Expressions.Expression,System.Reflection.MethodInfo)' inside 'System.Void MedLemnMobile.ValidRules.ValidatableObject`1::set_IsValid(System.Boolean)' was detected with 2nd argument which cannot be analyzed (TaskId:466)
5>  Expression call 'System.Linq.Expressions.MemberExpression System.Linq.Expressions.Expression::Property(System.Linq.Expressions.Expression,System.Reflection.MethodInfo)' inside 'System.Void MedLemnMobile.ValidRules.ValidatableObject`1::a(System.Collections.Generic.List`1<System.String>)' was detected with 2nd argument which cannot be analyzed (TaskId:466)
5>  Expression call 'System.Linq.Expressions.MemberExpression System.Linq.Expressions.Expression::Property(System.Linq.Expressions.Expression,System.Reflection.MethodInfo)' inside 'System.Void MedLemnMobile.ValidRules.ValidatableObject`1::set_Value(T)' was detected with 2nd argument which cannot be analyzed (TaskId:466)
5>  Activator call 'System.Object System.Activator::CreateInstance(System.Type,System.Object[])' inside 'System.Void MedLemnMobile.Classes.Utils/a::MoveNext()' was detected with 1st argument expression which cannot be analyzed (TaskId:466)
5>  Reflection call 'System.Type System.Type::GetType(System.String)' inside 'System.Object Xamarin.Forms.BindablePropertyConverter::ConvertFromInvariantString(System.String)' was detected with type name `Xamarin.Forms.` which can't be resolved. (TaskId:466)
5>  Expression call 'System.Linq.Expressions.MethodCallExpression System.Linq.Expressions.Expression::Call(System.Linq.Expressions.Expression,System.Reflection.MethodInfo,System.Linq.Expressions.Expression,System.Linq.Expressions.Expression)' inside 'System.Void MedLemnMobile.Behaviors.EventToCommandBehavior::a(System.Reflection.EventInfo,System.Object,System.Action`2<System.Object,System.EventArgs>)' was detected with 1st argument which cannot be analyzed (TaskId:466)
5>  Reflection call 'System.Type System.Type::GetType(System.String)' inside 'System.Type Java.Interop.__TypeRegistrations::Lookup(System.String[],System.String)' was detected with argument which cannot be analyzed (TaskId:466)
5>  Reflection call 'System.Reflection.MethodInfo System.Reflection.RuntimeReflectionExtensions::GetRuntimeMethod(System.Type,System.String,System.Type[])' inside 'System.String Humanizer.EnumHumanizeExtensions::GetCustomDescription(System.Reflection.MemberInfo)' does not use detectable instance type extraction (TaskId:466)
5>  Reflection call 'System.Reflection.MethodInfo System.Reflection.RuntimeReflectionExtensions::GetRuntimeMethod(System.Type,System.String,System.Type[])' inside 'System.String Humanizer.EnumHumanizeExtensions::GetCustomDescription(System.Reflection.MemberInfo)' does not use detectable instance type extraction (TaskId:466)
5>  Reflection call 'System.Reflection.FieldInfo System.Type::GetField(System.String,System.Reflection.BindingFlags)' inside 'System.Void Microsoft.CodeAnalysis.CSharp.Shared.Lightup.NullableSyntaxAnnotationEx::.cctor()' does not use detectable instance type extraction (TaskId:466)
5>  Reflection call 'System.Reflection.FieldInfo System.Type::GetField(System.String,System.Reflection.BindingFlags)' inside 'System.Void Microsoft.CodeAnalysis.CSharp.Shared.Lightup.NullableSyntaxAnnotationEx::.cctor()' does not use detectable instance type extraction (TaskId:466)
5>  Reflection call 'System.Type System.Type::GetType(System.String,System.Boolean)' inside 'System.Type Roslyn.Utilities.ReflectionUtilities::TryGetType(System.String)' was detected with argument which cannot be analyzed (TaskId:466)
5>  Reflection call 'System.Type System.Type::GetType(System.String)' inside 'System.Boolean Roslyn.Utilities.UICultureUtilities::TryGetCurrentUICultureSetter(System.Action`1<System.Globalization.CultureInfo>&)' was detected with type name `System.Globalization.CultureInfo, System.Globalization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a` which can't be resolved. (TaskId:466)
5>  Reflection call 'System.Type System.Type::GetType(System.String)' inside 'System.Type Roslyn.Utilities.ObjectReader::ReadType()' was detected with argument which cannot be analyzed (TaskId:466)
5>  Activator call 'System.Object System.Activator::CreateInstance(System.Type)' inside 'System.Object Microsoft.DiaSymReader.SymUnmanagedFactory::CreateObject(System.Boolean,System.Boolean,System.Boolean,System.String&,System.Exception&)' was detected with 1st argument expression which cannot be analyzed (TaskId:466)
5>  Activator call 'T System.Activator::CreateInstance()' inside 'T Microsoft.CodeAnalysis.DecodeWellKnownAttributeArguments`3::GetOrCreateData()' is not supported (TaskId:466)
5>  Activator call 'T System.Activator::CreateInstance()' inside 'T Microsoft.CodeAnalysis.EarlyDecodeWellKnownAttributeArguments`4::GetOrCreateData()' is not supported (TaskId:466)
5>  Activator call 'T System.Activator::CreateInstance()' inside 'System.Void Microsoft.CodeAnalysis.Diagnostics.AnalysisState/BlockAnalyzerStateData`2::.ctor()' is not supported (TaskId:466)
5>  Activator call 'System.Object System.Activator::CreateInstance(System.Type)' inside 'System.Collections.Immutable.ImmutableArray`1<TExtension> Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference/Extensions`1::GetAnalyzersForTypeNames(System.Reflection.Assembly,System.Collections.Generic.IEnumerable`1<System.String>,System.Boolean&)' was detected with 1st argument expression which cannot be analyzed (TaskId:466)
5>  Reflection call 'System.Type System.Type::GetType(System.String)' inside 'System.Type Roslyn.Utilities.ObjectReader::ReadType()' was detected with argument which cannot be analyzed (TaskId:466)
5>  Reflection call 'System.Type System.Type::GetType(System.String,System.Boolean)' inside 'System.Type Roslyn.Utilities.ReflectionUtilities::TryGetType(System.String)' was detected with argument which cannot be analyzed (TaskId:466)
5>  Activator call 'T System.Activator::CreateInstance()' inside 'System.Void Roslyn.Utilities.IDictionaryExtensions::MultiAdd(System.Collections.Generic.IDictionary`2<TKey,TCollection>,TKey,TValue)' is not supported (TaskId:466)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: Mono.Linker.MarkException: Error processing method: 'System.String Microsoft.CodeAnalysis.SQLite.Interop.NativeMethods::sqlite3_errmsg(Microsoft.CodeAnalysis.SQLite.Interop.SafeSqliteHandle)' in assembly: 'Microsoft.CodeAnalysis.Workspaces.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.String SQLitePCL.raw::sqlite3_errmsg(SQLitePCL.sqlite3)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000:    at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000:    at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000:    at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000:    at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000:    at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000:    at Mono.Linker.Steps.MarkStep.ProcessQueue()
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000:    --- End of inner exception stack trace ---
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000:    at Mono.Linker.Steps.MarkStep.ProcessQueue()
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000:    at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000:    at Mono.Linker.Steps.MarkStep.Process()
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000:    at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000:    at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000:    at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000:    at Mono.Linker.Pipeline.Process(LinkContext context)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000:    at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000:    at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000:    at Xamarin.Android.Tasks.LinkAssemblies.RunTask()
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000:    at Xamarin.Android.Tasks.AndroidTask.Execute()
5>Done executing task "LinkAssemblies" -- FAILED. (TaskId:466)
5>Done building target "_LinkAssembliesShrink" in project "MedLemnMobile.Android.csproj" -- FAILED.: (TargetId:492)
4

2 回答 2

0

成功!我让它按如下方式工作:

1.) 我发现将链接设置为“Sdk 和用户程序集”可以让应用程序构建正常,但是当它运行时,用户界面表现不佳。

2.) 然后,我将我的主要 Xamarin.Forms 共享代码项目的名称添加到我的“跳过链接”列表中。

而且,谢天谢地,它可以干净地构建和运行!

于 2021-02-24T05:09:19.823 回答
0

我尝试清理 bin 和 obj,做了很多事情,但没有任何帮助。最后,我关闭了我的 Android 属性中的“Multi-Dex”以进行编译。下面是我的设置。

在此处输入图像描述

于 2021-09-14T06:44:59.653 回答