繁体   English   中英

Gradle-如何设置它以显示错误所在的文件?

[英]Gradle - How to set it up so it displays which file the error is?

gradle通常不显示某个错误在哪个类中。

例如,我有一个使用其他类Utils.java A.java类。 因此,A.java具有以下导入:

import my.package.Utils;

如果我去A类,删除上面的导入并清理项目,gradle给我以下消息:

Information:25/08/15 9:18 AM - Compilation completed with 1 error and 0 warnings in 22s 800ms
Error:Gradle: Execution failed for task ':app:compileBauDebugAspectj'.
> Utils cannot be resolved

问题是,该消息无法在A类的任何地方说出问题。因此,我发现此问题的唯一方法是手动打开所有使用我的Utils类的类,直到找到缺少导入的类(在这种情况,A)。

有没有办法让gradle准确地说出错误是哪一类? 我不敢相信它会抛出这样的一般错误而没有指出它们的位置(尤其是在缺少导入等基本情况下)。

如果您使用的是Android Studio,请使用“构建”>“重建项目”,而不是“构建”>“清理项目”。

使用Rebuild Project或命令行Gradle构建,将很高兴地指出错误的具体位置。 例如,以下是Android Studio 1.3.1中Gradle控制台缺少的导入的输出:

Executing tasks: [clean, :app:compileDebugSources, :app:compileDebugAndroidTestSources]

Configuration on demand is an incubating feature.
:app:clean
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportSupportV132300Library
:app:prepareComAndroidSupportSupportV42300Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJavaWithJavac
/home/mmurphy/stuff/CommonsWare/projects/andprojector/app/src/main/java/com/commonsware/andprojector/MainActivity.java:40: error: cannot find symbol
    EventBus.getDefault().registerSticky(this);
    ^
  symbol:   variable EventBus
  location: class MainActivity
/home/mmurphy/stuff/CommonsWare/projects/andprojector/app/src/main/java/com/commonsware/andprojector/MainActivity.java:45: error: cannot find symbol
    EventBus.getDefault().unregister(this);
    ^
  symbol:   variable EventBus
  location: class MainActivity
Note: /home/mmurphy/stuff/CommonsWare/projects/andprojector/app/src/main/java/com/commonsware/andprojector/MainActivity.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

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

BUILD FAILED

Total time: 1.971 secs

您可以从命令行运行gradle assembleDebug获得等效的输出。

暂无
暂无

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

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