Android device doesn't show up as target of Unity3d debugging - android

First of all, I'm positive that I've followed all steps in the Attaching MonoDevelop Debugger To An Android Device guide correctly (most importantly: having "Development Build" and "Script Debugging" enabled in the Build Settings).
When building & running a Unity Android app, however, my device (Samsung Galaxy S5, Android 6.0.1) just doesn't show up as a possible debug target in neither MonoDevelop, nor Visual Studio. For instance in Visual Studio, after clicking on Debug -> Attach Unity Debugger, in the "Select Unity Instance" window that opens I only see the Unity3d editor (Machine: local machine, Type: Editor). Debugging a Unity project that is run in the Unity Editor works fine, only debugging a project run on the physical android device doesn't work. It's the same for MonoDevelop.
I see the device as connected and online when doing
adb devices
I can also call adb shell commands (such as ls) on that device via command line. When I open Android Studio, I also see the device as a target for Logcat and even the just mentioned Unity Android app as a debuggable process (and when selecting it, all the correct logs that are expected from the running app).
I think it's safe to rule out a fault on the debugger side, because I tried
two different developer machines (both Windows 10 with current updates and without firewalls),
two different networks (home & university)
MonoDevelop, Visual Studio Community 2015, Visual Studio Professional 2017 RC (with respective Tools for Unity),
re-installing Unity3d,
different Unity3d projects (standard example project as well as own minimal example consisting of just a Text and a Button),
manually adding android:debuggable="true" to the project's AndroidManifest and
in Visual Studio manually connecting the debugger to the device via deviceip:5555 (in the "Select Unity Instance" Window -> Input IP).
On the device, I tried to
turning the phone off and on again,
turn USB debugging off & on,
selecting the Unity App as the "debug app" (in Developer options) and enabling/disabling "Wait for debugger" (also Developer options),
connecting the device via USB cable or via adb connect deviceip:5555 and
rooting the phone.
I don't know what else to try. I'm pretty sure it's something on the device. It has worked before, however I don't know what changed since then. Any tips are appreciated.
EDIT
Ok so I got some progress. When I examined the logcat output from the app, I found lines such as
Waiting for connection from host on [192.168.2.110:55416]...
(.2.110 being the IP of the device)
So I manually entered that IP & Port in Visual Studio in "Select Unity Instance" Window -> Input IP and right after that, the logcat read
PlayerConnection accepted from [192.168.2.115] handle:0x1c
(.2.115 being my developer machine)
So the connection is there. Visual Studio just doesn't "recognize" (?) it and doesn't switch to debugging mode so it can stop at breakpoints. Does anyone have an idea how I can force it to do so?

Well, not really an answer but I've found a way to debug it after all. Amidst all the logcat output, I've also found that line:
Using monoOptions --debugger-agent=transport=dt_socket,embedding=1,defer=y,address=0.0.0.0:56785
Taking that port (and the actual device IP) and entering it in Visual Studio in the "Select Unity Instance" Window -> Input IP, the debugger finally connected.
The problem is, that port gets changed every time the app is run so in order to debug it, I'll always have to look it up. Also (that may be a different issue altogether), the output of Debug.Log or Console.WriteLine isn't caught by the debugger. The only way to read the log for now is in AndroidStudio.
So yeah, the question still stands, how come the device doesn't show up as AndroidPlayer in the Select Unity Instance Window in Visual Studio (or according place in MonoDevelop)?

It does show up if your Android device is connected to wifi. When the app starts playing, you can see it in the "Select Unity Instance" box and then you can select it.

Related

Cannot get neither the Android Emulator nor Run project to device working in Xamarin

