Android Studio's debugger not stopping at breakpoints within library modules

有些话、适合烂在心里 提交于 2019-11-27 19:34:22

As stated in the comments of this issue, setting minifyEnabled false in the debug build is the best practice. By setting this variable in the app module you are disabling the entire proguard build process. It is useful when optimizing the release build, but gives some problems if you are testing and developing.

olik79

I kind of solved it, although I don't fully understand it yet. The problem was that ProGuard still was active like @Feantury suggested. I don't know why that was the case as I had specified minifyEnabled false in every build.gradle position I could imagine, but it seems it didn't have any effect.

As I had a crash just a few minutes ago, I saw lines in the stacktrace that looked like so:

java.lang.NullPointerException
        at com.example.MyClass(Unknown Source)
        ...

That made ProGuard the number one suspect for me. After some searching around, I found another SO question that deals with the Unknown Source problem. I tried the suggested solution for debugging with ProGuard enabled and voilà it worked!

Simply add the following lines to proguard-rules.txt:

-renamesourcefileattribute SourceFile    
-keepattributes SourceFile,LineNumberTable
smoothumut

in addition to olik79's answer, I would like to add that , these two lines will make your app hit to breakpoints in fragments. otherwise it may baypass fragments

-keep public class * extends android.support.v4.** {*;}
-keep public class * extends android.app.Fragment

here is my complete edit on proguard-android.txt in sdk\tools\proguard

# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**

-keep class !android.support.v7.internal.view.menu.**,android.support.** {*;}
-ignorewarnings
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

-keep public class * extends android.support.v4.** {*;}
-keep public class * extends android.app.Fragment

I had a problem with trying to debug Kotlin code. The debugger wasn't stoping at any of the breakpoints. It turns out it was an issue with Instant run. I removed all the build directories from my project then I uninstalled the app after that I disabled Instant run.

To disable Instant run go to File > Settings > Build, execution, deployment > Instant run > Uncheck Enable Instant Run

Hartok

In fact, there's a known issue in Android Studio: Gradle plugin does not propagate debug/release to dependencies. It seems to happen in A Studio 1.4 and 1.5 at least.

When an app is compiled in debug, its modules are in fact compiled in release. That's why proguard may be enabled in debug.

I recommend this answer that worked for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!