Unity 安卓堆棧跟蹤和日志工具 (Android Logcat | 符號表解析Bugly捕獲)

一,工具集成

Logcat是開發者必備的工具,調試app時的閃退,異常,等問題都可以在這里看到。
Android Logcat包是在Unity Editor中顯示來自Android設備的堆棧跟蹤和日志等消息。

1.1 注意事項

Android Logcat軟件包需要Unity 2019.4或更高版本以及Android支持模塊。需要添加Android模塊:


image.png

image.png

導入前需要注意:確保你的工程已加載Android模塊,并且可以切到Android平臺。
確認后在“build Settings”窗口中切換到Android構建目標。


image.png

1.2 導入插件

在Package Manager(Window” --> PackageManager)界面中導入:


image.png

插件簡介:

Android Logcat軟件包支持:

  • Android:日志消息

  • Android:應用程序內存統計

  • Android:屏幕捕獲

  • Android:屏幕記錄器

  • Stacktrace:實用程序

可以通過“Window > Analysis > Android Logcat ”在Unity Editor中訪問該窗口。


image.png

窗口打開快捷鍵:Windows 按“Alt+6”;macOS “Option+6”

二,連接設備

Android Logcat軟件包支持USB和無線連接。本節介紹如何將Android設備連接到Android Logcat窗口。

2.1 使用USB連接

當您打開Android Logcat窗口時,Unity會自動將任何USB連接的Android設備添加到設備列表中。
手機連接上USB之后,需要選擇:傳輸文件。若沒有此選項,則需要打開開發者模式。


image.png

PS: 在手機版本上多次點擊才可以喚醒出開發者模式,再次點擊則有吐司提示您已處于開發者模式,這時再去更多設置中去找開發者模式并開啟即可。
檢測上之后,即可在窗口中看到實時日志了:


image.png

2.2 無線連接

要將Android設備連接到Android Logcat窗口:
無線連接,還是得先使用2.1方式使用USB鏈接一下,然后打開Android Logcat窗口,從工具欄中,選擇“設備選擇器”。
選擇其他連接選項:


image.png

在打開的窗口中,找到對應設備點擊Connect:


image.png

連接成功提示:(不使用USB方式鏈接,直接輸入IP地址,總是鏈接失敗,不知道為什么[\疑惑])


image.png

連接成功后,拔掉USB連接,就可以在可用設備窗口,找到Wifi鏈接的了:


image.png

PS:一次只能連接到一個設備。要選擇要連接的設備,請使用Android Logcat窗口中的設備列表。此列表包含已連接設備的設備ID。
可以看到實時日志了:


image.png

若需要斷開連接,可以在連接窗口對應設備后點擊“Disconnect”:


image.png

再次連接,直接點最下面的Connect鏈接,即可鏈接成功。

三,實用功能介紹

3.1 通用介紹

1.篩選包名查看日志
點擊No Filter,在彈出的下拉菜單中,即可選擇當前運行應用的包名,進行查看當前應用的相關日志:


image.png

2.篩選日志信息
Logcat工具支持在搜索框輸入正則表達式檢索和區分大小寫功能:


image.png

3.Reconnect重新連接,Disconnect斷開鏈接
當我們出現一個問題,需要查看日志時,為了防止日志太多將需要查看的日志刷過去,則可以點擊Disconnect斷開鏈接,停止捕獲更新日志信息。需要再次查看日志時,點擊Reconnect重新連接。


image.png

3.2 堆棧跟蹤工具 – 解析Bugly捕獲報錯

在Tools下拉菜單下選擇Stacktrace Utility 可以打開工具面板:


image.png

準備工作:指定符號表)

在Project Setting面板 -> Analysis -> Android Logcat Settings 中設置:


image.png

PS:打包時用的哪個就導入哪個,看你打包時的工程設置:Player -> Configuration


image.png

若不指定會在解析時報錯提示:

At least one symbol path needs to be specified.
Click Configure Symbol Paths and add the necessary symbol path.

舉個例子:解析Bugly捕獲報錯

操作步驟:復制Bugly報錯到工具Original界面,然后點擊Resolve Stacktraces 即可:

解析前日志:

at libunity.0x577cd8(Native Method)
at libunity.0x583bdc(Native Method)
at libunity.0x5844b8(Native Method)
at libunity.0x583870(Native Method)
at libunity.0x58380c(Native Method)
at libunity.0x1d9058(Native Method)
at libil2cpp.0x2bd4b20(Native Method)
at libil2cpp.0x2bd6008(Native Method)
at libil2cpp.0x278083c(Native Method)
at libil2cpp.0xb8dc68(Native Method)
at libil2cpp.0xb8dac8(Native Method)
at libunity.0x566cf4(Native Method)
at libunity.0x574f98(Native Method)
at libunity.0x581a0c(Native Method)
at libunity.0x5815e8(Native Method)
at libunity.0x583620(Native Method)
at libunity.0x583b44(Native Method)
at libunity.0x5844dc(Native Method)
at libunity.0x583870(Native Method)
at libunity.0x58380c(Native Method)
at libunity.0x1d9058(Native Method)
at libil2cpp.0x2bd4b20(Native Method)
at libil2cpp.0x2bd6008(Native Method)
at libil2cpp.0x278083c(Native Method)
at libil2cpp.0xb8dc68(Native Method)
at libil2cpp.0xb8dac8(Native Method)
at libunity.0x566cf4(Native Method)
at libunity.0x574f98(Native Method)
at libunity.0x581a0c(Native Method)
at libunity.0x5815e8(Native Method)
at libunity.0x583620(Native Method)
at libunity.0x583b44(Native Method)

