Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging android device possible? #44

Open
AlejandroHuerta opened this issue Jul 13, 2017 · 23 comments
Open

Debugging android device possible? #44

AlejandroHuerta opened this issue Jul 13, 2017 · 23 comments

Comments

@AlejandroHuerta
Copy link

@AlejandroHuerta AlejandroHuerta commented Jul 13, 2017

I'm trying to debug a physical android device. I followed the steps in the Unity Documents for setting up ADB over tcp and I'm able to debug with Visual Studio 2017. When I use the Unity Attach Debugger command in VSCode I don't see my device. Is there some additional setup I'm missing?

@lukaszunity

This comment has been minimized.

Copy link
Contributor

@lukaszunity lukaszunity commented Jul 19, 2017

I'm not too familiar with Android debugging. Isn't using ADB only for native debugging?

The Unity debugger extension for VS Code is for C# debugging using a custom protocol defined by Mono. It should work if you use the Mono scripting backend and enable Script Debugging when building the Android player.

@AlejandroHuerta

This comment has been minimized.

Copy link
Author

@AlejandroHuerta AlejandroHuerta commented Jul 28, 2017

ADB is used as the transport I believe. It's in the official Unity Documentation. The issue I'm having is when I used the Unity Attach Debugger command in vs code it does not show the android device. The equivalent procedure in Visual Studio 2017 works as expected.

@gino8080

This comment has been minimized.

Copy link

@gino8080 gino8080 commented Nov 16, 2017

what is the Mono scripting backend ?

@andrewsilber

This comment has been minimized.

Copy link

@andrewsilber andrewsilber commented Jan 9, 2018

@AlejandroHuerta @lukaszunity @gino8080 Did you ever figure out a solution for this? I'm also totally blocked until I can get this thing debugging. Monodevelop does not seem to be able to see the remote device and list it as an option to connect to.

@AlejandroHuerta

This comment has been minimized.

Copy link
Author

@AlejandroHuerta AlejandroHuerta commented Jan 18, 2018

I haven't attempted again since I posted this. I use Visual Studio for now when I need to debug android.

@a-m-dev

This comment has been minimized.

Copy link

@a-m-dev a-m-dev commented Feb 27, 2018

for debugging on android device you must have android sdk on your computer , via that you would be able to access adb tools inside your android sdk , then you need to open cmd in your platform-tools folder inside android sdk directory , then in cmd type : adb logcat
this will just spit out everything that going on device
for limiting logcat to show untiy logs you can try this one:
adb logcat -s Unity
or if you want some more you can try this:
adb logcat -s Unity ActivityManager PackageManager dalvikvm DEBUG

@AlejandroHuerta

This comment has been minimized.

Copy link
Author

@AlejandroHuerta AlejandroHuerta commented Dec 2, 2018

As far as I'm aware, using log cat does not allow you to set break points, which you can do with visual studio.

@habitoti

This comment has been minimized.

Copy link

@habitoti habitoti commented Feb 1, 2019

So what is the status as of today, early 2019? Is it possible at all to debug code running on Android device with Visual Code? VC is just showing "Unity Editor", not "Android Player". Anything I am missing to get it going? I have to debug on device, as some of the required libraries don't work in Unity Editor.

@miniwolf

This comment has been minimized.

Copy link
Collaborator

@miniwolf miniwolf commented Feb 1, 2019

@habitoti
In order for the Debug Configuration for Android Player, to appear. It needs to be in your launch.json file. If you are trying to find it through the "Unity Attach Debugger" command, then it requires that the player connection can be found. Which requires your firewall to allow for this, and that the build has been configured to allow for the player to debug.

@habitoti

This comment has been minimized.

Copy link

@habitoti habitoti commented Feb 1, 2019

Probably my bad, but I just can't find proper complete instructions for a full and working setup. "Android Player" is part of the launch.json. I am deploying a debug build with "Script-Debugging" enabled. What exactly do I need to enable in the Firewall on macOS? ADB logcat can access the device logs already. Anything else I need to setup?

@miniwolf

This comment has been minimized.

Copy link
Collaborator

@miniwolf miniwolf commented Feb 1, 2019

If you can access the device using adb then I don't think network connectivity is the problem.
It sounds more like a problem with the player connection in the debugger, which has unfortunately not been resolved yet.

@Bevan67

This comment has been minimized.

Copy link

@Bevan67 Bevan67 commented Jun 19, 2019

I don't like to revive old threads but this was one of the first results when I was trying to work this out so I thought I would add a reply on how I got this working for me.

