写在前面:
之前给大家介绍过在 Xamarin 中使用原生的第三方 SDK,或集成一些第三方厂商提供的 Framework,需要通过 Binding Library 将原生开发语言编写的组件转化为可以 Xamarin 引用的 C# 定义,对于这部分还不清楚的同学可以参考我之前的博客 年底第一篇:Xamarin.iOS MJRefresh集成 ,对于 Binding Library 的构建过程中难免会遇到一些未知且不好解决的问题,其中有的问题并没有详细的日志输出,以至于我们并不容易去定位问题,今天就介绍下怎么在 Xamarin 查看完整的 Build logs。
对于开发人员来说, Build logs 用来诊断 Android,iOS,Mac 或任何其他类型应用程序的 Build error 的最有价值的信息之一。当构建出现问题时,在 Xamarin 中完整的 Build logs 就尤为重要了 。
MTOUCHTASK: error MT5210: Native linking failed, undefined symbol: kSecReturnPersistentRef. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
MTOUCH: error MT5211: Native linking failed, undefined Objective-C class: _OBJC_CLASS$CLLocationManager. If '_OBJC_CLASS$_CLLocationManager' is a protocol from a third-party binding, please check that it has the [Protocol] attribute in its api definition file, otherwise verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
Please file a bug report at [http://bugzilla.xamarin.com](http://bugzilla.xamarin.com/) (MT5216) (OpenCVTest.iOS)
上面的错误日志大家经常会在 Binding Native iOS Framework 遇到,除了以上寥寥数行的错误提示以外,基本没有其它有用的完整日志可供我们定位错误,特别是 Binding Library 项目中,涉及到原生框架依赖比较多,如果不根据完整的错误日志,很难去找到响应的解决方案。但是其实 VS 中已经提供给我们了详细日志的选项,只是默认情况下并没有开启。
Enabling Diagnostic-Level Verbosity in Your Build Logs
要更改 Build Logs 的详细程度,在 VS For Mac 上,你需要通过 VS For Mac 顶部工具栏 —> 偏好设置 —> 项目 —> 构建。在 Windows 上,你需要通过 Tools —> Options —> Projects and Solutions —> Build and Run。
例如 VS For Mac :
对话框出现后,导航到Projects 部分的面板下的 Build 选项,你可以看到一个 Log verbosity 设置。日志详细程度下拉菜单提供了许多可能的详细级别,包括 Diagnostic(这是最详细的)。
To get full build logs just set the log verbosity to diagnostic at the following locations:
- On Visual Studio for Mac: Preferences > Projects > Build
- On Visual Studio for Windows: Tools > Options > Projects and Solutions > Build and Run
然后需要在 Windows 上需要右键选择你的项目 —> 属性 —> 构建 —> 额外的mtouch参数 中设置 -v -v -v -v
。
On Visual Studio Windows you also want to add
-v -v -v -v
to the mtouch additional arguments by right-clicking the project in the solution explorer and selectingProperties
.
注意事项:
在 VS For Mac 中当你把 Log verbosity 切换为 Diagnostic 后,VS For Mac 默认会自动添加 额外的mtouch参数 ,并不需要你再手动去设置。
Where To Find Your Build Log
您可以在 VS For Mac 窗口右下角的输出板 Errors( 文本编辑器视图下方 ) 中找到项目的构建日志:
注意:
如果您没有看到该 Errors 按钮,则可能已关闭该按钮。要重新启用它,请转到 View 菜单,向下导航到 Pads 子菜单,然后选择 Errors。
单击该 Errors 按钮将显示错误面板,其中包含构建日志以及构建项目时发生的错误和警告列表,这样你就可以在右侧看到完整的构建日志。
注意:您可以使用 Command-A 快捷方式轻松复制整个构建日志,以选择所有文本,然后使用 Command-C 将构建日志复制到剪贴板。
References
- how-to-obtain-diagnostic-build-logs
- Error MT5216: Native linking failed for .....
- Xamarin.iOS MJRefresh集成
到这里在 Get full build logs in Xamarin 就介绍完了,希望能对您有所帮助。