I am using a brand new xamarin.forms solution generated with the flyout shell template in VS 2022 community edition.
When I open the emulator and follow the first time setup, where it generates a common android device I get this error when trying to launch the emulator. I also get this error when creating a device myself.
Unknown AVD Name Error <- This part has been fixed by setting the ANDROID_SDK_HOME variable to the correct directory in the Environment Variables in system settings. But the emulator can still not be used for debugging.
I have tried looking around for solutions on all sorts of forums to get the emulator to work, but didn't find anything that made a difference.
I have tried running on a local device using USB instead as it was suggested that it was easier to get to work then the emulator, which didn't work either. The device does not show up in the Android Emulator drop-down menu. I then tried different cables and it still did not show up as a detected device.I then tried via wireless connection just in case something was up with the cables. It still doesn't show up. But if I check the devices through the adb command prompt I can see the device is connected and authorized, both when using the cable and when using the wireless connection. And the computer itself detects the device just fine.
The Device is in developer mode.
USB debugging is on.
The computer is approved as a trusted device.
Android project is set as start up project.
SDK's and tools have been downloaded using the Android SDK manager.
USB drivers have been downloaded for the device.
I have already tried
closing and opening VS multiple times.
Unloading and reloading the project.
Setting the device to PTP mode instead.
Reinstalling VS including deleting and regenerating the Java and Android folders.
Uninstalling VS 2022 and trying 2019 instead.
Generating a new VS solution.
downloading and installing the JDK manually.
Seeing that Virtual emulation is on in the BIOS.
Making sure the system is able to run Hyper-V and that it is on.
checking that the folder paths are set correctly in the options menu.
Making sure all nuget packages are up to date.
Any suggestions would be highly appreciated as I cannot debug and test the device properly at the moment.
If you see an error about a failure to install the APK on the emulator or a failure to run the Android Debug Bridge (adb), verify that the Android SDK can connect to your emulator. To verify emulator connectivity, use the following steps:
Launch the emulator from the Android Device Manager (select your virtual device and click Start).
Open a command prompt and go to the folder where adb is installed. If the Android SDK is installed at its default location, adb is located at C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe; if not, modify this path for the location of the Android SDK on your computer.
Type the following command:
adb devices
If the emulator is accessible from the Android SDK, the emulator should appear in the list of attached devices. For example:
List of devices attached
emulator-5554 device
If the emulator does not appear in this list, start the Android SDK Manager, apply all updates, then try launching the emulator again.
Update:
you can open the Android Device Manager first.
Select the device you want to run and click the Start button, so that the virtual machine can be started and detected, and then your virtual machine The device will be added to the Android Emulators menu.
I ended up wiping the hard-drive and starting from scratch. This time all I had to do was install VS and enable Hyper-v and everything worked as it should right away.
I have absolutely zero idea what caused this issue, but a complete wipe fixed it.

Nexus 5X not identified correctly in Android Studio

I'm (very) new to Android development, and am trying to test my app on my Nexus 5X. I've previously done it successfully, on the same 5X, with the same version of Android Studio on the same computer, so I'm not sure what's changed.
With the phone connected via USB to my laptop running Linux Mint (18.1), in the 'Select Deployment Target' screen in Android Studio (v2.3.1) under 'Connected Devices', I see a single entry:
00b9xxxxxxxxcb26 [null]
(that's a full ID, but I'm not sure how sensitive it is as a value, so am being conservative).
I'm sure previously here it said "Nexus 5X" or something similar.
If I try to deploy to that device it fails, with an error saying:
Session 'mobile': Error Installing APK
No message appears on the phone, which definitely has USB Debugging enabled.
There's nothing in the Android Monitor tab, and the Event Log just shows:
21:42 Executing tasks: [:mobile:assembleDebug]
21:42 Gradle build finished in 661ms
21:42 Session 'mobile': Error Installing APK
I've tried updating Android Studio (I was previously on 2.3, and the same happened), restarting the phone and Android Studio. The app runs successfully in a Nexus 5X emulator.
I can't think of any other useful information that might be relevant, except that I'm connected USB-C to USB-C, but I'm pretty sure that was how I connected the phone before, I can try USB-A to USB-C tomorrow, but don't have that cable available right now. Any other thoughts?
Possible solutions:
disable USB debugging and re-enable it again
check the cable - if it's not the cable, connect the phone directly to the computer, without using any hub or anything
stop adb deamon: adb kill-server, and then remove the .android directory in your home directory - this will remove the debug keys *
removing your debug keys and restarting adb should make appear a confirmation dialog on your android device when you connect it
Adding a new answer, because although Adam Szewera and A. Petrizza's answers helped get me there, neither of them quite includes the key problem.
That was that I'd changed the 'Use USB to...' option, which appears as a notification when you plug the phone in to a computer to 'Charge this device'. Changing it to 'Transfer files' immediately fixed the problem, and now I see "LGE Nexus 5X ..." in Android Studio, and can deploy to it as before.
Thanks both for your pointers which got me thinking straight :)
Plan A.
You need to make sure the cord that is plugged into the computer is used for data transfer and not just for charging your device!
Go to your phone's settings and make sure that the developer settings are turned on (my phone tends to turn this off randomly sometimes).
If all else fails try the good ole' phone off and back on again.
Plan B.
go to Run
Click on Edit Configurations
Select the project
find the Target Device section under the General tab on the Android Application page.