----SET UP ---
Unity 2019.1
Android SDK Installed (I used the option under Android build Support > Andoid SDK in the Unity Hub to install as part of the Unity Install)
VSCode version 1.35.1
VSCode Extension - Debugger for Unity 2.7.2 (By Unity)

In your Unity project on the build settings window ensure the following items are correct
Your Android device you are using for debugging is selected from the device drop down
Development Build check box is checked (this will make the other two required settings visible)
Script Debugging is checked
Wait for Managed Debugger is checked
image

NOTE: If your device does not show you will need to research adb.exe and how to check your android device is connected correctly and that it has authorised you computer to connect to it for debugging

In VSCode
Open the debug section from the left hand menu
Select "Android Player" from the Debug drop down (do not hit play yet)
set any break points you want
image

-- To Start Debugging --

  • In the Unity Build Settings windows and press "Build And Run"

  • Once built Unity will install the APK onto the device and you will see a dialog on the device pop up indicating it is time to connect a Managed Debugger.
    image

  • In VSCode Press the play button in front of the debug dropdown where you selected Android Player and you should see the Debug console in VSCode output that it has attached.
    image

You can then press the OK button on the Debug dialog on your device to start running your Unity project

I hope this helps someone that also finds this thread via google.

@jconst

This comment has been minimized.

Copy link

@jconst jconst commented Jul 1, 2019

Just to add my experience: I tried @Bevan67's steps, and was able to select Android Player from the debug drop-down, but when I hit the play button in VSCode to start debugging, I get an error window saying: "Could not find target name 'Android Player'. Is it running?".

It has an option to open launch.json, which I've done, and the Android Player entry shows the following:

        {
            "name": "Android Player",
            "type": "unity",
            "request": "launch"
        }

whereas the Unity Editor also has a path value:

        {
            "name": "Unity Editor",
            "type": "unity",
            "path": "/c:/Users/jconst/my-app/Library/EditorInstance.json",
            "request": "launch"
        }

So it feels like the Android Player entry needs more info than it has, but I wouldn't know what to put there.

I've had no trouble debugging the unity editor through VSCode, but now I have a bug that's only reproducible on-device, so I need to attach a debugger somehow. adb also works fine for logcat, etc. I'm going to try out Visual Studio in the meantime.

@Bevan67

This comment has been minimized.

Copy link

@Bevan67 Bevan67 commented Jul 2, 2019

Hi jconst

It took me ages to get this all working so I know how frustrating it can be. my lauch.json file has the same limited info as you have shown above so I do not think the json file is the issue.

You mention that logcat is working so it sounds like you android device is connected to you system.

A few things to possibly check:

  • In Unity>Build Settings to make sure you have the correct android device selected to use for testing.
    image

  • In Unity>Build Settings are the Development Build, Script Debugging and Wait for Managed Debugger check boxes checked?
    image

  • Are you waiting for the prompt on the android device to start the debugger.
    image

@LuizPelegrini

This comment has been minimized.

Copy link

@LuizPelegrini LuizPelegrini commented Jul 3, 2019

I don't like to revive old threads but this was one of the first results when I was trying to work this out so I thought I would add a reply on how I got this working for me.

----SET UP ---
Unity 2019.1
Android SDK Installed (I used the option under Android build Support > Andoid SDK in the Unity Hub to install as part of the Unity Install)
VSCode version 1.35.1
VSCode Extension - Debugger for Unity 2.7.2 (By Unity)

In your Unity project on the build settings window ensure the following items are correct
Your Android device you are using for debugging is selected from the device drop down
Development Build check box is checked (this will make the other two required settings visible)
Script Debugging is checked
Wait for Managed Debugger is checked
image

NOTE: If your device does not show you will need to research adb.exe and how to check your android device is connected correctly and that it has authorised you computer to connect to it for debugging

In VSCode
Open the debug section from the left hand menu
Select "Android Player" from the Debug drop down (do not hit play yet)
set any break points you want
image

-- To Start Debugging --

  • In the Unity Build Settings windows and press "Build And Run"
  • Once built Unity will install the APK onto the device and you will see a dialog on the device pop up indicating it is time to connect a Managed Debugger.
    image
  • In VSCode Press the play button in front of the debug dropdown where you selected Android Player and you should see the Debug console in VSCode output that it has attached.
    image

You can then press the OK button on the Debug dialog on your device to start running your Unity project

I hope this helps someone that also finds this thread via google.

The Debug dialog appears on my phone, however when I press play on visual studio code, the error message stills appears.

@BinaryNate

This comment has been minimized.

Copy link

@BinaryNate BinaryNate commented Jul 3, 2019

