How do I get Visual Studio to debug an Android app? - android

I'm using Visual Studio 2017 to build and deploy a NativeActivity to my Android device. It builds and deploys with no issues, but I cannot set breakpoints.
Before running, I can add a breakpoint to a line (the first line of android_main() for example) and the little red circle shows up on the left of that line in the IDE as you'd expect.
But after installing and running the app, the breakpoint doesn't trigger because the red circle has turned white - it's saying there are no debug symbols.
I've verified I'm building the Debug version and have verified the APK file is bigger and has the debug symbols by using Android Studio.
At this point it appears to me that Visual Studio itself is confused and somehow doesn't recognize the debug symbols.
I've added "-g" to the C++ options manually, and have added the Gradle line packagingOptions.doNotStrip '**.so' as well. But still this problem persists.
What would cause this behavior in Visual Studio and how can I fix it?

The Xamarin debugger can only debug managed (i.e. C#) code. Breakpoints only work with the Xamarin debugger if the project being debugged is a managed project. They don't work if the project is a native app or native library.
So you have to make NativeActivity c++ app be attached to a Xamarin Managed App(Acttach to Process)to get what you want.
1) create a c# xamarin android app and then input that xamarin managed apk file into the NativeActivity c++ app's Properties-->Debugging-->Package To Launch
2) start Xamarin c# app first and then make the Xamarin debugger active. While the managed app is still running or being debugged, right-click on the native library project and select Debug --> Attach to Android process.
Here is an example provided by Richard Walters and he provided the detailed info.

Related

How to solve 'Please select a valid device before running the application.' for Android in Visual Studio Preview 2022?

After migrating my project from Xamarin.Forms to .NET MAUI as instructed by this article, I could deploy it to Android Emulator just fine, but when I pushed it to a new branch in Gitlab, clone it to a new local folder and deploy it to Android Emulator, I got this error from the cloned project solution's Output window. The build was successful, but not so for deploy.
1>------ Deploy started: Project: x.Android, Configuration: Debug Any CPU ------
1>Please select a valid device before running the application.
1>Deploy failed
========== Deploy: 0 succeeded, 1 failed, 0 skipped ==========
My OS is Windows 10 and I use Visual Studio Community 2022 Preview (ver. 17.3.0 Preview 1.1). My Android Emulator is Pixel 5 - API 31.
I'm aware that similar questions have already been asked multiple times, but most of them were dedicated for iOS and I couldn't find the solution for Android. I've tried rebuilding my solution, unchecking and rechecking all the checkboxes in Configuration Manager, updating Android SDK, factory reset my emulator, and restart Adb server, but none of these worked.
I've also checked my selected emulator and from the looks of it, VS 2022 Preview detected my emulator just fine
as shown by this image
Outside of this project solution, VS 2022 Preview can run .NET MAUI projects without problem, with my Android Emulator's name replacing the "Start" button. Additionally, I can also switch between two Android Emulators (before I deleted one) when I open natural .NET MAUI project solutions, something I can't do for this migrated project. The dropdown just closed without doing anything, with check mark on the left of my emulator's name not moving to the newly-chosen emulator.
I'm not sure whether it's caused by VS 2022 Preview, my emulator, or my migrated project. Any help would be appreciated.
I had the same issue. What resolved it for me was setting <SingleProject>True</SingleProject> in the Android .csproj file.
I could not find much documentation on the issue. Apparently, this tag is meant to declare that the project is using MAUI's Single Project philosophy instead of Xamarin.Forms. https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/single-project
Even though my project came from a Xamarin.Forms migration, this tag seems to work.
I had the same issue, in my case Visual Studio did not add the .csproj.user file for my project automatically
I had to add this file to the git (and also edit it because I had different emulators on the other machine).

Xamarin no longer debugging my app

I've been working on a Xamarin project for a few days and have been testing it fine, but today it has suddenly stopped allowing me to debug the app, either via Live Player, or by connecting my smart phone via USB.
The only error I am getting, as far as I can see, is
Failed to debug your app
I've not got a way of testing it on iOS devices, but the built-in Windows Phone emulator runs the app fine, albeit with an error in my code popping up now and then.
What could be causing the Android version to stop debugging, or how do I at least fix it?
There are a couple of steps that can help with that issue:
Clean the solution and exit visual studio
manually delete the .vs folder in your solution directory
Delete the /obj and /bin folders in your shared code, and in each project for the platforms you are using
if you are developing for iOS, sometimes it helps to restart your mac
Start Visual Studio
Rebuild your shared code project
Rebuild every native project
Beyond that also make sure that you are using the latest versions of Visual Studio, Xamarin and Xamarin.Forms on all your computers, and that the nuGet Packages your project is using are at the very same version each in shared and native code
Also check, if your app isn't throwing an unexpected exception during its initialization. Especially if not caught, it can happen that your app crashes before your code gets executed at all.
In addition you may find further information about what is going on at Help -> Xamarin -> Open logs or in the device management in XCode (iOS only)
Try this :
Close visual studio if open.
Open App Data and then go to
(a) Local\Xamarin
(B) Local\Xamarin\Xamarin.Android
Empty these folders.
Open your project and then try to build your application.
Not a proper solution, but I uninstalled and reinstalled Visual Studio. This seems to have fixed the problem, but I've still no idea why it stopped working in the first place.

