AndroidStudio: What does 'debuggable' do?

半腔热情 提交于 2019-12-17 20:54:22

问题


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.


回答1:


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.)




回答2:


It causes the Android gradle plugin to include the debuggable flag in the application manifest when it is generated. This allows debuggers to attach to the app while running in the emulator or on device.



来源:https://stackoverflow.com/questions/37143960/androidstudio-what-does-debuggable-do

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