android debugger does not stop at breakpoints

2020-07-01 04:30发布

I am seeing debug statements in the console but the debugger does not stop on any breakpoints. I tried clearing all breakpoints and adding them back in. Not sure how this can happen but it is.

10条回答
放我归山
2楼-- · 2020-07-01 05:05

if you have added some build type in build.gradle check to have debuggable true

buildTypes {
    debug {
        debuggable true
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    } 

    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
查看更多
冷血范
3楼-- · 2020-07-01 05:06

Have you set the debuggable flag in the AndroidManifest? If you miss that, do so by adding android:debuggable="true" in the application tag. It should look like that in the end:

<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
查看更多
放我归山
4楼-- · 2020-07-01 05:06

For Android Studio:

  • Check if the option Mute Breakpoints is enabled by mistake. The icon looks like this:

Android debug toolbar

For Eclipse:

  • Check if the option "Skip All Breakpoints" is enabled by mistake. It is the last icon on the following toolbar skip-all icon

eclipse toolbar

查看更多
等我变得足够好
5楼-- · 2020-07-01 05:06

In my case, the app created a service with a different process with android:process=":service" in the AndroidManifest. So I was setting breakpoints in the service process code while the debugger is automatically attached to the main app process. Pretty stupid of me but it might help someone else.

You attach to the service process with Run > Attach Debugger To Android Process and choose the service process. You might need to add android.os.Debug.waitForDebugger(); to your service process code if you can't attach in time manually.

As far as I know, there's no way to automatically tell Android Studio or IntelliJ to attach to a different process before running.

查看更多
登录 后发表回答