Android Studio not detecting device but DDMS and IntelliJ are

I'm using Android Studio 0.8.9. The issue, it is not detecting my device. I tried it with a couple of different devices. "adb devices" on the command line shows the device. adb logcat on the command line works. DDMS view (Android Device Monitor) recognizes the device and shows logcat too! But the Android Studio shell does not show it. I'm at my wit's end. I have tried restarting everything involved in the process - Android Studio, adb, my phone and even my Mac. Nothing helped. It's not a one-off problem either - I have had this 2 weeks ago, tried everything I could. Gave up and worked on something else. Now I'm back to working on Android and the issue is still there. I suspect it's something to do with my Studio config, but haven't been able to figure it out.
update: I downloaded IntelliJ and that is working fine too. So either I'm running into a weird bug in Android Studio that nobody else seems to be facing, or my Android Studio settings are wrong!
Follow the steps !
Step1> Connect your phone to computer via USB Enable USB debugging on your phone
Step2> Right click on project -> Run As -> Run Configuration
Step3> There are three tabs, Here select the second tab
Step4> In your project and check if your mobile device is detected ? If yes the click on it and Click Run button.

Unity Remote 4 mac/android not working

I am trying to run "unity remote 4" test project (http://u3d.as/content/unity-technologies/unity-remote-4/7PZ) on Unity Free for Mac.
I have "Unity Remote 4" installed on Samsung galaxy.
I have android SDK installed, adb devices command returns 0019e6197e378e device.
I have turned on all necessary developer options on the phone.
When I press Play in Unity, it says accepted incoming socket.
But nothing shows up on app but the welcome screen asking me to press Play in Unity.
Here are the steps you might be missing
Go to Edit Menu:- Project Setting:- Editor.
Under Unity Remote: Device choose "Any Android Device".
Connect your android device through usb cable.
Run unity Remote on your android device.
Now press play button in unity.
It will launch your game in android device.
Make sure no android emulator (bluestack, genimotion etc) is running in background. Sometimes priority of emulator gets higher than device and operations like "Build & run" or debugging etc starts producing their outputs on emulator rather than device :)

Not Able to debug android application direclty from eclipse to device

i have one doubt,i have created new project in eclipse with android 2.3.1 and try to debug directly from eclipse to device.and it's wokring well,it's debugg in device.now when i am converting that version of android 2.3.1 to GoogleApi 2.3.1 by right clicking project and changing android property.after that when i run my project i am getting such warrining kind of symbol as u can see in below image.
again when i am changing version to simple android 2.3.1 than it's get debugging from eclipse to device.
my device name is Sony Ericon Walk Man Live and ya one more thing Google API version working well when i copy apk to sd card directly and installed in device,but getting problem only when i am running from eclipse to device directly.
One another thing i noticed is that when i create a simple project than right clicking project and runing it's asking me to wether to run in device or emulator but in older one it's not even asking and directly running in emulator...in both's project manifest there is no tag like android:debuggable="true/false" also...
any one have idea what is a solution of this problem i have already insatlled device driver to pc as well.
please help me to short out this
Thanks in advance
Aamirkhan I.
Enabling USB debugging is key, but there's something else as well. Eclipse, by default, runs your application automatically after the first run. So, if you choose an emulator as your first run, Eclipse will default to run by emulator every run afterwards.To change this, go to your "Run Configurations".
There will be an option to run manually or automatically.
Choose "Manual" and you will prompted to choose between your emulator and device every time you decide to run. Otherwise, you can set whether to run automatically with your device or emulator.
try as in this link
If you already connected your mobile device with your computer via the USB cable, please unplug it from your phone, otherwise your device will prompt you a warning requesting to do so.

Categories

Resources