当前位置: 首页 > news >正文

Unity Android Logcat插件 输出日志中文乱码解决

  • 背景

        之前安卓真机调试看日志,一直用的是Android Studio自带的adb命令进行看日志,不太方便,改用Unity自带的安卓日志插件时,存在中文日志乱码问题。

  • 插件安装

        基于Unity6000.1.11版本:Window -> Package Management -> Package Manager,即可打开包管理工具,选择Unity Registry分类,找到Android Logcat插件,导入即可。

  • 插件使用

        打开插件:Window -> Analysis -> Android Logcat,手机开启调试模式后,使用数据线连接电脑,在该插件面板默认会自动选择手机并输出日志(需手机先运行程序,每次运行后,每次选择)。可在顶部选择要调试程序的包名,输出的日志更整洁。

  • 乱码解决

        找到插件源码:Editor/AndroidLogcatMessageProvider.cs

        public override void Start(){var arguments = LogcatArguments();AndroidLogcatInternalLog.Log("\n\nStarting logcat\n\n");AndroidLogcatInternalLog.Log("{0} {1}", m_ADB.GetADBPath(), arguments);m_LogcatProcess = new Process();m_LogcatProcess.StartInfo.FileName = m_ADB.GetADBPath();m_LogcatProcess.StartInfo.Arguments = arguments;m_LogcatProcess.StartInfo.RedirectStandardError = true;m_LogcatProcess.StartInfo.RedirectStandardOutput = true;m_LogcatProcess.StartInfo.UseShellExecute = false;m_LogcatProcess.StartInfo.CreateNoWindow = true;//中文乱码修复,增加两行代码m_LogcatProcess.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8;m_LogcatProcess.StartInfo.StandardErrorEncoding = System.Text.Encoding.UTF8;m_LogcatProcess.OutputDataReceived += OutputDataReceived;m_LogcatProcess.ErrorDataReceived += OutputDataReceived;m_LogcatProcess.Start();m_LogcatProcess.BeginOutputReadLine();m_LogcatProcess.BeginErrorReadLine();}

        找到插件源码:Editor/AndroidTools/Shell.cscishi 

        internal static ShellReturnInfo RunProcess(ShellStartInfo startInfo){Process process = new Process();process.StartInfo.FileName = startInfo.FileName;process.StartInfo.Arguments = startInfo.Arguments;process.StartInfo.WorkingDirectory = startInfo.WorkingDirectory;process.StartInfo.UseShellExecute = false;process.StartInfo.RedirectStandardOutput = true;process.StartInfo.RedirectStandardError = true;process.StartInfo.CreateNoWindow = true;//中文乱码修复,增加两行代码process.StartInfo.StandardOutputEncoding = Encoding.UTF8;process.StartInfo.StandardErrorEncoding = Encoding.UTF8;...}

此时,日志就能够正常显示中了。 

http://www.dtcms.com/a/281897.html

相关文章:

  • FPGA基础 -- Verilog 访问寄存器数组的指定位示例
  • 第六章 OBProxy 路由与使用运维
  • [Linux入门] Linux 账号和权限管理入门:从基础到实践
  • Linux实现进程之间Socket通信详解
  • 30 天自制 C++ 服务器--Day3
  • NO.6数据结构树|二叉树|满二叉树|完全二叉树|顺序存储|链式存储|先序|中序|后序|层序遍历
  • 【SpringBoot】实战-开发接口-用户-注册
  • 参数检验?非参数检验?
  • 【openbmc3】时间相关
  • 代码随想录算法训练营第五十一天|图论part2
  • 【FreeRTOS】03任务管理
  • 工业相机GigE数据接口的优势及应用
  • django安装、跨域、缓存、令牌、路由、中间件等配置
  • Jenkins全方位CI/CD实战指南
  • LabVIEW Occurrence功能
  • 嵌入式Linux(RV1126)系统定制中的编译与引导问题调试报告
  • 【RTSP从零实践】12、TCP传输H264格式RTP包(RTP_over_TCP)的RTSP服务器(附带源码)
  • 基于WebRTC技术实现一个在线课堂系统
  • el-input 回显怎么用符号¥和变量拼接展示?
  • Spring Boot 解决跨域问题
  • Spring Boot - Spring Boot 集成 MyBatis 分页实现 手写 SQL 分页
  • 日语学习-日语知识点小记-构建基础-JLPT-N3阶段(5):语法+单词
  • Buffer Pool
  • css 如何实现大屏4个占位 中屏2个 小屏幕1个
  • Samba服务器
  • Git版本控制完全指南:从入门到精通
  • 网络编程/Java面试/TCPUDP区别
  • 基于spring boot养老院老人健康监护平台设计与实现
  • SFT:大型语言模型专业化定制的核心技术体系——原理、创新与应用全景
  • docker run elasticsearch 报错