Java 如何在尝试调试应用程序时修复“无法连接到远程进程”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53962831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 00:57:05  来源:igfitidea点击:

How do I fix "Could not connect to remote process" while trying to debug the application?

javaandroidandroid-studiodebugging

提问by SAPHI

I am making a android studio project and I try to debug my application.

我正在制作一个 android studio 项目,并尝试调试我的应用程序。

Running the application works fine, but when I try to debug it I get this error:

运行应用程序工作正常,但是当我尝试调试它时,我收到此错误:

Could not connect to remote process. Aborting debug session.

Could not connect to remote process. Aborting debug session.

What can I do to fix the issue?

我能做些什么来解决这个问题?

采纳答案by Daniel B.

You need to restart the ADB.

您需要重新启动亚行。

kill adb.exe process.

杀死 adb.exe 进程。

how to restart ADB manually from Android Studio

如何从 Android Studio 手动重启 ADB

回答by Azhagthott

Check if you have selected the right Build Variant, usually "release" comes with debuggable false

检查您是否选择了正确的 Build Variant,通常“ release”附带debuggable false

Example:

例子:

 buildTypes {
        release {
            debuggable false
            ....
        }
    }

is not recommendable change releaseto debuggable true, just change the right variant

不推荐将发布更改为debuggable true,只需更改正确的变体

   debug {
        debuggable true
        ....
    }

回答by nuwancy

In My case, For some reason I disabled Instant run and it has changed the Launch value from "Default Activity" to "Nothing" in "Run/Debug configurations". So always it says "Could not connect to remote process. Aborting debug session" and I was not able to debug. I enabled Instant and changed the Launch value from "Nothing" to "Default Activity" in "Run/Debug configurations" and it worked. Hope this will help some one.

在我的情况下,出于某种原因,我禁用了即时运行,它已将“运行/调试配置”中的“启动”值从“默认活动”更改为“无”。所以总是说“无法连接到远程进程。中止调试会话”,我无法调试。我启用了 Instant 并在“运行/调试配置”中将 Launch 值从“Nothing”更改为“Default Activity”并且它起作用了。希望这会帮助某人。

(to get Run/Debug configurations, click "app" drop down and click Edit Configurations)

(要获取运行/调试配置,请单击“应用程序”下拉菜单,然后单击“编辑配置”)

回答by Kevin ABRIOUX

In command line :

在命令行中:

adb kill-server && adb start-server

This command will restart ADB

此命令将重新启动 ADB

回答by Yennefer

By default Android Studio builds the debugversion of the application. However, during the publishing phase you may have switched to the releaseone as the tutorial suggests.

默认情况下,Android Studio 构建debug应用程序的版本。但是,在发布阶段,您可能已经release按照教程的建议切换到了那个。

ADB won't be able to attach to the application unless you revert to the debugconfiguration oryou allow to the debug the releaseone.

除非您恢复debug配置允许调试该配置,否则 ADB 将无法附加到应用程序release

If nothing of this works, you may resort in restarting ADB as explianed in How to restart ADB manually from Android Studio

如果这些都不起作用,您可以按照如何从 Android Studio 手动重启 ADB 中的说明重新启动 ADB

Revert to debug configuration

恢复到调试配置

  1. Choose Build->Select Build Variant
  2. Pick up debugin the second column
  3. Deploy the application again
  1. 选择Build->Select Build Variant
  2. debug在第二列拿起
  3. 再次部署应用程序

Allow the release version to be debugged

允许调试发布版本

  1. Select your application node in the tree
  2. Right click and choose Open Module Settings(or hit F4)
  3. Select Build Variantson the left
  4. Choose releaseon the right
  5. Set debuggableto true
  6. Apply and deploy the application
  1. 在树中选择您的应用程序节点
  2. 右键单击并选择打开模块设置(或按 F4)
  3. 选择左侧的构建变体
  4. 选择release右边
  5. 设置debuggabletrue
  6. 应用和部署应用程序

Keep in mind that your life won't be easy as your application may be optimized and therefore not debugger friendly (e.g. you might not be able to step in certain methods, or view some local variables).

请记住,您的生活并不容易,因为您的应用程序可能已优化,因此对调试器不友好(例如,您可能无法单步执行某些方法,或查看某些局部变量)。