在 Android Studio 中的 Release Build 上启用 LogCat

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25610936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:34:25  来源:igfitidea点击:

Enable LogCat on Release Build in Android Studio

androidlogcat

提问by Christopher Francisco

By default, when I change Build Variantsto releaseI don't get any Logs on the logcat, but I do need to read release logs of my app, how can I enable this?

默认情况下,当我更改Build Variantsrelease我在 logcat 上没有任何日志时,但我确实需要阅读我的应用程序的发布日志,我该如何启用它?

回答by reVerse

Add android:debuggable="true"(default is false) to your Manifest inside the <application>tag.

添加android:debuggable="true"(默认为 false)到您的 Manifest<application>标签内。

From the docs:

从文档:

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.

android:debuggable
是否可以调试应用程序,即使在用户模式下在设备上运行 - 如果可以,则为“true”,否则为“false”。

respectively

分别

You can disable debugging by removing the android:debuggable attribute from the tag in your manifest file, or by setting the android:debuggable attribute to false in your manifest file.

您可以通过从清单文件中的标记中删除 android:debuggable 属性,或在清单文件中将 android:debuggable 属性设置为 false 来禁用调试。

Edit

编辑

You may need to add the following to your build.gradlefile inside the android{...} tag:

您可能需要将以下内容添加到build.gradleandroid{...} 标签内的文件中:

lintOptions {
   checkReleaseBuilds false
}

And as a side-note: Right on the device the Logs are always written, no matter if your application's debuggableis set to falseor true. But via the LogCatin Android Studio it's only possible if debuggable is set to true. (Just tested this)

作为一个侧面说明:对设备上的日志始终写入,不管你的应用程序的可调试设置为假的真实的。但是通过Android Studio 中的LogCat,只有在 debuggable 设置为 true 时才有可能。(刚刚测试了这个)

回答by Morten Holmgaard

I do not like the other solution because then you are not testing how the App really is deployed.

我不喜欢其他解决方案,因为那样您就没有测试应用程序的实际部署方式。

A better solution is to open the Android Device Monitorwhere you can see the logs even when in release configuration with debuggable=false.

更好的解决方案是打开Android 设备监视器,即使在使用debuggable=false.

Find it here:

在这里找到它:

Tools -> Android -> Android Device Monitor

工具 -> Android -> Android 设备监视器

Update:
Android Device Monitor was removed in Android Studio 3.2. However, it is still present in SDK, and you can use it to see the logs (it is located in $ANDROID_SKD/tools/)

更新:
Android 设备监视器已在 Android Studio 3.2 中删除。但是,它仍然存在于 SDK 中,您可以使用它来查看日志(它位于$ANDROID_SKD/tools/

回答by CoolMind

You should add

你应该添加

android {
    buildTypes {
        release {
            debuggable true

In this case you can use Log.or System.out.printlnand see logs.

在这种情况下,您可以使用Log.System.out.println查看日志。

If you cannot run release version (appis disabled), and error is shown: "apk is not signed. Please configure the signing information for the selected flavor using the Project Structure dialog", see app-release-unsigned.apk is not signed.

如果您无法运行发布版本(app已禁用),并显示错误:“apk 未签名。请使用项目结构对话框配置所选风格的签名信息”,请参阅app-release-unsigned.apk 未签名