构建 Android Studio 项目时如何添加 Stacktrace 或调试选项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21674091/
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 04:54:58  来源:igfitidea点击:

How to Add Stacktrace or debug Option when Building Android Studio Project

androidandroid-studiostack-trace

提问by Neoh

I was trying to investigate the project build error in the console output as follow:

我试图调查控制台输出中的项目构建错误,如下所示:

:myapp:processDebugResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
...
...

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

I suspect it has something to do with resource not found error. My question is, at IDE level how can I add --stacktraceor --debugoption so that it can produce more information for me to debug?

我怀疑它与资源未找到错误有关。我的问题是,在 IDE 级别,我如何添加--stacktrace--debug选择以便它可以生成更多信息供我调试?

回答by pyus13

You can use GUI to add these gradle command line flags from

您可以使用 GUI 从以下位置添加这些 gradle 命令行标志

File > Settings > Compiler (Gradle-based Android Project)

For MacOS user, it's here

对于 MacOS 用户,它在这里

Android Studio > Preferences > Build, Execution, Deployment > Compiler

like this (add --stacktraceor --debug)

像这样(添加--stacktrace--debug

enter image description here

在此处输入图片说明

(Note that the screenshot is from before 0.8.10, the option is no longerin the Compiler > Gradlesection, it's now in a separate section named Compiler (Gradle-based Android Project))

(请注意,截图是 0.8.10 之前的,该选项不再在该Compiler > Gradle部分中,现在位于名为 的单独部分中Compiler (Gradle-based Android Project)

回答by jpa57

On the Macversion of Android Studio Beta 1.2, it's under

在 的Mac版本上Android Studio Beta 1.2,它在

Android Studio->preferences->Build, Execution, Deployment->Compiler

Android Studio->preferences->Build, Execution, Deployment->Compiler

回答by Angel Koh

In Android Studios 2.1.1, the command-line Options is under "Build, Execution, Deployment">"Compiler"

在 Android Studios 2.1.1 中,命令行选项位于“构建、执行、部署”>“编译器”下

enter image description here

在此处输入图片说明

回答by Francois

What I use for debugging purposes is running the gradle task with stacktrace directly in terminal. Then you don't affect your normal compiles.

我用于调试目的是直接在终端中使用 stacktrace 运行 gradle 任务。那么你不会影响你的正常编译。

From your project root directory, via terminal you can use:

从您的项目根目录,通过终端您可以使用:

./gradlew assembleMyBuild --stacktrace

回答by user1551978

To add a stacktrace click on the Gradle on the right side of Android project screen;

要添加堆栈跟踪,请单击 Android 项目屏幕右侧的 Gradle;

  1. Click on the settings icon; this will open the settings page,
  2. Then click on compiler
  3. Then add the command --stacktraceor --debugas shown;

  4. Run the application again to get the gradle report.

  1. 点击设置图标;这将打开设置页面,
  2. 然后点击编译器
  3. 然后添加命令--stacktrace--debug如图所示;

  4. 再次运行应用程序以获取 gradle 报告。

回答by auspicious99

(edited Dec 2018: Android Studio 3.2.1 on Mac too)

(2018 年 12 月编辑:Mac 上也有 Android Studio 3.2.1)

For Android Studio 3.1.3 on a Mac, it was under

对于 Mac 上的 Android Studio 3.1.3,它在

Android Studio -> Preferences -> Build, Execution, Deployment -> Compiler

Android Studio -> Preferences -> Build, Execution, Deployment -> Compiler

and then, to view the stack trace, press this button

然后,要查看堆栈跟踪,请按此按钮

button to show stack trace

按钮显示堆栈跟踪

回答by gmetax

For Android Studio 3.1.3 it was under

对于 Android Studio 3.1.3,它位于

File -> Settings -> Build, Execution, Deployment -> Compiler

文件 -> 设置 -> 构建、执行、部署 -> 编译器

回答by Fredy sanchez .m

my solution is this:

我的解决方案是这样的:

configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-v4:27.1.0'
    }
}

回答by Anthony Cannon

To be able to run options like --stacktracewithin a gradle command, you need to put it at the beginning, like:

为了能够--stacktrace在 gradle 命令中运行选项,您需要将其放在开头,例如:

./gradlew --stacktrace assembleMyBuild

./gradlew --stacktrace assembleMyBuild

回答by Vladyslav Zavalykhatko

In case you use fastlane, additional flags can be passed with

如果您使用 fastlane,则可以传递额外的标志

gradle(
   ...
   flags: "{your flags}"
)

More information here

更多信息在这里