简体   繁体   English

忽略Android中的所有皮棉错误和警告

[英]Ignoring all lint errors and warnings in Android

Is it Ok to ignore lint errors and warnings given by lint if my projects runs perfectly with no errors in my emulator? 如果我的项目在模拟器中没有错误地完美运行,可以忽略lint给出的lint错误和警告吗? I'm asking this because I would like tu publish my app to the store (my first android app) and I'm not sure if this will cause any shut downs or any other errors... 我问这个问题是因为我想把我的应用发布到商店(我的第一个android应用),我不确定这是否会导致关闭或任何其他错误...

You can but you definitely should not. 您可以,但绝对不能。 Those warnings are here to help you avoid common mistakes which lead to poor code quality. 这些警告可帮助您避免导致错误代码质量的常见错误。 Especially as a beginner, the lint warnings are good to follow. 特别是作为初学者,应该遵循皮棉警告。

Some warning can't be avoided sometimes, but at least you should check them and put a specific annotation on it. 有时无法避免某些警告,但是至少您应该检查它们并在上面加上特定的注释。

Most importantly, understand the warning and be aware of the consequences of not taking care of it. 最重要的是,了解警告并意识到不注意警告的后果。

If you understand the warning well enough and sure that it will not going to effect the apps behavior in other devices, you can go for it. 如果您对警告有足够的了解,并确保它不会影响其他设备上的应用程序行为,则可以这样做。

But, If you are not sure then certainly you should fix all the lint warnings. 但是,如果不确定,则应该修复所有棉绒警告。 Lint error/warnings are very basic for android apps. Lint错误/警告对于Android应用程序来说是非常基本的。

There are various levels of Lint errors, as long as they are showing as warnings - the yellow mark - and not errors - the red ones - you are good. Lint错误有多种级别,只要它们显示为警告-黄色标记-而不是错误-红色标记-很好。

The linter basically just helps you avoid common mistakes - forgetting .show() , or not specifying a default orientation for a LinearLayout . 短绒基本上可以帮助您避免常见的错误-忘记了.show()或不为LinearLayout指定默认方向。

If the app works, it works. 如果该应用程序正常运行,则可以正常运行。 Go for it. 去吧。

@AnkitSomani's answer says the important things: think about warnings first. @AnkitSomani的回答说了重要的事情:首先考虑警告。

If you want to ignore them, lint can be told to ignore warnings by several methods (document is way longer) 如果要忽略它们,可以通过几种方法告诉皮棉忽略警告(文档更长)

  • With annotations: 带有注释:

     @SuppressLint("NewApi") public void onGlobalLayout() { 
  • In .xml files: 在.xml文件中:

     <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> .... <LinearLayout tools:ignore="MergeRootFrame" 
  • java comments: Java注释:

     //noinspection AndroidLintSdCardPath 
  • xml comments: xml注释:

     <!--suppress AndroidLintHardcodedText --> 
  • In Build File: With Gradle Configuration 在构建文件中:使用Gradle配置

     android { lintOptions { disable 'TypographyFractions','TypographyQuotes' ... } } 
  • on the command line 在命令行上

     $ lint --disable MissingTranslation,UnusedIds,Usability:Icons /src/astrid/ 
  • config file 'lint.xml' (next to 'AndroidManifest.xml') 配置文件“ lint.xml”(“ AndroidManifest.xml”之后)

     <?xml version="1.0" encoding="UTF-8"?> <lint> <!-- Ignore the ObsoleteLayoutParam issue in the given files --> <issue id="ObsoleteLayoutParam"> <ignore path="res/layout/activation.xml" /> <ignore path="res/layout-xlarge/activation.xml" /> </issue> </lint> 
  • Android Studio Android Studio

    To suppress an error, open the issue in the editor and run the quickfix/intentions action (Ctrl/Cmd F1) and select Suppress which will use annotations, attributes or comments to disable the issue. 要抑制错误,请在编辑器中打开问题,然后运行quickfix / intentions操作(Ctrl / Cmd F1),然后选择“抑制”,该操作将使用注释,属性或注释来禁用问题。

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

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