Getting Visual Studio to correctly debug a hybrid Java/C++ app on an Android phone

huangapple go评论65阅读模式
英文:

Getting Visual Studio to correctly debug a hybrid Java/C++ app on an Android phone

问题

Ok, the problem is easily stated. I want to debug the C++ portion of code that is written in a mix of Java and C++ on an actual phone (as opposed to an emulator) running Android version 13 through Visual Studio 2022. The phone is in developer mode, is attached by USB cable, and permanently trusts the PC. The C++ code is written for Visual Studio and cannot be debugged through Android Studio.

我要解决的问题很简单。我想要在实际手机上(而不是模拟器)通过Visual Studio 2022来调试混合了Java和C ++的代码的C ++部分,该手机运行Android版本13。手机已开发者模式,通过USB电缆连接,并且始终信任PC。C ++代码是为Visual Studio编写的,不能通过Android Studio进行调试。

I have set breakpoints in the C++ code only, and have set Visual Studio to debug the ARM64 version of the app.

我只在C ++代码中设置了断点,并将Visual Studio设置为调试应用程序的ARM64版本。

Visual Studio is correctly identifying the phone and does initiate something on the device. However, the device is showing a message that it is waiting for the debugger to attach. I am then attaching Visual Studio to the adb process, since I think that's the debugger.

Visual Studio正确识别了手机,并在设备上启动了某些操作。然而,设备显示了等待调试器附加的消息。然后,我将Visual Studio附加到adb进程,因为我认为这是调试器。

Visual Studio attaches to something, since it is off and running, but the phone is still saying it is waiting for the debugger.

Visual Studio附加到了某些内容,因为它已启动运行,但手机仍然显示它正在等待调试器。

If I then try from the other direction - start the app on the phone and attach Visual Studio to the process - then Visual Studio will say "Error while trying to enter break state. Debugging will now stop. Failed to find thread 71 for break event."

如果我尝试从另一个方向开始在手机上启动应用程序并附加Visual Studio到该进程,那么Visual Studio将会显示"尝试进入中断状态时出错。调试现在将停止。找不到线程71以进行中断事件。"

If I hit cancel on the Android device after Visual Studio finishes starting up its side, then Visual Studio will report "Failed to connect to and resume the Android Java Virtual Machine. This may be because a Java debugger, such as Eclipse, is already connected. Resume the Java debugger or close it." This message is the same whether or not I've attached to adb.

如果在Visual Studio完成启动后,我在Android设备上点击取消,然后Visual Studio会报告"无法连接并恢复Android Java虚拟机。这可能是因为Java调试器,如Eclipse,已连接。恢复Java调试器或关闭它。",无论是否已附加到adb,都会显示相同的消息。

I was expecting one of these two approaches to correctly start the app, link up with Visual Studio, and permit me to debug the C++ portion of the code through breakpoints as I would any other C++ application.

我希望这两种方法中的一种能够正确启动应用程序,与Visual Studio连接,并允许我通过断点调试C ++代码的部分,就像我对待其他C ++应用程序一样。

The code all works, but I need to be able to see what's going on in the C++ portions and not just the Java code.

代码都能运行,但我需要能够查看C ++部分发生的情况,而不仅仅是Java代码。

I've checked the version of Android that is being built for and it matches the version on the phone. I'm completely out of idea for how to do this.

我已检查正在构建的Android版本,它与手机上的版本匹配。我完全不知道如何解决这个问题。

英文:

Ok, the problem is easily stated. I want to debug the C++ portion of code that is written in a mix of Java and C++ on an actual phone (as opposed to an emulator) running Android version 13 through Visual Studio 2022. The phone is in developer mode, is attached by USB cable, and permanently trusts the PC. The C++ code is written for Visual Studio and cannot be debugged through Android Studio.

I have set breakpoints in the C++ code only, and have set Visual Studio to debug the ARM64 version of the app.

Visual Studio is correctly identifying the phone and does initiate something on the device. However, the device is showing a message that it is waiting for the debugger to attach. I am then attaching Visual Studio to the adb process, since I think that's the debugger.

Visual Studio attaches to something, since it is off and running, but the phone is still saying it is waiting for the debugger.

If I then try from the other direction - start the app on the phone and attach Visual Studio to the process - then Visual Studio will say "Error while trying to enter break state. Debugging will now stop. Failed to find thread 71 for break event."

If I hit cancel on the Android device after Visual Studio finishes starting up its side, then Visual Studio will report "Failed to connect to and resume the Android Java Virtual Machine. This may be because a Java debugger, such as Eclipse, is already connected. Resume the Java debugger or close it." This message is the same whether or not I've attached to adb.

I was expecting one of these two approaches to correctly start the app, link up with Visual Studio, and permit me to debug the C++ portion of the code through breakpoints as I would any other C++ application.

The code all works, but I need to be able to see what's going on in the C++ portions and not just the Java code.

I've checked the version of Android that is being built for and it matches the version on the phone. I'm completely out of idea for how to do this.

答案1

得分: 1

Ok,解决方法之一是那种“很奇怪!”的时刻。Visual Studio必须编译到Android Studio中Java一侧支持的最低支持API,否则整个事情都会失败。我还发现,即使它们不做任何事情,我也不能同时运行Android Studio和Visual Studio。这会导致Visual Studio中的调试器卡住。

我不知道这是否独特于此软件,还是尝试将Android Studio和Visual Studio配对时的常见问题。

英文:

Ok, the solution is one of those "that's strange!" moments. Visual Studio has to compile to the MINIMUM supported API supported by the Java side in Android Studio, or the whole thing blows up. I also discovered that I can't have both Android Studio and Visual Studio simultaneously running, even if they're not doing anything. It causes the debugger in Visual Studio to jam up.

I don't know if this is unique to this software, or if it's a common issue with trying to couple Android Studio and Visual Studio.

huangapple
  • 本文由 发表于 2023年3月31日 17:21:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75896799.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定