How to disable android native debugger in Android studio

Using Studio 2.3, gradle:2.2.1
When I try to attached debugger to app, it shows Android Hybrid Debugger ->
Now Launching Native Debug Session Attention! No symbol directories
found - please check your native debug
Start hybrid debugger.
And loading all *.so libraries.
I try to rename Android sdk/lldb to lldb_bak but still starting hybrid debugger.
It takes too long, waste of time. Mean while app is not responding. Can any one help me to disable native debugging. I need only java debugging.
Edit:
After uninstalling LLDB from sdk tools Android Studio ask me for Quick fix dialog saying "C++ debugger is missing". If I press yes. It install LLDB again and if I press no it gives me error saying.
Error running Android Hybrid Debugger (23533): C++ debugger package is
missing or incompatible
By the way I am using wireless debugging and I have c++ module with sources in my project.
Changing run configuration -> "Debug type" to 'Java' doesn't work for me.
I found solution. Select Java from debugger list. Enjoy. Sometime it happens :)
For the ones still looking for a permanent solution:
Go to menu Run, then Edit Configurations. Under Debugger then select the Debug Type Java.

Android App Made in Qt Not Launching

I am getting started with developing an application for Android using Qt 5.8 and am running into issues running a basic application. When I run a basic application on an Android emulator, the application fails to load and a lot of errors are printed to the Qt console. Text file of errors
Images of Qt Creator, emulator, and errors
I followed tutorials online on getting the Android development environment set up, and as far as I know, I have the SDK, the NDK, Java, and ant all set up correctly.
From "create a project" in Qt, I selected the Qt Quick Control Application, and set the kit for Androidx86 and desktop. I basically kept the application as it came, but added a teal background and two text fields, but didn't change any code.
When I run the program for desktop, it works fine and opens as shown with clickable buttons and typeable text fields. But when I try to deploy the application on any emulated Android application on 7.1, the emulator boots properly but the app that displays is just this.
The error messages that show up in the Qt Designer are and here is a file dump of the whole list of errors that showed up from trying to run the app.
I am unable to figure out what these errors mean, as I installed Qt and the android files according to the documentation but still encountered these errors and was hoping someone would know what the issue was?
Probably related to the service change or similar (QtActivity etc.) Please check the following link. (Bug fixed and resolved) Fix version: 5.7.0 RC
https://bugreports.qt.io/browse/QTBUG-52373

Android Studio debugger taking too long to start/load

I had recently intalled NDK and had worked on jni for some time. I am again now shifted to my normal Android work but now when I am applying a debugger, the debugger is taking too much time to load. It loads many so files and all which are required to debug native code/ jni related stuff. I want to disable this so that debugger knows that I do not wnt to debug any cpp files. I am using Android studio 2.2.2 and I have tried setting "Debug type" of debugger to "Java" from "Edit Configurations" but it did not helped me. It stills loads the LLDB server and related so files while stating debugger.
Any help would be really appreciated.. !!!
run app first, then press the "attach debugger to android process" button, it will open a choose process dialog, set the debugger from 'auto' to 'java'.
Its probably because you have introduced C++ native libraries in your App, to only debug java, click Run > Edit Configurations and then in the debugger tab, change Debug Type to Java
According to docs:
Because different debugger tools are required to debug Java/Kotlin
code and C/C++ code, the Android Studio debugger allows you to select
which debugger type to use. By default, Android Studio decides which
debugger to use based on which languages it detects in your project
(with the Auto debugger type)
The debug types available include the following:
Auto
automatically choose the best option for the code you are debugging.
For example, if you have any C or C++ code in your project, Android
Studio automatically uses the Dual debug type. Otherwise, Android
Studio uses the Java debug type.
Java
Select this debug type if you
want to debug only code written in Java or Kotlin—the Java debugger
ignores any breakpoints or watches you set in your native code.
Native (available only with C/C++ code)
Select this debug type if you want to
use only LLDB to debug your code. When using this debug type, the Java
debugger session view is not available. By default, LLDB inspects only
your native code and ignores breakpoints in your Java code. If you
want to also debug your Java code, you should switch to either the
Auto or Dual debug type.Select this debug type if you want Android Studio to
1). Go to the debugger and select view breakpoints
2).Make sure the All Breakpoint is unchecked.

Categories

Resources