有两种方法可以实现: 在Android Run/Debug配置中,禁用Deploy application并启用Do not launch Activity。 在工具栏中使用Attach debugger to Android process按钮:
IntelliJ >= 2022 在 Android Run/Debug 配置中选择 Deploy: Default APK 和 Launch: Nothing。 如果无法附加,请使用 Attach Debugger to Android Process 按钮:
android.os.Debug.waitForDebugger()
,以便等待调试器附加。https://groups.google.com/d/msg/android-developers/DftP5gYcwYI/j_mccTSCHNQJ - Heath Borders