AndroidStudio:“可调试"有什么作用? [英] AndroidStudio: What does 'debuggable' do?
问题描述
我想确切地知道 debuggable true
语句的作用:
I would like to know exactly what the debuggable true
statement does:
// build.gradle
android
{
buildTypes
{
debug
{ debuggable true
}
}
}
我我能够在不使用模拟器(genymotion)的情况下进行调试:断点有效;Log.d(...)
语句输出到 Android 监视器;
I am able to debug without it using the emulator (genymotion): the breakpoints work; the Log.d(...)
statements output to the Android Monitor;
由于 debuggable
标志位于 debug
部分的内部,无论如何它似乎都是多余的.它不应该在 buildTypes
部分之外,向 ide 指示应该使用 debug
构建类型吗?
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?
如果能对 debug
和 release
构建类型之间的区别有一些简单的外行一般背景了解,也会很好.
It would also be nice to get some simple layperson general background understanding of the difference between the debug
and release
buildtypes.
推荐答案
在 Android 上,调试器使用 JDWP.启用调试后,VM 会创建一个专用线程来侦听 JDWP 流量并响应请求.(也可以使用本机调试器,例如 gdb,但那是另一种鱼.)
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.)
在出售给消费者的设备上,通常不需要运行额外的线程,因此默认情况下应用不可调试.此外,恶意软件可能会使用调试器界面来检查或操纵正在运行的应用程序,因此禁用它是最安全的.另一方面,在模拟器上运行的任何东西都应该是可调试的,所以那里的默认行为是不同的.ro.debuggable
系统属性决定了这一点(adb shell getprop ro.debuggable
).
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
).
应用清单中的 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.
以上所有内容都与应用的运行时行为有关,与构建无关.调试版本也不同于发布版本.将 -g
标志传递给 javac
会导致输出附加信息,并且有 dx
选项将删除或保留附加调试信息.dex
文件.(我不知道 gradle 标志如何与这些交互.)
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.)
这篇关于AndroidStudio:“可调试"有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!