通常,gradle不会在哪个类中显示某个错误。
例如,我有一个班级A.java
,它使用我的其他班级Utils.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确切地说出哪个类错误?我不敢相信它会抛出这样的一般性错误而不指出它们的位置(特别是在缺少导入这些基本情况下)。
答案 0 :(得分:0)
如果您使用的是Android Studio,请使用Build>重建项目,而不是构建>清洁项目。
使用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
获得相同的输出。