Gradle - 如何设置它以显示错误是哪个文件?
Gradle - How to set it up so it displays which file the error is?
通常 gradle 不会显示 class 某个错误所在。
例如,我有一个 class A.java
,它使用我的另一个 class Utils.java
。因此,A.java 具有以下含义:
import my.package.Utils;
如果我转到 class 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
问题是消息没有说明问题出在 class A 中。所以我找到答案的唯一方法是手动打开所有使用我的 Utils classes class 直到我找到缺少导入的那个(在本例中为 A)。
有没有办法让 gradle 准确地说出哪个 class 错误?我不敢相信它会抛出这样的一般性错误而不指出它们的位置(尤其是在这些基本情况下,例如缺少导入)。
如果您使用的是 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
获得等效输出。
通常 gradle 不会显示 class 某个错误所在。
例如,我有一个 class A.java
,它使用我的另一个 class Utils.java
。因此,A.java 具有以下含义:
import my.package.Utils;
如果我转到 class 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
问题是消息没有说明问题出在 class A 中。所以我找到答案的唯一方法是手动打开所有使用我的 Utils classes class 直到我找到缺少导入的那个(在本例中为 A)。
有没有办法让 gradle 准确地说出哪个 class 错误?我不敢相信它会抛出这样的一般性错误而不指出它们的位置(尤其是在这些基本情况下,例如缺少导入)。
如果您使用的是 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
获得等效输出。