解析后日志:

at libunity.0x577cd8 (ScriptingInvocation::ScriptingInvocation(ScriptingObjectPtr, ScriptingMethodPtr) at ??:?)(Native Method)
at libunity.0x583bdc (MonoBehaviour::InvokeMethodOrCoroutineChecked(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingExceptionPtr) at ??:?)(Native Method)
at libunity.0x5844b8 (MonoBehaviour::InvokeMethodOrCoroutineChecked(ScriptingMethodPtr, ScriptingObjectPtr) at ??:?)(Native Method)
at libunity.0x583870 (MonoBehaviour::StartCoroutine(char const
, ScriptingObjectPtr) at ??:?)(Native Method)
at libunity.0x58380c (MonoBehaviour::StartCoroutineManaged(char const, ScriptingObjectPtr) at ??:?)(Native Method)
at libunity.0x1d9058 (MonoBehaviour_CUSTOM_StartCoroutineManaged(ScriptingBackendNativeObjectPtrOpaque
, ScriptingBackendNativeStringPtrOpaque, ScriptingBackendNativeObjectPtrOpaque) at ??:?)(Native Method)
at libil2cpp.0x2bd4b20 (__start_il2cpp at ??:?)(Native Method)
at libil2cpp.0x2bd6008 (__start_il2cpp at ??:?)(Native Method)
at libil2cpp.0x278083c (__start_il2cpp at ??:?)(Native Method)
at libil2cpp.0xb8dc68 (BrotliDecoderVersion at ??:?)(Native Method)
at libil2cpp.0xb8dac8 (BrotliDecoderVersion at ??:?)(Native Method)
at libunity.0x566cf4 (scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr, bool) at ??:?)(Native Method)
at libunity.0x574f98 (ScriptingInvocation::Invoke(ScriptingExceptionPtr
, bool) at ??:?)(Native Method)
at libunity.0x581a0c (Coroutine::InvokeMoveNext(ScriptingExceptionPtr) at ??:?)(Native Method)
at libunity.0x5815e8 (Coroutine::Run(bool
) at ??:?)(Native Method)
at libunity.0x583620 (MonoBehaviour::TryCreateAndRunCoroutine(ScriptingObjectPtr, ScriptingMethodPtr, Coroutine) at ??:?)(Native Method)
at libunity.0x583b44 (MonoBehaviour::HandleCoroutineReturnValue(ScriptingMethodPtr, ScriptingObjectPtr) at ??:?)(Native Method)
at libunity.0x5844dc (MonoBehaviour::InvokeMethodOrCoroutineChecked(ScriptingMethodPtr, ScriptingObjectPtr) at ??:?)(Native Method)
at libunity.0x583870 (MonoBehaviour::StartCoroutine(char const
, ScriptingObjectPtr) at ??:?)(Native Method)
at libunity.0x58380c (MonoBehaviour::StartCoroutineManaged(char const
, ScriptingObjectPtr) at ??:?)(Native Method)
at libunity.0x1d9058 (MonoBehaviour_CUSTOM_StartCoroutineManaged(ScriptingBackendNativeObjectPtrOpaque, ScriptingBackendNativeStringPtrOpaque, ScriptingBackendNativeObjectPtrOpaque) at ??:?)(Native Method)
at libil2cpp.0x2bd4b20 (__start_il2cpp at ??:?)(Native Method)
at libil2cpp.0x2bd6008 (__start_il2cpp at ??:?)(Native Method)
at libil2cpp.0x278083c (__start_il2cpp at ??:?)(Native Method)
at libil2cpp.0xb8dc68 (BrotliDecoderVersion at ??:?)(Native Method)
at libil2cpp.0xb8dac8 (BrotliDecoderVersion at ??:?)(Native Method)
at libunity.0x566cf4 (scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr
, bool) at ??:?)(Native Method)
at libunity.0x574f98 (ScriptingInvocation::Invoke(ScriptingExceptionPtr, bool) at ??:?)(Native Method)
at libunity.0x581a0c (Coroutine::InvokeMoveNext(ScriptingExceptionPtr
) at ??:?)(Native Method)
at libunity.0x5815e8 (Coroutine::Run(bool) at ??:?)(Native Method)
at libunity.0x583620 (MonoBehaviour::TryCreateAndRunCoroutine(ScriptingObjectPtr, ScriptingMethodPtr, Coroutine
*) at ??:?)(Native Method)
at libunity.0x583b44 (MonoBehaviour::HandleCoroutineReturnValue(ScriptingMethodPtr, ScriptingObjectPtr) at ??:?)(Native Method)

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容