寫在前面:
之前給大家介紹過在 Xamarin 中使用原生的第三方 SDK,或集成一些第三方廠商提供的 Framework,需要通過 Binding Library 將原生開發(fā)語言編寫的組件轉(zhuǎn)化為可以 Xamarin 引用的 C# 定義,對于這部分還不清楚的同學(xué)可以參考我之前的博客 年底第一篇:Xamarin.iOS MJRefresh集成 ,對于 Binding Library 的構(gòu)建過程中難免會遇到一些未知且不好解決的問題,其中有的問題并沒有詳細(xì)的日志輸出,以至于我們并不容易去定位問題,今天就介紹下怎么在 Xamarin 查看完整的 Build logs。
對于開發(fā)人員來說, Build logs 用來診斷 Android,iOS,Mac 或任何其他類型應(yīng)用程序的 Build error 的最有價(jià)值的信息之一。當(dāng)構(gòu)建出現(xiàn)問題時(shí),在 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)
上面的錯(cuò)誤日志大家經(jīng)常會在 Binding Native iOS Framework 遇到,除了以上寥寥數(shù)行的錯(cuò)誤提示以外,基本沒有其它有用的完整日志可供我們定位錯(cuò)誤,特別是 Binding Library 項(xiàng)目中,涉及到原生框架依賴比較多,如果不根據(jù)完整的錯(cuò)誤日志,很難去找到響應(yīng)的解決方案。但是其實(shí) VS 中已經(jīng)提供給我們了詳細(xì)日志的選項(xiàng),只是默認(rèn)情況下并沒有開啟。
Enabling Diagnostic-Level Verbosity in Your Build Logs
要更改 Build Logs 的詳細(xì)程度,在 VS For Mac 上,你需要通過 VS For Mac 頂部工具欄 —> 偏好設(shè)置 —> 項(xiàng)目 —> 構(gòu)建。在 Windows 上,你需要通過 Tools —> Options —> Projects and Solutions —> Build and Run。
例如 VS For Mac :
對話框出現(xiàn)后,導(dǎo)航到Projects 部分的面板下的 Build 選項(xiàng),你可以看到一個(gè) Log verbosity 設(shè)置。日志詳細(xì)程度下拉菜單提供了許多可能的詳細(xì)級別,包括 Diagnostic(這是最詳細(xì)的)。
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 上需要右鍵選擇你的項(xiàng)目 —> 屬性 —> 構(gòu)建 —> 額外的mtouch參數(shù) 中設(shè)置 -v -v -v -v 。
On Visual Studio Windows you also want to add
-v -v -v -vto the mtouch additional arguments by right-clicking the project in the solution explorer and selectingProperties.

注意事項(xiàng):
在 VS For Mac 中當(dāng)你把 Log verbosity 切換為 Diagnostic 后,VS For Mac 默認(rèn)會自動添加 額外的mtouch參數(shù) ,并不需要你再手動去設(shè)置。
Where To Find Your Build Log
您可以在 VS For Mac 窗口右下角的輸出板 Errors( 文本編輯器視圖下方 ) 中找到項(xiàng)目的構(gòu)建日志:

注意:
如果您沒有看到該 Errors 按鈕,則可能已關(guān)閉該按鈕。要重新啟用它,請轉(zhuǎn)到 View 菜單,向下導(dǎo)航到 Pads 子菜單,然后選擇 Errors。
單擊該 Errors 按鈕將顯示錯(cuò)誤面板,其中包含構(gòu)建日志以及構(gòu)建項(xiàng)目時(shí)發(fā)生的錯(cuò)誤和警告列表,這樣你就可以在右側(cè)看到完整的構(gòu)建日志。

注意:您可以使用 Command-A 快捷方式輕松復(fù)制整個(gè)構(gòu)建日志,以選擇所有文本,然后使用 Command-C 將構(gòu)建日志復(fù)制到剪貼板。
References
- how-to-obtain-diagnostic-build-logs
- Error MT5216: Native linking failed for .....
- Xamarin.iOS MJRefresh集成
到這里在 Get full build logs in Xamarin 就介紹完了,希望能對您有所幫助。
——End 有問題可以加我微信,大家一起討論,加好友前請備注您的簡稱,謝謝!
