Xamarin.Android Release模式编译链接失败 无法解析SQLitePCL.raw方法
问题基本信息
- 应用类型:Xamarin Android 应用
- 运行表现:DEBUG 模式可正常编译、运行;RELEASE 模式下编译失败
- 已完成的排查动作:
- 为
Microsoft.CodeAnalysis.Workspaces.dll、SQLitePCLRaw.core配置“跳过链接”规则,报错未消除 - 若将链接选项设置为“无”,编译可正常完成,但该配置不符合 RELEASE 模式的发布规范
- 为
- 运行环境:Visual Studio 2019 社区版,使用 Xamarin.Android Legacy 构建链路
核心编译报错
RELEASE 模式编译过程中在链接器环节抛出异常,完整错误栈如下:
Mono.Linker.MarkException: 程序集 `Microsoft.CodeAnalysis.Workspaces.dll` 中方法 `System.String Microsoft.CodeAnalysis.SQLite.Interop.NativeMethods::sqlite3_errmsg(Microsoft.CodeAnalysis.SQLite.Interop.SafeSqliteHandle)` 处理失败 ---> Mono.Cecil.ResolutionException: 无法解析方法定义 `System.String SQLitePCL.raw::sqlite3_errmsg(SQLitePCL.sqlite3)` 位于:Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference) 位于:Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference) 位于:Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction) 位于:Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body) 位于:Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method) 位于:Mono.Linker.Steps.MarkStep.ProcessQueue() --- 内部异常栈结束 --- 位于:Mono.Linker.Steps.MarkStep.ProcessQueue() 位于:Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue() 位于:Mono.Linker.Steps.MarkStep.Process() 位于:Mono.Linker.Steps.MarkStep.Process(LinkContext context) 位于:MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context) 位于:Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step) 位于:Mono.Linker.Pipeline.Process(LinkContext context) 位于:MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context) 位于:Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res) 位于:Xamarin.Android.Tasks.LinkAssemblies.RunTask() 位于:Xamarin.Android.Tasks.AndroidTask.Execute() 报错关联配置文件路径:`C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets` 第 366 行
详细构建日志检索结果
2021 年 2 月 22 日将构建输出详细级别调高后,筛选 System.String 相关条目,提取的链接器分析提示与最终报错如下:
[任务ID:466] 提示:`System.Object System.Reflection.Assembly::CreateInstance(System.String)` 在方法 `System.ValueTuple`2<System.Int32,System.Reflection.MethodInfo> CompilerClassLibNETStandard.Compiler::CompileInMemory(System.String)` 内部的调用,暂不被链接器支持 [任务ID:466] 提示:检测到 `Xamarin.Forms.BindableProperty Xamarin.Forms.VisualElement::Xamarin.Forms.StyleSheets.IStylable.GetProperty(System.String,System.Boolean)` 内部对 `System.Reflection.FieldInfo System.Type::GetField(System.String,System.Reflection.BindingFlags)` 的反射调用,传入参数无法被静态分析 [任务ID:466] 提示:检测到 `MedLemnMobile.ViewModels.GraphViewModel::MethodBeginModeReduce(System.String)` 内部对 `System.Type System.Type::GetType(System.String)` 的反射调用,传入的类型名 `MedLemnMobile.Classes.` 无法被解析 [任务ID:466] 提示:检测到 `MedLemnMobile.ViewModels.GraphViewModel::MethodBeginModeReduce(System.String)` 内部对 `System.Object System.Activator::CreateInstance(System.Type)` 的激活器调用,第 1 个参数表达式无法被静态分析 [任务ID:466] 提示:检测到 `MedLemnMobile.ValidRules.ValidatableObject`1::set_IsValid(System.Boolean)` 内部对 `System.Linq.Expressions.MemberExpression System.Linq.Expressions.Expression::Property(System.Linq.Expressions.Expression,System.Reflection.MethodInfo)` 的表达式调用,第 2 个参数无法被静态分析 [任务ID:466] 提示:检测到 `MedLemnMobile.ValidRules.ValidatableObject`1::a(System.Collections.Generic.List`1<System.String>)` 内部对 `System.Linq.Expressions.MemberExpression System.Linq.Expressions.Expression::Property(System.Linq.Expressions.Expression,System.Reflection.MethodInfo)` 的表达式调用,第 2 个参数无法被静态分析 [任务ID:466] 提示:检测到 `MedLemnMobile.ValidRules.ValidatableObject`1::set_Value(T)` 内部对 `System.Linq.Expressions.MemberExpression System.Linq.Expressions.Expression::Property(System.Linq.Expressions.Expression,System.Reflection.MethodInfo)` 的表达式调用,第 2 个参数无法被静态分析 [任务ID:466] 提示:检测到 `MedLemnMobile.Classes.Utils/a::MoveNext()` 内部对 `System.Object System.Activator::CreateInstance(System.Type,System.Object[])` 的激活器调用,第 1 个参数表达式无法被静态分析 [任务ID:466] 提示:检测到 `System.Object Xamarin.Forms.BindablePropertyConverter::ConvertFromInvariantString(System.String)` 内部对 `System.Type System.Type::GetType(System.String)` 的反射调用,传入的类型名 `Xamarin.Forms.` 无法被解析 [任务ID:466] 提示:检测到 `MedLemnMobile.Behaviors.EventToCommandBehavior::a(System.Reflection.EventInfo,System.Object,System.Action`2<System.Object,System.EventArgs>)` 内部对 `System.Linq.Expressions.MethodCallExpression System.Linq.Expressions.Expression::Call(System.Linq.Expressions.Expression,System.Reflection.MethodInfo,System.Linq.Expressions.Expression,System.Linq.Expressions.Expression)` 的表达式调用,第 1 个参数无法被静态分析 [任务ID:466] 提示:检测到 `Java.Interop.__TypeRegistrations::Lookup(System.String[],System.String)` 内部对 `System.Type System.Type::GetType(System.String)` 的反射调用,传入参数无法被静态分析 [任务ID:466] 提示:`System.String Humanizer.EnumHumanizeExtensions::GetCustomDescription(System.Reflection.MemberInfo)` 内部对 `System.Reflection.MethodInfo System.Reflection.RuntimeReflectionExtensions::GetRuntimeMethod(System.Type,System.String,System.Type[])` 的反射调用,未使用可检测的实例类型提取逻辑(共 2 条重复提示) [任务ID:466] 提示:`Microsoft.CodeAnalysis.CSharp.Shared.Lightup.NullableSyntaxAnnotationEx::.cctor()` 内部对 `System.Reflection.FieldInfo System.Type::GetField(System.String,System.Reflection.BindingFlags)` 的反射调用,未使用可检测的实例类型提取逻辑(共 2 条重复提示) [任务ID:466] 提示:检测到 `Roslyn.Utilities.ReflectionUtilities::TryGetType(System.String)` 内部对 `System.Type System.Type::GetType(System.String,System.Boolean)` 的反射调用,传入参数无法被静态分析 [任务ID:466] 提示:检测到 `System.Boolean Roslyn.Utilities.UICultureUtilities::TryGetCurrentUICultureSetter(System.Action`1<System.Globalization.CultureInfo>&)` 内部对 `System.Type System.Type::GetType(System.String)` 的反射调用,传入的类型名 `System.Globalization.CultureInfo, System.Globalization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a` 无法被解析 [任务ID:466] 提示:检测到 `Roslyn.Utilities.ObjectReader::ReadType()` 内部对 `System.Type System.Type::GetType(System.String)` 的反射调用,传入参数无法被静态分析 [任务ID:466] 提示:检测到 `Microsoft.DiaSymReader.SymUnmanagedFactory::CreateObject(System.Boolean,System.Boolean,System.Boolean,System.String&,System.Exception&)` 内部对 `System.Object System.Activator::CreateInstance(System.Type)` 的激活器调用,第 1 个参数表达式无法被静态分析 [任务ID:466] 提示:`T Microsoft.CodeAnalysis.DecodeWellKnownAttributeArguments`3::GetOrCreateData()` 内部对 `T System.Activator::CreateInstance()` 的激活器调用暂不被链接器支持 [任务ID:466] 提示:`T Microsoft.CodeAnalysis.EarlyDecodeWellKnownAttributeArguments`4::GetOrCreateData()` 内部对 `T System.Activator::CreateInstance()` 的激活器调用暂不被链接器支持 [任务ID:466] 提示:`System.Void Microsoft.CodeAnalysis.Diagnostics.AnalysisState/BlockAnalyzerStateData`2::.ctor()` 内部对 `T System.Activator::CreateInstance()` 的激活器调用暂不被链接器支持 [任务ID:466] 提示:检测到 `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&)` 内部对 `System.Object System.Activator::CreateInstance(System.Type)` 的激活器调用,第 1 个参数表达式无法被静态分析 [任务ID:466] 提示:检测到 `Roslyn.Utilities.ObjectReader::ReadType()` 内部对 `System.Type System.Type::GetType(System.String)` 的反射调用,传入参数无法被静态分析 [任务ID:466] 提示:检测到 `Roslyn.Utilities.ReflectionUtilities::TryGetType(System.String)` 内部对 `System.Type System.Type::GetType(System.String,System.Boolean)` 的反射调用,传入参数无法被静态分析 [任务ID:466] 提示:`System.Void Roslyn.Utilities.IDictionaryExtensions::MultiAdd(System.Collections.Generic.IDictionary`2<TKey,TCollection>,TKey,TValue)` 内部对 `T System.Activator::CreateInstance()` 的激活器调用暂不被支持 最终报错:错误码 XALNK7000,触发位置 `Xamarin.Android.Legacy.targets` 第 366 行,核心错误为链接器无法解析 SQLitePCL.raw 程序集中的方法定义 执行结果:`LinkAssemblies` 任务执行失败,`_LinkAssembliesShrink` 构建目标执行失败,RELEASE 模式编译中断
内容的提问来源于stack exchange,提问作者T. A. Pfaff
相关产品推荐
相关产品推荐

