在“构建”中检测到哪些错误在Android Studio中 - Gradle的角色 [英] What errors get detected in "build" in Android Studio - role of Gradle

查看:1000
本文介绍了在“构建”中检测到哪些错误在Android Studio中 - Gradle的角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Eclipse转换到Android Studio,我发现我仍然对Android Studio的不同组件感到困惑,因为它们检测到错误。我有一个包含大约20个Java文件和30个XML文件的项目。我最近运行了一个clean和build,并且得到了


Gradle构建在13s中完成了5个错误(397 ms)


显示了两个XML文件,并且在它们的第一个元素前面都有空格,并且有错误说...


Xml声明应该放在所有文档内容之前


然后,我运行Lint,发现 8个以上的错误XML文件(注意,错误,不是警告)说元素选择器没有必需的属性:layout_height。这个错误显然是由于这些文件位于布局文件夹中,而不是可绘制的文件夹,尽管为什么在Eclipse中不会导致问题尚不清楚。



我的问题


  1. 为什么Gradle Build只检测一些错误, $ b是通过lint找到的?

  2. 通过Gradle Build可以找到哪些类型的错误?

  3. Gradle构建脚本以查找$ b $ em全部错误

编辑:实际上,对于常规的Java文件也是如此 - 我会在Gradle构建中获得0错误,然后在调试器中进入源文件并查看来自Lint的4个错误。

$ b $为什么Gradle Build只检测一些错误,但其他的必须是通过lint发现的

>

Lint错误不是编译错误,但代码是起诉,并默认AndroidStudio不会检查这些。 (标准的javac也是如此)。


通过Gradle Build可以找到哪些类型的错误?


Gradle将检测所有编译时错误,注释处理,打包错误,dex,签名,不正确定义的xml,不正确的文件命名等。


向Gradle Build脚本添加某些内容以查找所有错误有多难?

令人惊讶的是,事实上,



在应用程序级别编译添加时启用lint检查build.gradle

  android {
lintOptions {
//设置为true以关闭lint的分析进度报告
quiet false
//如果为true,则在发现错误时停止gradle构建
abortOnError true
//如果为true,则仅报告错误
ignoreWarnings false
}
...
}

如果这将不适用于U,每次制作后添加皮棉,要做到这一点,你可以按照这个答案



我会补充说这个配置会检测所有已启用的检查,并在严重性警告和错误下:

 文件>其他设置>默认设置>编辑器>检查

Android Studio将实时运行代码检查检查,以便在编辑时显示代码中的所有lint warnigns / errors ,lint错误用红色下划线标记,并通过用黄色背景标记代码片段来警告。即使lint错误与编译时错误标记相同,它们也不会停止默认生成。


I'm transitioning over from Eclipse to Android Studio and I find that I'm still confused about the different components of Android Studio regarding detecting errors. I have a project with about 20 Java files and 30 XML files. I recently ran a clean and build and got

Gradle build finished with 5 error(s) in 13s 397 ms

Two XML files were indicated and in both of them there was whitespace in front of the first element with an error saying ...

Xml declaration should precede all document content

So I fixed those and ran the build again with no errors.

I then ran Lint and found 8 more XML files with errors (NB, errors, not warning) saying "Element selector doesn't have required attribute:layout_height ". This error was apparently due to these files being in a layout folder instead of a drawable folder, although why that didn't cause problems in Eclipse is unclear.

My Questions:

  1. Why does Gradle Build only detect some errors, but other have to be found via lint?
  2. What categories of errors will be found via Gradle Build?
  3. How hard is it to add something to the Gradle Build script to find all errors?

Edit: actually this is also true for regular Java files - I'll get "0 errors" in the Gradle build and then I'll step into a source file in the debugger and see 4 errors from Lint.

解决方案

Why does Gradle Build only detect some errors, but other have to be found via lint?

Lint errors are not compile errors, but code issues, and by default AndroidStudio will not check those. (Same goes for standard javac).

What categories of errors will be found via Gradle Build?

Gradle will detect all compile time errors, annotation processing, packaging errors, dex, signing, incorectly defined xml, incorrect file naming, etc.

How hard is it to add something to the Gradle Build script to find all errors?

Surprisingly easy in fact, source

To enable lint checks when compiling add in your application level build.gradle

android {
   lintOptions {
       // set to true to turn off analysis progress reporting by lint
       quiet false
       // if true, stop the gradle build if errors are found
       abortOnError true
       // if true, only report errors
       ignoreWarnings false
       }
   ...
}

If this will not work for U, add lint after each make, to do this you can follow this answer

I will add that this config will detect all enabled inspections with severity warning and error under:

File > Other Settings > Default Settings > Editor > Inspections 

Android Studio will run code inspections checks live so all lint warnigns / errors are displayed in code while editing, lint errors are marked with red underscore, and warnings by marking code fragment with yellow background. Even if lint errors are marked the same as compile time errors they will not stop build by default.

这篇关于在“构建”中检测到哪些错误在Android Studio中 - Gradle的角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