简体   繁体   English

为什么默认情况下无法调试Android应用?

[英]Why is an Android app not debuggable by default?

According to Android Doc , an Android app is not debuggable by default. 根据Android Doc的说法,默认情况下无法调试Android应用。

android:debuggable android:debuggable

Whether or not the application can be debugged, even when running on a device in user mode — "true" if it can be, and "false" if not. 即使可以在用户模式下的设备上运行应用程序,也可以对其进行调试-如果可以,则为“ true”,否则为“ false”。 The default value is "false". 默认值为“ false”。

Now, provided that I create a simplest app by Android Studio through default steps. 现在,前提是我通过默认步骤通过Android Studio创建了最简单的应用。

  • The AndroidManifest.xml contains no android:debuggable specifier. AndroidManifest.xml包含android:debuggable说明符。

  • The default build.gradle file contains no debuggable specifier under buildTypes . 默认的build.gradle文件在buildTypes下不包含可调试的说明buildTypes

So, as per the Android Doc, the app should not be debuggable by default. 因此,根据Android Doc,该应用默认情况下不可调试。

However, I can always debug a newly created app by Android Studio. 但是,我始终可以通过Android Studio调试新创建的应用。

Why? 为什么?

This following post explains it well do not use debugabble attribute 下面的帖子很好地解释了不要使用debugabble属性

Here are the important notes from it. 这是重要的注释。

There were a time when the Android developer had to take care of updating the debuggable attribute of his app's manifest file, setting it to "true" for debugging, and for "false" just before releasing a new signed package. 曾经有一段时间,Android开发人员必须负责更新其应用清单文件的debuggable属性,将其设置为“ true”进行调试,并在发布新的签名包之前将其设置为“ false”。

But that time passed by on December, 2010. Although not every developer had noticed it, so many of them continue manually doing the debuggable switching. 但是那段时间是在2010年12月过去的。尽管不是每个开发人员都注意到它,但仍有许多开发人员继续手动进行可调试切换。

http://developer.android.com/tools/sdk/tools-notes.html http://developer.android.com/tools/sdk/tools-notes.html

From SDK Tools revision 8: 从SDK Tools修订版8:

Support for a true debug build. 支持真正的调试版本。 Developers no longer need to add the android:debuggable attribute to the tag in the manifest — the build tools add the attribute automatically. 开发人员不再需要在清单中的标签中添加android:debuggable属性-构建工具会自动添加该属性。 In Eclipse/ADT, all incremental builds are assumed to be debug builds, so the tools insert android:debuggable="true". 在Eclipse / ADT中,所有增量构建都假定为调试构建,因此工具会插入android:debuggable =“ true”。 When exporting a signed release build, the tools do not add the attribute. 导出签名发行版本时,这些工具不会添加属性。 In Ant, a ant debug command automatically inserts the android:debuggable="true" attribute, while ant release does not. 在Ant中,ant debug命令会自动插入android:debuggable =“ true”属性,而ant release不会。 Ifandroid:debuggable="true" is manually set, then ant release will actually do a debug build, rather than a release build. 如果手动设置了android:debuggable =“ true”,则ant release实际上将进行调试构建,而不是发布构建。 So, the best thing you can do in most of the cases is not to deal with the attribute at all, since that way you will be sure that when you are exporting a signed release it won't include debug data. 因此,在大多数情况下,您可以做的最好的事情就是根本不处理该属性,因为这样可以确保在导出签名版本时,它不会包含调试数据。

The only exception is if you actually need to distribute a signed package with debug information included, not a common case indeed... 唯一的例外是,如果您实际上需要分发包含调试信息的签名程序包,实际上并不常见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM