---
title: "Unity项目Android调试过程"
author: "Perrin Yong"
author_profile: https://www.pystone.net/profile/
published_by: "Perrin Yong"
canonical: https://www.pystone.net/notes/unity-android-debug-workflow/
type: note
content_role: unspecified
visibility: public
id_stability: rename-stable
source_path: "10-计算机、信息技术与工程/05-游戏图形与运行时/Unity/Unity项目Android调试过程.md"
content_hash: d75a46acb119e3d852c468dc9571657745ce157479e9eb0785fabad3e1d0fb18
knowledge_version: 224c990773de.5fa8af6e39fa
site_commit: 224c990773de166d23a886306577dd90379529ce
notes_commit: 5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a
---
# Unity项目Android调试过程

﻿# Unity项目Android调试过程

> 创建时间：2020/8/21 14:24

* Unity Profiler的连接
  * adb的一些技巧
    * adb forward原理
    * log获取
    * 不太清楚为什么的操作
    * 密码忘记
  * Ref

## Unity Profiler的连接

通过USB接口对安卓设备的程序进行分析：

Profiler中的选项：AndroidProfiler(ADB@127.0.0.1:34999)

The Unity Editor automatically creates an adb **tunnel** for your application when you select **Build & Run**. If you want to **profile another application** , or you **restart the adb server** , you need to configure this tunnel manually.

Required when Editor-to-Android connection is established via USB cableadb

```csharp
class Program
{
    static void Main(string[] args)
    {
        dynamic dyn = 1;
        object obj = 1;
        dyn = dyn + 3;
        //obj = obj + 3; 报错

        // Rest the mouse pointer over dyn and obj to see their
        // types at compile time.
        System.Console.WriteLine(dyn.GetType());
        System.Console.WriteLine(obj.GetType());
    }
}

```

Required when Android-to-Editor connection is established via USB cableadb

```csharp
class Program
{
    static void Main(string[] args)
    {
        dynamic dyn = 1;
        object obj = 1;
        dyn = dyn + 3;
        //obj = obj + 3; 报错

        // Rest the mouse pointer over dyn and obj to see their
        // types at compile time.
        System.Console.WriteLine(dyn.GetType());
        System.Console.WriteLine(obj.GetType());
    }
}

```

## adb的一些技巧

### adb forward原理

adb forward tcp:8888 tcp:9999
执行完该命令后，转发PC机8888端口的数据到手机的9999端口。

adb forward --list
查看一下转发是否成功，只有通过USB成功连接了手机该命令才能成功

### log获取

log获取方法一：

```csharp
class Program
{
    static void Main(string[] args)
    {
        dynamic dyn = 1;
        object obj = 1;
        dyn = dyn + 3;
        //obj = obj + 3; 报错

        // Rest the mouse pointer over dyn and obj to see their
        // types at compile time.
        System.Console.WriteLine(dyn.GetType());
        System.Console.WriteLine(obj.GetType());
    }
}

```

log获取方法二（ddms调式）：

android-sdk\tools 下的ddms.bat，运行。

点击+号添加Filter Name和by log cat

真机上启动刚刚Build的APK，就可以看见输出的Debug信息。

### 不太清楚为什么的操作

  1. 首先在手机上开启USB调试功能，并安装驱动。USB连接
  2. 确保手机和电脑在一个局域网内

adb连接

```csharp
class Program
{
    static void Main(string[] args)
    {
        dynamic dyn = 1;
        object obj = 1;
        dyn = dyn + 3;
        //obj = obj + 3; 报错

        // Rest the mouse pointer over dyn and obj to see their
        // types at compile time.
        System.Console.WriteLine(dyn.GetType());
        System.Console.WriteLine(obj.GetType());
    }
}

```

Run->Attach to process 会发现你手机的选项，选择手机，在脚本里面添加断点，你发现可以调试了

其他命令

```csharp
class Program
{
    static void Main(string[] args)
    {
        dynamic dyn = 1;
        object obj = 1;
        dyn = dyn + 3;
        //obj = obj + 3; 报错

        // Rest the mouse pointer over dyn and obj to see their
        // types at compile time.
        System.Console.WriteLine(dyn.GetType());
        System.Console.WriteLine(obj.GetType());
    }
}

```

### 密码忘记

adb shell
cd data\system
ls
如果设置了密码会有gesture.key或者password.key
若设置的是图案密码请继续输入命令：rm gesture.key
若设置的是单纯密码请输入命令：rm password.key
reboot

## Ref

https://gameinstitute.qq.com/community/detail/124474
