Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
363 views
in Technique[技术] by (71.8m points)

android - AndroidStudio: What does 'debuggable' do?

I would like to know exactly what the debuggable true statement does:

// build.gradle
android
  {         
    buildTypes
      {
        debug
          { debuggable true
          }       
      }
  }

I am able to debug without it using the emulator (genymotion): the breakpoints work; the Log.d(...) statements output to the Android Monitor;

Since the debuggable flag is inside the debug section, it seems redundant anyway. Shouldn't it be outside the buildTypes section, indicating to the ide that the debug buildtype should be used?


It would also be nice to get some simple layperson general background understanding of the difference between the debug and release buildtypes.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

On Android, debuggers communicate with the virtual machine using JDWP. When debugging is enabled, the VM creates a dedicated thread that listens for JDWP traffic and responds to requests. (It's also possible to use a native debugger, such as gdb, but that's a different kettle of fish.)

On devices sold to consumers, there's generally no need to have the extra thread running, so by default apps are not debuggable. Also, malware could potentially use the debugger interface to examine or manipulate running apps, so it's safest to disable it. On the other hand, anything running on an emulator should be debuggable, so the default behavior there is different. The ro.debuggable system property determines this (adb shell getprop ro.debuggable).

The debuggable flag in the app manifest tells the VM that the app is under development, and connections from debuggers should be allowed whether or not the app is running on a production device.

All of the above relates to the app's runtime behavior, not the build. Debug builds are also different from release builds. Passing the -g flag to javac causes additional information to be output, and there are dx options that will strip or keep additional debug information in the .dex file. (I don't know how the gradle flag interacts with these.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...