Same issue here—I carefully followed Bevan67's helpful steps, but when my app displays the "You can attach a managed debugger now if you want" message and I press VS Code's green play button to attach the debugger, I get the message "Could not find target name 'Android Player'. Is it running?". I'll keep looking into this.

image

@Bevan67

This comment has been minimized.

Copy link

@Bevan67 Bevan67 commented Jul 3, 2019

Sorry to hear it is still not working, unfortunately it sounds like you have already tried/confirmed all of the fixes I am aware of. Here are some other tips from a Microsoft doc about similar issues with Visual Studio that might help.

Hopefully someone else with some extra knowledge of the issue might be able to offer some other tips?

Unable to attach

  • Try to temporarily disable your antivirus or create exclusion rules for both VS and Unity.
  • Try to temporarily disable your firewall or create rules for allowing TCP/UDP networking between VS and Unity.
  • Some programs, like Team Viewer, can interfere with process detection. You can try to temporarily stop any extra software to see if it changes something.
  • Do not rename the main Unity executable, as VSTU is only monitoring "Unity.exe" processes.
@Britvich

This comment has been minimized.

Copy link

@Britvich Britvich commented Jul 3, 2019

Same problem for me.

Unity 2019.2.0b7
VSCode Insider 1.36.0-insider
Debugger for Unity 2.7.2
MacOS 10.14.5

also doesn't work with...

Debugger for Unity 3.0.1

@drewjosh

This comment has been minimized.

Copy link

@drewjosh drewjosh commented Oct 24, 2019

I don't like to revive old threads but this was one of the first results when I was trying to work this out so I thought I would add a reply on how I got this working for me.

----SET UP ---
Unity 2019.1
Android SDK Installed (I used the option under Android build Support > Andoid SDK in the Unity Hub to install as part of the Unity Install)
VSCode version 1.35.1
VSCode Extension - Debugger for Unity 2.7.2 (By Unity)

In your Unity project on the build settings window ensure the following items are correct
Your Android device you are using for debugging is selected from the device drop down
Development Build check box is checked (this will make the other two required settings visible)
Script Debugging is checked
Wait for Managed Debugger is checked
image

NOTE: If your device does not show you will need to research adb.exe and how to check your android device is connected correctly and that it has authorised you computer to connect to it for debugging

In VSCode
Open the debug section from the left hand menu
Select "Android Player" from the Debug drop down (do not hit play yet)
set any break points you want
image

-- To Start Debugging --

* In the Unity Build Settings windows and press "Build And Run"

* Once built Unity will install the APK onto the device and you will see a dialog on the device pop up indicating it is time to connect a Managed Debugger.
  ![image](https://user-images.githubusercontent.com/10668792/60474675-c5525900-9cb6-11e9-99c7-00fcfb170a71.png)

* In VSCode Press the play button in front of the debug dropdown where you selected Android Player and you should see the Debug console in VSCode output that it has attached.
  ![image](https://user-images.githubusercontent.com/10668792/60474690-df8c3700-9cb6-11e9-98ca-2075c54b4920.png)

You can then press the OK button on the Debug dialog on your device to start running your Unity project

I hope this helps someone that also finds this thread via google.

Thanks for your detailed explanation. I do exactyl the same procedures as you do, but I also get the "Cannot find the target Android player" message.
Running Unity 2019.2.9f1
I'm tryin to switch to Visual Studio now..

@andrewsilber

This comment has been minimized.

Copy link

@andrewsilber andrewsilber commented Oct 25, 2019

@edwonia

This comment has been minimized.

Copy link

@edwonia edwonia commented Nov 25, 2019

same issue as everyone else for me "Could not find target name 'Android Player'"

@khambadkone

This comment has been minimized.

Copy link

@khambadkone khambadkone commented Dec 24, 2019

The instructions shared here are perfect. The only thing that got me stuck was that the game was running on a device with a VPN ; you have to ensure your machine and mobile are on the same network.

#44 (comment)

@ecv80

This comment has been minimized.

Copy link

@ecv80 ecv80 commented Mar 29, 2020

Thanks @Bevan67 for the detailed instructions. Sadly neither I could get it to work and I'm getting the same as @BinaryNate.

One thing I noticed that may be relevant is that non-development builds are actually built & run, but when I check DEVELOPMENT built, it WON'T LAUNCH it. This is 2019.2.0b7 (Linux) and a Xiaomi Redmi Note 5A.

Running the app manually does get me the "waiting for managed debugger" dialog but VSCode debugger can never connect to it. No problems connecting through adb otherwise.

I hope someone will figure this out completely soon :) Hunting bugs without a debugger can be bothersome at best :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.