Skip to content

Commit

Permalink
Feature/android debug (#92)
Browse files Browse the repository at this point in the history
* Add Android abd path to Android builds in the BuildWindow.
- Easy place to see where Unity is looking for adb. Also concat the path.

* Only check for adb when using Oculus/Android.

(cherry picked from commit 258592b06644682d3e0c3d6b4f64418b09c0b7fa)
  • Loading branch information
billyquith authored Apr 10, 2021
1 parent 7a5d508 commit 8ca2f95
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions Assets/Editor/BuildWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
using System.Runtime.InteropServices;

namespace TiltBrush {
public class BuildWindow : EditorWindow {

public class BuildWindow : EditorWindow
{
private class HeaderedHorizontalLayout : GUI.Scope {
public HeaderedHorizontalLayout(string header, params GUILayoutOption[] options) {
GUILayout.BeginVertical(new GUIContent(header), EditorStyles.helpBox, options);
Expand Down Expand Up @@ -188,6 +188,7 @@ private string SpinnerString() {
private int? m_buildLogPosition;
private System.IntPtr m_hwnd;
private DateTime m_buildCompleteTime;
private static string m_adbPath;

private bool AndroidConnected {
get {
Expand Down Expand Up @@ -417,6 +418,11 @@ private void DeviceGui() {
private void BuildActionsGui() {
using (var builds = new HeaderedVerticalLayout("Build")) {
EditorGUILayout.LabelField("Build Path", m_currentBuildPath);
if (!String.IsNullOrEmpty(m_adbPath)) {
EditorGUILayout.LabelField("Adb Path", m_adbPath);
if (!File.Exists(m_adbPath))
EditorGUILayout.LabelField("Adb status", "ADB not found in expected path.");
}
if (m_currentBuildTime.HasValue) {
TimeSpan age = DateTime.Now - m_currentBuildTime.Value;
EditorGUILayout.LabelField("Creation Time", m_currentBuildTime.Value.ToString());
Expand Down Expand Up @@ -463,7 +469,21 @@ private void ScanAndroidDevices() {
}
}

private void OnBuildSettingsChanged() {
private void OnBuildSettingsChanged()
{
// Only set this if supporting SDK that needs Android (and is installed!).
#if OCULUS_SUPPORTED
#if UNITY_EDITOR_WIN
string adbExe = "adb.exe";
#else
string adbExe = "adb";
#endif
// If we're on Android cache the path to adb as it used during building. Need to do it pre-work so on main thread.
m_adbPath = BuildTiltBrush.GuiSelectedBuildTarget == BuildTarget.Android
? Path.Combine(UnityEditor.Android.AndroidExternalToolsSettings.sdkRootPath, "platform-tools", adbExe)
: null;
#endif

m_currentBuildPath = BuildTiltBrush.GetAppPathForGuiBuild();
if (File.Exists(m_currentBuildPath)) {
m_currentBuildTime = File.GetLastWriteTime(m_currentBuildPath);
Expand Down Expand Up @@ -524,13 +544,8 @@ private void OnBuildSettingsChanged() {

public static string[] RunAdb(params string[] arguments) {
var process = new System.Diagnostics.Process();
#if UNITY_EDITOR_WIN
process.StartInfo =
new System.Diagnostics.ProcessStartInfo("adb.exe", String.Join(" ", arguments));
#else
process.StartInfo =
new System.Diagnostics.ProcessStartInfo("adb", String.Join(" ", arguments));
#endif
new System.Diagnostics.ProcessStartInfo(m_adbPath, String.Join(" ", arguments));
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
Expand All @@ -541,7 +556,6 @@ public static string[] RunAdb(params string[] arguments) {
Concat(process.StandardError.ReadToEnd().Split('\n')).ToArray();
}


private void Update() {
if (BuildTiltBrush.GuiSelectedBuildTarget == BuildTarget.Android) {
ScanAndroidDevices();
Expand Down

0 comments on commit 8ca2f95

Please sign in to comment.