Android lint具 常见问题检查

 1. Correctness  
1) DuplicatedIds  
Layout于id应该唯一  
2) NewApi  
代码中使用的某些API高于Manifest中的Min SDK  
3) InconsistentArrays  
字符串国际化中。同一名字的的String-Array相应的item值不同样  
4) Registered  
Activity/Service/ContentProvider没有通过AndroidManifest注冊  
5) Deprecated  
使用已经废弃的API  
6) PxUsage  
避免使用px。使用dp  
   
2. Correctness:Messeges  
1) MissingTranslation  
字符串国际化不全然  
2) ExtraTranslation  
国际化的字符串,在默认位置(defaultlocale),未定义  
   
3. Security  
1) SetJavaScriptEnabled  
不确定你的程序中确实须要JavaScript就不要运行SetJavaScriptEnabled。

2)ExportedContentProvider/ExportedReceiver/ExportedService/ExportedActivity ContentProvider/Receiver/Service/Activity的exported为true时。设置一个Permission。让使用者获取了Permission才干使用。

3) HardcodedDebugMode 不要在manifest中设置android:debuggable。 设置它,编译的不论什么版本号都要採用指定的debug模式。不设置,编译Eng版本号採用debug模式;编译User版本号採用release模式。 4. Performance 1) DrawAllocation 避免在绘制或者解析布局(draw/layout)时分配对象。

E.g.,Ondraw()中实例化Paint对象。 2) ObsoleteLayoutParam Layout中没用的參数。 3) UseCompoundDrawables 可优化的布局:如包括一个Imageview和一个TextView的线性布局,可被採用CompoundDrawable的TextView取代。 4) UseSparseArrays 尽量用Android的SparseArray取代Hashmap 5) DisableBaselineAlignment 假设LinearLayout被用于嵌套的layout空间计算,它的android:baselineAligned属性应该设置成false,以加速layout计算。

6) FloatMath 使用FloatMath取代Math。 7) NestedWeights 避免嵌套weight。那将拖累运行效率 8) UnusedResources/UnusedIds 未被使用的资源会是程序变大,而且编译速度减少。 9) Overdraw 假设为RootView指定一个背景Drawable,会先用Theme的背景绘制一遍,然后才用指定的背景,这就是所谓的“Overdraw”。 能够设置theme的background为null来避免。 10) UselessLeaf/UselessParent View或view的父亲没实用 5. Usability:Typography 1) TypographyDashes 特殊字符需用编码取代:“–”须要用“–”;“—”须要用“—” 2) TypographyEllipsis 特殊字符需用编码取代:“…”须要用“…” 3) TypographyOther 问题:“(c)”须要用“©” 6. Usability:Icons 1) IconNoDpi Icon在nodpi和指定dpi的文件夹下都出现。 2) GifUsage Image不要用GIF,最好用PNG,能够用JPG。 7. Usability 1) BackButton Android中不要设计有Back的button,Android中一般有Back的硬按键。 2) ButtonCase Button的“Ok”/“Cancel”显示大写和小写一定,不要全大写或全小写。

有标准的资源的字符串,不要自己再定义,而要用系统定义的:@android:string/ok和@android:string/cancel 8. Accessibility 1) ContentDescription ImageView和ImageButton应该提供contentDescription 9. Internationalization 1) HardcodeText 硬编码的字符串应该在资源里定义 2) EnforceUTF8 整个XML资源文件应UTF-8编码



版权声明:本文博主原创文章。博客,未经同意不得转载。

原文地址:https://www.cnblogs.com/lcchuguo/p/4868874.html