Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Feedback Android Logcat Package Feedback

Discussion in 'Android' started by Tomas1856, Dec 8, 2018.

  1. AllanRW

    AllanRW

    Joined:
    Nov 6, 2014
    Posts:
    22
    "Open Terminal" button not working on MacOS

    Code (CSharp):
    1. Win32Exception: Cannot find the specified file
    2. System.Diagnostics.Process.StartWithShellExecuteEx (System.Diagnostics.ProcessStartInfo startInfo) (at <ae22a4e8f83c41d69684ae7f557133d9>:0)
    3. System.Diagnostics.Process.Start () (at <ae22a4e8f83c41d69684ae7f557133d9>:0)
    4. (wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start()
    5. System.Diagnostics.Process.Start (System.Diagnostics.ProcessStartInfo startInfo) (at <ae22a4e8f83c41d69684ae7f557133d9>:0)
    6. System.Diagnostics.Process.Start (System.String fileName, System.String arguments) (at <ae22a4e8f83c41d69684ae7f557133d9>:0)
    7. Unity.Android.Logcat.AndroidLogcatUtilities.OpenTerminal (System.String workingDirectory) (at Library/PackageCache/com.unity.mobile.android-logcat@1.0.0/Editor/AndroidLogcatUtilities.cs:230)
    8. Unity.Android.Logcat.AndroidLogcatConsoleWindow.OnGUI () (at Library/PackageCache/com.unity.mobile.android-logcat@1.0.0/Editor/AndroidLogcatConsoleWindow.cs:423)
    9. System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <567df3e0919241ba98db88bec4c6696f>:0)
    10. Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    11. System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <567df3e0919241ba98db88bec4c6696f>:0)
    12. System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <567df3e0919241ba98db88bec4c6696f>:0)
    13. UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at /Users/builduser/buildslave/unity/build/Editor/Mono/HostView.cs:359)
    14. UnityEditor.HostView.Invoke (System.String methodName) (at /Users/builduser/buildslave/unity/build/Editor/Mono/HostView.cs:353)
    15. UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at /Users/builduser/buildslave/unity/build/Editor/Mono/HostView.cs:329)
    16. UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect, System.Boolean floatingWindow, System.Boolean isBottomTab) (at /Users/builduser/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:374)
    17. UnityEditor.DockArea.OldOnGUI () (at /Users/builduser/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:341)
    18. UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize) (at /Users/builduser/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:298)
    19. UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect) (at /Users/builduser/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:483)
    20. UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e) (at /Users/builduser/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:466)
    21. UnityEngine.UIElements.IMGUIContainer.HandleEvent (UnityEngine.UIElements.EventBase evt) (at /Users/builduser/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:447)
    22. UnityEngine.UIElements.MouseCaptureDispatchingStrategy.DispatchEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at /Users/builduser/buildslave/unity/build/Modules/UIElements/Events/MouseCaptureDispatchingStrategy.cs:93)
    23. UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at /Users/builduser/buildslave/unity/build/Modules/UIElements/EventDispatcher.cs:280)
    24. UnityEngine.UIElements.EventDispatcher.Dispatch (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, UnityEngine.UIElements.DispatchMode dispatchMode) (at /Users/builduser/buildslave/unity/build/Modules/UIElements/EventDispatcher.cs:156)
    25. UnityEngine.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.UIElements.EventBase e, UnityEngine.UIElements.DispatchMode dispatchMode) (at /Users/builduser/buildslave/unity/build/Modules/UIElements/Panel.cs:190)
    26. UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at /Users/builduser/buildslave/unity/build/Modules/UIElements/UIElementsUtility.cs:255)
    27. UnityEngine.UIElements.UIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at /Users/builduser/buildslave/unity/build/Modules/UIElements/UIElementsUtility.cs:78)
    28. UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at /Users/builduser/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179)
    29.  
     
  2. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    446
    >> Moved Android Settings under Preferences->Analysis

    Is it still there? Can't find Analysis under Edit->Preferences
     
  3. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    446
    Android Logcat doesn't show anything when connected to an LG6 device running Android 8.0.0. I enabled USB debugging on the device and authorized the PC to connect to it. Any suggestions?
     
  4. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    2,313
    What's MacOS version are you using, can you spawn terminal manually?


    Still there, ensure package is installed, and active platform is Android

    In the top right corner in Android logcat window, click on context menu, and select Internal Log, see if any executed adb logcat commands show any errors
     
  5. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    446
    Yes, the package is installed. I'm using it. And Android is selected:
    platform.PNG

    No Analysis in Preferences:
    prefs.PNG

    I restarted Unity a couple of times, but that didn't help.
     
  6. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    2,313
    You need to check internal log.
    In the top right corner in Android logcat window, click on context menu, and select Internal Log, see if any executed adb logcat commands show any errors

    I think your Android device is simply not sending logs for some reasons, I heard about similar problems on other LG phones as well
     
  7. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    446
    I agree that it has to be an adb problem. I'm have logcat working fine with another phone on the same computer. The LG phone doesn't show anything even when I use adb logcat from command line. I know that it's not a connection issue because I can install .apk files via adb.
     
  8. AllanRW

    AllanRW

    Joined:
    Nov 6, 2014
    Posts:
    22
    Yes, I can spawn terminal manually, I'm on MacOS Catalina 10.15.2
     
  9. Sparkline

    Sparkline

    Joined:
    Feb 8, 2013
    Posts:
    90
    Hello!
    Just installed Unity 2019.3.0f6
    Started new project and switched build target to Android
    Installed Android Logcat 1.0.0 via package manager
    Connected my device via USB (usb debugging enabled)
    Opened Logcat window but it tells me that no device connected 5.png

    When I try to select device from dropdown list I get an error in console 4.png
    Though I have adb installed and it works correct long time ago.
    CMD:
    2.png
    Android Monitor:
    3.png

    Any suggestions? Tried to reinstall USB driver, restart Unity
     
  10. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    2,313
    Are you able to build for Android via Unity, also can you click on the error, and copy paste the stacktrace.

    Alternatively, enable preview packages in Package Manager, and download latest logcat preview package.
     
  11. Sparkline

    Sparkline

    Joined:
    Feb 8, 2013
    Posts:
    90
    I fixed it with unchecking these checkboxes in Edit =>Preferences => External Tools 2020-02-03_150343.png

    Now everything works as i should! Thanks
     
  12. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    2,313
    I guess for some reason Unity didn't find Android SDK, we can improve the error message if that helps
     
  13. AllanRW

    AllanRW

    Joined:
    Nov 6, 2014
    Posts:
    22
    Hey Tomas, did you get a chance to test the Open Terminal button on MacOS Catalina?
     
  14. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    2,313
    Sadly I cannot reproduce this locally, everything works fine on my end, something's is probably different in my environment

    In the meantime, you could try to check this on your end.
    * Open a project where you added Android logcat package
    * Expand Project inspector, expand Packages, Right click on 'Android Logcat', it should open the folder in Library/PackageCache
    * Copy paste com.unity.mobile.android-logcat@.... to <your_project>\Packages
    * Inside com.unity.mobile.android-logcat@.... delete Tests folder, it might cause you compile errors
    * Unity should start using Android Logcat source from <your_project>\Packages\com.unity.mobile.android-logcat@....
    * Open C# project, AndroidLogcatUtilities.cs file, locate OpenTerminal function
    Code (CSharp):
    1.        public static void OpenTerminal(string workingDirectory)
    2.         {
    3.             switch (Application.platform)
    4.             {
    5.                 case RuntimePlatform.WindowsEditor:
    6.                     System.Diagnostics.Process.Start(“cmd.exe”, string.Format(/K \“cd {0}\“”, workingDirectory));
    7.                     break;
    8.                 case RuntimePlatform.OSXEditor:
    9.                     System.Diagnostics.Process.Start(@“/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal”, workingDirectory);
    10.                     break;
    11.                 default:
    12.                     throw new Exception(“Don’t know how to open terminal on ” + Application.platform.ToString());
    13.             }
    14.         }
    * Validate if Terminal.app is really in that path above
     
    AllanRW likes this.
  15. AllanRW

    AllanRW

    Joined:
    Nov 6, 2014
    Posts:
    22
    That made it, my Terminal path is slightly different:

    /System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal
     
    Tomas1856 likes this.
  16. AllanRW

    AllanRW

    Joined:
    Nov 6, 2014
    Posts:
    22
    Hey Tomas,

    This MacOS path issue will be fixed on next update? We have a lot of projects and would be to fix these manually. This package is very useful for us! Thank you!
     
  17. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    2,313
    Yes, the new package version should be released next week. Sorry for the delay
     
    AllanRW likes this.
  18. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    2,313
    1.1.0 was released, basically it's an accumulation of previous preview packages + additional fixes, here's the full list
    Fix & Improvements.

    • Added feature 'Filter by process id'
    • Fixed addr2line functionality, when we try to resolve stacktrace
    • Correctly open Terminal on macOS Catalina
    • Fix Open Terminal button not working on Windows sometimes.
    • Reworked Connect to IP window, it's now multithreaded, thus it will not lock Editor. It's now easier to connect to Android device via IP.
    • Added icons for messages
    • Added disconnect button, you can stop logcat messages this way.
    • Improved mouse right click behavior to be consistent with the rest of Unity
    • Correctly identify Android 9 version
    • Android Settings will have color settings separated between Free skin and Pro skin.
    • Moved Android Settings under Preferences->Analysis
    • Provide proper windows title for Stacktrace Utility window
    • Right clicking log lines behavior will be consistent with other Unity windows.
    • Ctrl/CMD + C will copy log lines correctly.
    • Column seperators will be drawn correctly
    Android Logcat Settings
    • Introducing settings, accessible from Preferences. For ex., on Windows Edit->Preferences
     
  19. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    2,313
    1.2.0-preview was released (to access it, you'll need to tick Advanced->Show Preview Packages in Package Manager)

    Fix & Improvements
    • Android Logcat per project settings are saved in ProjectSettings directory.
    • Fix issue where sometimes Android Logcat would stop working if USB cable is unplugged and replugged.
    • Properly save/restore Android Logcat settings, previously settings like tags were being lost during domain reload or Editor restart.
    • Added Capture button in Capture Screen window, also capturing screen no longer will lock Unity thread.
    • Fix issue where incorrect date format in incoming log message would break whole log parsing.
    • Moved Stacktrace Utility, Capture Screen, Open Terminal under Tools menu.
    • The package list will automatically clean itself, if there's more than 5 exited packages in the list;
    • Improved documentation.
    • Added Clear button in internal log window.
    • Minimum Unity version was raised to 2019.2. The reason was to drop .NET 3.5 support.
    • 'Enter IP' window got renamed to 'Other connection options.
    • In the device selection list, you'll also able to see disconnected and unauthorized devices for informational purposes.
    • 'Other connection options' window has a Disconnect button for devices connected via Network.
    • Added device selection in Screen Capture window
    MemoryWindow
    • Introduced a window for viewing application memory in real time, more information in the docs.
    MemoryControls.png
     
  20. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    903
    With the latest Unity 2019.3.13 and Logcat 1.1 or 1.2 I cannot see the messages anymore.
    I can see everything <Time,PID,Tid, Priority, Tag> but the message field is blank.
    It happened before but I was able to get it working by enabling and disabling regex button, but now the fix doesn't work anymore.
     
  21. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    2,313
    Try clicking in top right left corner, internal log, and see if there's anything suspicious. Also what OS does your Android device have?
     
  22. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    903
    Now it restarted working on its own, don't know what changed.
    The device is an Asus zephone 3 Ultra with Android 7.0.
    If it reappear I'll try to copy the log.
     
  23. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    903
    It happened again.

     
  24. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    2,313
    The command
    Code (CSharp):
    1. 5:30:16.7578 E:/AndroidSDK/sdk\platform-tools\adb.exe -s H4AKCX002625XGK logcat --pid=16162 -v year *:V
    Contains filter by process id, I assume this is a process id of a package you have selected ?
     
  25. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    903
    I also found out the package tend to stall and slow down the application when switching scenes after a while,
    Yes, "xxxxxxxxxxxxxxxx" is actually the package name censored since it's not released yet I don't want to divulge the name.
     
  26. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    2,313
    Try executing

    Code (CSharp):
    1. E:/AndroidSDK/sdk\platform-tools\adb.exe -s H4AKCX002625XGK logcat --pid=16162 -v year *:V
    manually, after clicking Open Terminal.

    Note: --pid will be different on each application run.
     
  27. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    903
    Ok, I have to wait that it happens again, cause right now it restarted working on its own.
     
  28. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    605
    I love the logcat window so far. It has been very helpful.

    I've been building a customized build & management tool for our project and was wondering, if I could use the adb calls asynchronously for my own purposes. The ADB class API is publically available, it has the
    GetInstance
    and
    Run
    methods. However the
    Run
    method is synchronous. So using that will freeze it up for a few seconds when it is starting the ADB server.
    Is there or will there be public API available to run adb commands asynchronously and getting the results back when it is done?

    I'm using the ADB class to fetch my own device list to select a device and install / reinstall a selected apk file. Also made a packages list so I can easily uninstall apps from the target device.

    I could create the API myself but if Unity already has it available in the Logcat package it wouldn't make sense to not use it of course. But I can't find out how to run it async with the current public API.
     
  29. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    2,313
    I think you can already call ADB.Run function from any thread. Logcat package itself does that, just check the logcat package source and search for QueryDevicesAsync, which is executed on worker thread.
     
  30. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    605
    I've looked into it and it all seems to be either private or internal. The QueryDevicesAsync does indeed call the Run method. But the method itself is not async. It seems to be called asynchronous through a "Dispatcher" which runs the Action on a Thread. It is quite a complex setup to read through.
    I was actually hoping to just have a RunAsync method and let the internal Dispatcher do its job.

    But I guess I could run a thread then call the Run method then get back to the main thread to handle the result.

    Task.Run(() => devices = adb.Run(new[] { "devices" }, string.empty));
     
    Last edited: Jul 22, 2020
  31. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    2,313
    I see what you mean now, as far as I am aware there are no plans for RunAsync method for ADB class
     
  32. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    903

    You can try my code, taken from Unity answers and adapted to install and run apk, cause I think it's crazy that in 2020 I had to rebuild the apk just to test a new device.
    For my project I also did an editor gui with some checkboxes to select the action to perform after the build, install and run.


    Code (CSharp):
    1.  
    2.     public static void ExecuteCommandAsync(string executable, string argument, System.Action onEnd = null)
    3.     {
    4.         var thread = new System.Threading.Thread(delegate () { ExecuteCommand(executable,argument,  onEnd ); });
    5.         thread.Start();
    6.     }
    7.     public static void ExecuteCommand(string executable,string argument, System.Action onEnd=null)
    8.     {
    9.         try
    10.         {
    11.            
    12.             UnityEngine.Debug.Log($"============== Start Executing {executable} { argument}  ===============");
    13.  
    14.             System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(executable)
    15.             {
    16.                 WorkingDirectory = "/",
    17.                 UseShellExecute = false,
    18.                 RedirectStandardOutput = true,
    19.                 RedirectStandardError=true
    20.             };
    21.             System.Diagnostics.Process myProcess = new System.Diagnostics.Process
    22.             {
    23.                 StartInfo = startInfo
    24.             };
    25.             myProcess.StartInfo.Arguments = argument;
    26.             myProcess.Start();
    27.             string output = myProcess.StandardOutput.ReadToEnd();
    28.             string error = myProcess.StandardError.ReadToEnd();
    29.            
    30.             UnityEngine.Debug.Log($"Result for {executable} { argument} is : \n{output}");
    31.             if(!string.IsNullOrEmpty(error))  UnityEngine.Debug.LogError($"Error for {executable} { argument} is : \n{error}");
    32.             myProcess.WaitForExit();
    33.             UnityEngine.Debug.Log("============== End ===============");
    34.             if (onEnd!=null) onEnd();
    35.         }
    36.         catch (System.Exception e)
    37.         {
    38.             UnityEngine.Debug.Log(e);
    39.         }
    40.     }
    41.     void RunPlayer(string AppID)
    42.     {
    43.        
    44.         string args = $" shell monkey -p {AppID} -c android.intent.category.LAUNCHER 1";
    45.         ExecuteCommandAsync("adb", args);
    46.  
    47.     }
    48.  
    49.     void InstallPlayer(bool RunToo=false)
    50.     {
    51.         string AppID = Application.identifier;
    52.  
    53. #if UNITY_ANDROID
    54.         char Separator ='/';
    55.         //string Extension = ".apk";
    56. #else
    57.         char Separator ='/';
    58.         string Extension = ".apk"; //Need to change for IOS, haven't worked on it yet.
    59. #endif
    60.  
    61.         string ProjectPath = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf(Separator));
    62.         string PlayerPath= ProjectPath + Separator + PlayerName;
    63.  
    64.         ExecuteCommandAsync("adb", "install -r -d " + PlayerPath,
    65.             ()=>
    66.             {
    67.                 if(RunToo)
    68.                 RunPlayer(AppID);
    69.             });
    70.        
    71.  
    72.  
    73.  
    74.     }
     
  33. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    605
    Yeah well I went with Task.Run and run the method to call ADB asynchronously (such as refreshing device list, package list etc).
    I've got my own Editor UI now set up to be able to select an android device and install, uninstall and run applications on that selected device. Even built in to connect with it wirelessly. It's not perfect but it does smoothen the experience of managing things via Unity.
     
    00christian00 likes this.
  34. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    2,313
    1.2.0 is verified now.

    Changelog

    Fix & Improvements.

    • Correctly resolve top activity when device is locked.
    • Improved Stacktrace Utility, it's easier to set symbol paths and regexes.
    • Consola font is now selectable in Logcat settings.
    • Android Logcat per project settings are saved in ProjectSettings directory.
    • Fix issue where sometimes Android Logcat would stop working if USB cable is unplugged and replugged.
    • Properly save/restore Android Logcat settings, previously settings like tags were being lost during domain reload or Editor restart.
    • Added Capture button in Capture Screen window, also capturing screen no longer will lock Unity thread.
    • Fix issue where incorrect date format in incoming log message would break whole log parsing.
    • Moved Stacktrace Utility, Capture Screen, Open Terminal under Tools menu.
    • The package list will automatically clean itself, if there's more than 5 exited packages in the list.
    • Improved documentation.
    • Added Clear button in internal log window.
    • Minimum Unity version was raised to 2019.2. The reason was to drop .NET 3.5 support.
    • 'Enter IP' window got renamed to 'Other connection options.
    • In the device selection list, you'll also able to see disconnected and unauthorized devices for informational purposes.
    • 'Other connection options' window has a Disconnect button for devices connected via Network.
    • Added device selection in Screen Capture window
    Memory Window
    • Introduced a window for viewing application memory in real time, more information in the docs.
     
    fherbst and Prodigga like this.
unityunity