2012-10-02
这里的Android-Lint所检查的问题列表是从AndroidSDK Tools r20.0.3 (ADT v20.0.3)中得来的默认的,执行下列指令即可得到:
$lint --show
$lint --list
--show可获得详细列表(id,summary, priority, severity, category and details);--list仅可获得Issue的id和summary的简表
Android-Lint相关的文章:
Android-Lint的简述:Lint检查哪些问题;如何使用;有哪些选项;与其他系统集成。
对Android-Lint发现的问题进行处理。可定制项目中采用的规则。
Android SDK Tools / ADT 20.0.3中所支持的默认检查的所有问题。
当然,最关键最权威的还是应该看官方网站:http://tools.android.com/tips/lint
===========
-------------------
Summary: Checksthat AdapterViews do not define their children in XML
Priority: 10 / 10
Severity: Warning
Category:Correctness
AdapterViews such as ListViews must be configured with datafrom Java code, such as a ListAdapter.
More information:http://developer.android.com/reference/android/widget/AdapterView.html
-------
Summary: Ensuresthat onClick attribute values refer to real methods
Priority: 10 / 10
Severity: Error
Category:Correctness
The onClick attribute value should be the name of a methodin this View's context to invoke when the view is clicked. This name mustcorrespond to a public method that takes exactly one parameter of type View.
Must be a string value, using '\;' to escape characters suchas '\n' or '\uxxxx' for a unicode character.
----------------
Summary: Checksfor 'import android.R' statements, which are usually accidental
Priority: 9 / 10
Severity: Warning
Category:Correctness
Importing android.R is usually not intentional; it sometimeshappens when you use an IDE and ask it to automatically add imports at a timewhen your project's R class it not present.
Once the import is there you might get a lot of"confusing" error messages because of course the fields available onandroid.R are not the ones you'd expect from just looking at your own R class.
-------------
Summary: Looksfor incorrect casts to views that according to the XML are of a different type
Priority: 9 / 10
Severity: Error
Category:Correctness
Keeps track of the view types associated with ids and if itfinds a usage of the id in the Java code it ensures that it is treated as thesame type.
-------------
Summary: DetectXML attributes not using the Android namespace
Priority: 8 / 10
Severity: Warning
Category:Correctness
Most Android views have attributes in the Android namespace.When referencing these attributes you *must* include the namespace prefix, oryour attribute will be interpreted by aapt as just a custom attribute.
-------------
Summary: Looksfor misspellings in namespace declarations
Priority: 8 / 10
Severity: Warning
Category: Correctness
Accidental misspellings in namespace declarations can leadto some very obscure error messages. This check looks for potentialmisspellings to help track these down.
--------
Summary: Looksfor problems in proguard config files
Priority: 8 / 10
Severity: Fatal
Category:Correctness
Using -keepclasseswithmembernames in a proguard config fileis not correct; it can cause some symbols to be renamed which should not be.
Earlier versions of ADT used to create proguard.cfg fileswith the wrong format. Instead of -keepclasseswithmembernames use-keepclasseswithmembers, since the old flags also implies "allowshrinking" which means symbols only referred to from XML and not Java(such as possibly CustomViews) can get deleted.
More information: http://http://code.google.com/p/android/issues/detail?id=16384
---------------
Summary: Checksthat ScrollViews have exactly one child widget
Priority: 8 / 10
Severity: Warning
Category:Correctness
ScrollViews can only have one child widget. If you want morechildren, wrap them in a container layout.
----------
Summary: Looksfor cycles in style definitions
Priority: 8 / 10
Severity: Fatal
Category:Correctness
There should be no cycles in style definitions as this canlead to runtime exceptions.
More information:http://developer.android.com/guide/topics/ui/themes.html#Inheritance
---------
Summary: Checksfor id references in RelativeLayouts that are not defined elsewhere
Priority: 8 / 10
Severity: Fatal
Category:Correctness
The "@+id/" syntax refers to an existing id, orcreates a new one if it has not already been defined elsewhere. However, thismeans that if you have a typo in your reference, or if the referred view nolonger exists, you do not get a warning since the id will be created on demand.This check catches errors where you have renamed an id without updating all ofthe references to it.
------------
一个Layout内部的id应该是唯一的。
Summary: Checksfor duplicate ids within a single layout
Priority: 7 / 10
Severity: Warning
Category:Correctness
Within a layout, id's should be unique since otherwisefindViewById() can return an unexpected view.
------------------
字符串国际化中,同一名字的的String-Array对应的item值不相同
Summary: Checksfor inconsistencies in the number of elements in arrays
Priority: 7 / 10
Severity: Warning
Category:Correctness
When an array is translated in a different locale, it shouldnormally have the same number of elements as the original array. When adding orremoving elements to an array, it is easy to forget to update all the locales,and this lint warning finds inconsistencies like these.
Note however that there may be cases where you really wantto declare a different number of array items in each configuration (for examplewhere the array represents available options, and those options differ fordifferent layout orientations and so on), so use your own judgement to decideif this is really an error.
You can suppress this error type if it finds false errors inyour project.
---------------
Summary: Checkswhether a scrolling widget has any nested scrolling widgets within
Priority: 7 / 10
Severity: Warning
Category:Correctness
A scrolling widget such as a ScrollView should not containany nested scrolling widgets since this has various usability issues
---------------
Summary: Looksfor calls to setColor where a resource id is passed instead of a resolved color
Priority: 7 / 10
Severity: Error
Category: Correctness
Methods that take a color in the form of an integer shouldbe passed an RGB triple, not the actual color resource id. You must call getResources().getColor(resource)to resolve the actual color value first.
--------------
Summary: Checksthat ScrollViews use wrap_content in scrolling dimension
Priority: 7 / 10
Severity: Warning
Category:Correctness
ScrollView children must set their layout_width orlayout_height attributes to wrap_content rather than fill_parent or match_parentin the scrolling dimension
-------------
Summary: Looksfor TextViews being used for input
Priority: 7 / 10
Severity: Warning
Category:Correctness
Using a <TextView> to input text is generally anerror, you should be using <EditText> instead. EditText is a subclass of TextView, and someof the editing support is provided by TextView, so it's possible to set some input-relatedproperties on a TextView. However, using a TextView along with input attributesis usually a cut & paste error. To input text you should be using<EditText>.
This check also checks subclasses of TextView, such asButton and CheckBox, since these have the same issue: they should not be usedwith editable attributes.
---------------
Summary: Looksfor code editing a SharedPreference but forgetting to call commit() on it
Priority: 6 / 10
Severity: Warning
Category:Correctness
After calling edit() on a SharedPreference, you must callcommit() or apply() on the editor to save the results.
--------------------
Summary: Checksfor duplicate ids across layouts that are combined with include tags
Priority: 6 / 10
Severity: Warning
Category:Correctness
It's okay for two independent layouts to use the same ids.However, if layouts are combined with include tags, then the id's need to beunique within any chain of included layouts, or Activity#findViewById() canreturn an unexpected view.
-----------------
Summary: Flagscustom attributes in libraries, which must use the res-auto-namespace instead
Priority: 6 / 10
Severity: Error
Category:Correctness
When using a custom view with custom attributes in a libraryproject, the layout must use the special namespacehttp://schemas.android.com/apk/res-auto instead of a URI which includes thelibrary project's own package. This will be used to automatically adjust thenamespace of the attributes when the library resources are merged into theapplication project.
---------------
Summary: Checksthat the <uses-sdk> element appears at most once
Priority: 6 / 10
Severity: Fatal
Category:Correctness
The <uses-sdk> element should appear just once; thetools will *not* merge the contents of all the elements so if you split up theatttributes across multiple elements, only one of them will take effect. To fixthis, just merge all the attributes from the various elements into a single<uses-sdk> element.
More information:http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
------
代码中使用的某些API高于Manifest中的MinSDK
Summary: FindsAPI accesses to APIs that are not supported in all targeted API versions
Priority: 6 / 10
Severity: Error
Category:Correctness
This check scans through all the Android API calls in the applicationand warns about any calls that are not available on *all* versions targeted by thisapplication (according to its minimum SDK attribute in the manifest).
If your code is *deliberately* accessing newer APIs, and youhave ensured (e.g. with conditional execution) that this code will only ever becalled on a supported platform, then you can annotate your class or method withthe @TargetApi annotation specifying the local minimum SDK to apply, such as@TargetApi(11),such that this check considers 11 rather than your manifest file's minimum SDKas the required API level.
----------
Activity/Service/ContentProvider没有通过AndroidManifest注册
Summary: Ensuresthat Activities, Services and Content Providers are registered in the manifest
Priority: 6 / 10
Severity: Warning
Category:Correctness
Activities, services and content providers should beregistered in the AndroidManifext.xml file using <activity>,<service> and <provider> tags.
If your activity is simply a parent class intended to be subclassedby other "real" activities, make it an abstract class.
More information:http://developer.android.com/guide/topics/manifest/manifest-intro.html
----------
Summary: Looksfor hardcoded references to /sdcard
Priority: 6 / 10
Severity: Warning
Category:Correctness
Your code should not reference the /sdcard path directly;instead use Environment.getExternalStorageDirectory().getPath()
More information:http://developer.android.com/guide/topics/data/data-storage.html#filesExternal
---------
Summary: Looksfor code creating a Toast but forgetting to call show() on it
Priority: 6 / 10
Severity: Warning
Category:Correctness
Toast.makeText() creates a Toast but does *not* show it. Youmust call show() on the resulting object to actually make the Toast appear.
-------------
Summary: Ensuresthat Fragment subclasses can be instantiated
Priority: 6 / 10
Severity: Warning
Category:Correctness
From the Fragment documentation: *Every* fragment must havean empty constructor, so it can be instantiated when restoring its activity'sstate. It is strongly recommended that subclasses do not have otherconstructors with parameters, since these constructors will not be called whenthe fragment is re-instantiated; instead, arguments can be supplied by thecaller with setArguments(Bundle) and later retrieved by the Fragment withgetArguments().
More information:http://developer.android.com/reference/android/app/Fragment.html#Fragment()
-------------------
Summary: Checksthat various manifest elements are declared in the right place
Priority: 6 / 10
Severity: Fatal
Category:Correctness
The <uses-library> element should be defined as adirect child of the <application> tag, not the <manifest> tag or an<activity> tag. Similarly, a <uses-sdk> tag much be declared at theroot level, and so on. This check looks for incorrect declaration locations inthe manifest, and complains if an element is found in the wrong place.
More information:http://developer.android.com/guide/topics/manifest/manifest-intro.html
-----------------
Summary: Checksthat an activity is registered only once in the manifest
Priority: 5 / 10
Severity: Error
Category:Correctness
An activity should only be registered once in the manifest.If it is accidentally registered more than once, then subtle errors can occur,since attribute declarations from the two elements are not merged, so you may accidentallyremove previous declarations.
-------------
Summary: Checksfor manifest problems like <uses-sdk> after the <application> tag
Priority: 5 / 10
Severity: Warning
Category:Correctness
The <application> tag should appear after the elementswhich declare which version you need, which features you need, which librariesyou need, and so on. In the past there have been subtle bugs (such as themesnot getting applied correctly) when the <application> tag appears beforesome of these other elements, so it's best to order your manifest in thelogical dependency order.
------------------
Summary: Looksfor unreachable states in a <selector>
Priority: 5 / 10
Severity: Warning
Category:Correctness
In a selector, only the last child in the state list shouldomit a state qualifier. If not, all subsequent items in the list will beignored since the given item will match all.
-----------------
Summary: Makessure that @+id references refer to views in the same layout
Priority: 5 / 10
Severity: Warning
Category:Correctness
The "@+id/" syntax refers to an existing id, orcreates a new one if it has not already been defined elsewhere. However, thismeans that if you have a typo in your reference, or if the referred view nolonger exists, you do not get a warning since the id will be created on demand.
This is sometimes intentional, for example where you arereferring to a view which is provided in a different layout via an include.However, it is usually an accident where you have a typo or you have renamed aview without updating all the references to it.
--------------
Summary: Looksfor code sending text messages to unlocalized phone numbers
Priority: 5 / 10
Severity: Warning
Category:Correctness
SMS destination numbers must start with a country code orthe application code must ensure that the SMS is only sent when the user is inthe same country as the receiver.
----------
Summary: Checksfor potential GridLayout errors like declaring rows and columns outside thedeclared grid dimensions
Priority: 4 / 10
Severity: Fatal
Category:Correctness
Declaring a layout_row or layout_column that falls outsidethe declared size of a GridLayout's rowCount or columnCount is usually anunintentional error.
---------
Summary: Looksfor extraneous text in layout files
Priority: 3 / 10
Severity: Warning
Category:Correctness
Layout resource files should only contain elements andattributes. Any XML text content found in the file is likely accidental (andpotentially dangerous if the text resembles XML and the developer believes thetext to be functional)
---------------
Summary: Looksfor references to private resources
Priority: 3 / 10
Severity: Fatal
Category: Correctness
Private resources should not be referenced; the may not bepresent everywhere, and even where they are they may disappear without notice.
To fix this, copy the resource into your own project. Youcan find the platform resources under $ANDROID_SK/platforms/android-$VERSION/data/res/.
-------------
Summary: Checksfor old proguard.cfg files that contain generic Android rules
Priority: 3 / 10
Severity: Warning
Category:Correctness
Earlier versions of the Android tools bundled a single"proguard.cfg" file containing a ProGuard configuration file suitablefor Android shrinking and obfuscation. However, that version was copied intonew projects, which means that it does not continue to get updated as weimprove the default ProGuard rules for Android.
In the new version of the tools, we have split the ProGuardconfiguration into two halves:
* A simple configuration file containing onlyproject-specific flags, in your project
* A generic configuration file containing the recommendedset of ProGuard options for Android projects. This generic file lives in theSDK install directory which means that it gets updated along with the tools.
In order for this to work, the proguard.config property inthe project.properties file now refers to a path, so you can reference both thegeneric file as well as your own (and any additional files too).
To migrate your project to the new setup, create a newproguard-project.txt file in your project containing any project specificProGuard flags as well as any customizations you have made, then update yourproject.properties file to contain:
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-projec.txt
----------
使用已经废弃的API
Summary: Looksfor usages of deprecated layouts, attributes, and so on.
Priority: 2 / 10
Severity: Warning
Category:Correctness
Deprecated views, attributes and so on are deprecatedbecause there is a better way to do something. Do it that new way. You've beenwarned.
-------
避免使用px,使用dp代替
Summary: Looksfor use of the "px" dimension
Priority: 2 / 10
Severity: Warning
Category:Correctness
For performance reasons and to keep the code simpler, theAndroid system uses pixels as the standard unit for expressing dimension orcoordinate values.
That means that the dimensions of a view are alwaysexpressed in the code using pixels, but always based on the current screendensity. For instance, if myView.getWidth() returns 10, the view is 10 pixelswide on the current screen, but on a device with a higher density screen, thevalue returned might be 15. If you use pixel values in your application code towork with bitmaps that are not pre-scaled for the current screen density, youmight need to scale the pixel values that you use in your code to match theun-scaled bitmap source.
More information:http://developer.android.com/guide/practices/screens_support.html#screen-independence
--------------------
Summary: Checksthat the minimum SDK and target SDK attributes are defined
Priority: 2 / 10
Severity: Warning
Category:Correctness
The manifest should contain a <uses-sdk> element whichdefines the minimum minimum API Level required for the application to run, aswell as the target version (the highest API level you have tested the versionfor.)
More information:http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
---------------
Summary: Findsunused namespaces in XML documents
Priority: 1 / 10
Severity: Warning
Category:Correctness
Unused namespace declarations take up space and requireprocessing that is not necessary
====================
-------------------
Summary: Checksthat format strings are valid
Priority: 9 / 10
Severity: Error
Category:Correctness:Messages
If a string contains a '%' character, then the string may bea formatting string which will be passed to String.format from Java code toreplace each '%' occurrence with specific values.
This lint warning checks for two related problems:
(1) Formatting strings that are invalid, meaning thatString.format will throw exceptions at runtime when attempting to use theformat string.
(2) Strings containing '%' that are not formatting stringsgetting passed to a String.format call. In this case the '%' will need to beescaped as '%%'.
NOTE: Not all Strings which look like formatting strings areintended for use by String.format; for example, they may contain date formatsintended for android.text.format.Time#format(). Lint cannot always figure outthat a String is a date format, so you may get false warnings in thosescenarios. See the suppress help topic for information on how to suppresserrors in that case.
-------------------
Summary: Ensuresthat the format used in <string> definitions is compatible with theString.format call
Priority: 9 / 10
Severity: Error
Category:Correctness:Messages
This lint check ensures the following:
(1) If there are multiple translations of the format string,then all translations use the same type for the same numbered arguments
(2) The usage of the format string in Java is consistentwith the format string, meaning that the parameter types passed toString.format matches those in the format string.
------------------
字符串国际化不完全
Summary: Checksfor incomplete translations where not all strings are translated
Priority: 8 / 10
Severity: Fatal
Category:Correctness:Messages
If an application has more than one locale, then all thestrings declared in one language should also be translated in all otherlanguages.
By default this detector allows regions of a language tojust provide a subset of the strings and fall back to the standard languagestrings. You can require all regions to provide a full translation by settingthe environment variable ANDROID_LINT_COMPLETE_REGIONS.
----------------
国际化的字符串,在默认位置(defaultlocale)中没有定义
Summary: Checksfor translations that appear to be unused (no default language string)
Priority: 6 / 10
Severity: Warning
Category:Correctness:Messages
If a string appears in a specific language translation file,but there is no corresponding string in the default locale, then this string isprobably unused. (It's technically possible that your application is only intendedto run in a specific locale, but it's still a good idea to provide a fallback.)
-----------------
Summary: Ensuresthat all format strings are used and that the same number is defined acrosstranslations
Priority: 5 / 10
Severity: Warning
Category:Correctness:Messages
When a formatted string takes arguments, it usually needs toreference the same arguments in all translations. There are cases where this isnot the case, so this issue is a warning rather than an error by default.However, this usually happens when a language is not translated or updatedcorrectly.
========
------------
Summary: Checksfor <grant-uri-permission> elements where everything is shared
Priority: 7 / 10
Severity: Warning
Category:Security
The <grant-uri-permission> element allows specificpaths to be shared. This detector checks for a path URL of just '/'(everything), which is probably not what you want; you should limit access to asubset.
--------------------
不确定你的程序中确实需要JavaScript就不要执行SetJavaScriptEnabled。
Summary: Looksfor invocations of android.webkit.WebSettings.setJavaScriptEnabled
Priority: 6 / 10
Severity: Warning
Category:Security
Your code should not invoke setJavaScriptEnabled if you arenot sure that your app really requires JavaScript support.
More information:http://developer.android.com/guide/practices/security.html
-----------------------
ContentProvider exported为true时,设置一个Permission,让使用者获取了Permission才能使用。
Summary: Checksfor exported content providers that do not require permissions
Priority: 5 / 10
Severity: Warning
Category:Security
Content providers are exported by default and anyapplication on the system can potentially use them to read and write data. Ifthe contentprovider provides access to sensitive data, it should be protectedby specifying export=false in the manifest or by protecting it with apermission that can be granted to other applications.
----------------
Receiver的exported为true时,设置一个Permission,让使用者获取了Permission才能使用。
Summary: Checksfor exported receivers that do not require permissions
Priority: 5 / 10
Severity: Warning
Category:Security
Exported receivers (receivers which either set exported=trueor contain an intent-filter and do not specify exported=false) should define apermission that an entity must have in order to launch the receiver or bind toit. Without this, any application can use this receiver.
---------------
Service的exported为true时,设置一个Permission,让使用者获取了Permission才能使用。
Summary: Checksfor exported services that do not require permissions
Priority: 5 / 10
Severity: Warning
Category:Security
Exported services (services which either set exported=trueor contain an intent-filter and do not specify exported=false) should define apermission that an entity must have in order to launch the service or bind toit. Without this, any application can use this service.
------------------
不要在manifest中设置android:debuggable。
设置它,编译的任何版本都要采用指定的debug模式。不设置,编译Eng版本采用debug模式;编译User版本采用release模式。
Summary: Checksfor hardcoded values of android:debuggable in the manifest
Priority: 5 / 10
Severity: Warning
Category:Security
It's best to leave out the android:debuggable attribute fromthe manifest. If you do, then the tools will automatically insertandroid:debuggable=true when building an APK to debug on an emulator or device.And when you perform a release build, such as Exporting APK, it willautomatically set it to false.
If on the other hand you specify a specific value in themanifest file, then the tools will always use it. This can lead to accidentallypublishing your app with debug information.
------------------
Summary: Checksfor openFileOutput() and getSharedPreferences() calls passing MODE_WORLD_READABLE
Priority: 4 / 10
Severity: Warning
Category:Security
There are cases where it is appropriate for an applicationto write world readable files, but these should be reviewed carefully to ensurethat they contain no private data that is leaked to other applications.
-------------------
Summary: Checksfor openFileOutput() and getSharedPreferences() calls passing MODE_WORLD_WRITEABLE
Priority: 4 / 10
Severity: Warning
Category:Security
There are cases where it is appropriate for an applicationto write world writeable files, but these should be reviewed carefully toensure that they contain no private data, and that if the file is modified by amalicious application it does not trick or compromise your application.
----------------
Activity的exported为true时,设置一个Permission,让使用者获取了Permission才能使用。
Summary: Checksfor exported activities that do not require permissions
Priority: 2 / 10
Severity: Warning
Category:Security
Exported activities (activities which either setexported=true or contain an intent-filter and do not specify exported=false)should define a permission that an entity must have in order to launch theactivity or bind to it. Without this, any application can use this activity.
===========
--------------
避免在绘制或者解析布局(draw/layout)时分配对象。E.g.,Ondraw()中实例化Paint对象。
Summary: Looksfor memory allocations within drawing code
Priority: 9 / 10
Severity: Warning
Category:Performance
You should avoid allocating objects during a drawing orlayout operation. These are called frequently, so a smooth UI can beinterrupted by garbage collection pauses caused by the object allocations.
The way this is generally handled is to allocate the neededobjects up front and to reuse them for each drawing operation.
Some methods allocate memory on your behalf (such asBitmap.create), and these should be handled in the same way.
-------------------
Layout中有无用的参数。
Summary: Looksfor layout params that are not valid for the given parent layout
Priority: 6 / 10
Severity: Warning
Category:Performance
The given layout_param is not defined for the given layout,meaning it has no effect. This usually happens when you change the parentlayout or move view code around without updating the layout params. This willcause useless attribute processing at runtime, and is misleading for othersreading the layout so the parameter should be removed.
--------------------
可优化的布局:如包含一个Imageview和一个TextView的线性布局,可被采用CompoundDrawable的TextView代替。
Summary: Checkswhether the current node can be replaced by a TextView using compounddrawables.
Priority: 6 / 10
Severity: Warning
Category: Performance
A LinearLayout which contains an ImageView and a TextViewcan be more efficiently handled as a compound drawable.
There's a lint quickfix to perform this conversion in theEclipse plugin.
-----------
直接访问类里的内部域,不要用getter方法。这样会快3倍。
Summary: Suggestsreplacing uses of getters with direct field access within a class
Priority: 4 / 10
Severity: Warning
Category:Performance
NOTE: This issue is disabled by default! You can enable itby adding --enable FieldGetter
Accessing a field within the class that defines a getter forthat field is at least 3 times faster than calling the getter. For simplegetters that do nothing other than return the field, you might want to justreference the local field directly instead.
More information: http://developer.android.com/guide/practices/design/performance.html#internal_get_set
-----------
Summary: Ensuresthat Handler classes do not hold on to a reference to an outer class
Priority: 4 / 10
Severity: Warning
Category:Performance
In Android, Handler classes should be static or leaks mightoccur. Messages enqueued on the application thread's MessageQueue also retaintheir target Handler. If the Handler is an inner class, its outer class will beretained as well. To avoid leaking the outer class, declare the Handler as astatic nested class with a WeakReference to its outer class.
--------------
Summary: Checkswhether a root <FrameLayout> can be replaced with a <merge> tag
Priority: 4 / 10
Severity: Warning
Category:Performance
If a <FrameLayout> is the root of a layout and doesnot provide background or padding etc, it can often be replaced with a<merge> tag which is slightly more efficient. Note that this depends oncontext, so make sure you understand how the <merge> tag works beforeproceeding.
More information:http://android-developers.blogspot.com/2009/03/android-layout-tricks-3-optimize-by.html
---------------
尽量用Android的SparseArray代替Hashmap
Summary: Looksfor opportunities to replace HashMaps with the more efficient SparseArray
Priority: 4 / 10
Severity: Warning
Category:Performance
For maps where the keys are of type integer, it's typicallymore efficient to use the Android SparseArray API. This check identifiesscenarios where you might want to consider using SparseArray instead of HashMapfor better performance.
This is *particularly* useful when the value types areprimitives like ints, where you can use SparseIntArray and avoid auto-boxingthe values from int to Integer.
If you need to construct a HashMap because you need to callan API outside of your control which requires a Map, you can suppress thiswarning using for example the @SuppressLint annotation.
----------
新建一个对象时候,尽量考虑用带有valueOf()的封装类实现。比如:Integer.valueOf().
Summary: Looksfor usages of "new" for wrapper classes which should use "valueOf"instead
Priority: 4 / 10
Severity: Warning
Category:Performance
You should not call the constructor for wrapper classesdirectly, such as"new Integer(42)". Instead, call the"valueOf" factory method, such as Integer.valueOf(42). This willtypically use less memory because common integers such as 0 and 1 will share asingle instance.
------------------------
如果LinearLayout被用于嵌套的layout空间计算,它的android:baselineAligned属性应该设置成false,以加速layout计算。
Summary: Looksfor LinearLayouts which should set android:baselineAligned=false
Priority: 3 / 10
Severity: Warning
Category:Performance
When a LinearLayout is used to distribute the spaceproportionally between nested layouts, the baseline alignment property shouldbe turned off to make the layout computation faster.
---------
使用FloatMath代替Math。
Summary: Suggestsreplacing java.lang.Math calls with android.util.FloatMath to avoid conversions
Priority: 3 / 10
Severity: Warning
Category:Performance
On modern hardware, "double" is just as fast as"float" though of course it takes more memory. However, if you areusing floats and you need to compute the sine, cosine or square root, then itis better to use the android.util.FloatMath class instead of java.lang.Mathsince you can call methods written to operate on floats, so you avoidconversions back and forth to double.
More information:http://developer.android.com/guide/practices/design/performance.html#avoidfloat
-----------------
Summary: Looksfor inefficient weight declarations in LinearLayouts
Priority: 3 / 10
Severity: Warning
Category:Performance
When only a single widget in a LinearLayout defines aweight, it is more efficient to assign a width/height of 0dp to it since itwill absorb all the remaining space anyway. With a declared width/height of 0dpit does not have to measure its own size first.
-------------
避免嵌套weight,那将拖累执行效率
Summary: Looksfor nested layout weights, which are costly
Priority: 3 / 10
Severity: Warning
Category:Performance
Layout weights require a widget to be measured twice. When aLinearLayout with non-zero weights is nested inside another LinearLayout withnon-zero weights, then the number of measurements increase exponentially.
--------
如果为RootView指定一个背景Drawable,会先用Theme的背景绘制一遍,然后才用指定的背景,这就是所谓的“Overdraw”。
可以设置theme的background为null来避免。
Summary: Looksfor overdraw issues (where a view is painted only to be fully painted over)
Priority: 3 / 10
Severity: Warning
Category:Performance
If you set a background drawable on a root view, then youshould use a custom theme where the theme background is null. Otherwise, thetheme background will be painted first, only to have your custom backgroundcompletely cover it; this is called "overdraw".
NOTE: This detector relies on figuring out which layouts areassociated with which activities based on scanning the Java code, and it'scurrently doing that using an inexact pattern matching algorithm. Therefore, itcan incorrectly conclude which activity the layout is associated with and then wronglycomplain that a background-theme is hidden.
If you want your custom background on multiple pages, thenyou should consider making a custom theme with your custom background and justusing that theme instead of a root element background.
Of course it's possible that your custom drawable istranslucent and you want it to be mixed with the background. However, you willget better performance if you pre-mix the background with your drawable and usethat resulting image or color as a custom theme background instead.
---------------
未被使用的资源会是程序变大,并且编译速度降低。
Summary: Looksfor unused resources
Priority: 3 / 10
Severity: Warning
Category:Performance
Unused resources make applications larger and slow downbuilds.
-----------
检查一个子Layout能否被移除。无子孙无背景
Summary: Checkswhether a leaf layout can be removed.
Priority: 2 / 10
Severity: Warning
Category: Performance
A layout that has no children or no background can often beremoved (since it is invisible) for a flatter and more efficient layouthierarchy.
-------------
检查一个父Layout能否被移除。有子孙而无旁亲的layout,如果不是scrollview,不是根layout,并且无背景。
Summary: Checkswhether a parent layout can be removed.
Priority: 2 / 10
Severity: Warning
Category:Performance
A layout with children that has no siblings, is not ascrollview or a root layout, and does not have a background, can be removed andhave its children moved directly into the parent for a flatter and moreefficient layout hierarchy.
-------------
Summary: Checkswhether a layout hierarchy is too deep
Priority: 1 / 10
Severity: Warning
Category:Performance
Layouts with too much nesting is bad for performance.Consider using a flatter layout (such as RelativeLayout or GridLayout).Thedefault maximum depth is 10 but can be configured with the environment variableANDROID_LINT_MAX_DEPTH.
------------
Summary: Checkswhether a layout has too many views
Priority: 1 / 10
Severity: Warning
Category:Performance
Using too many views in a single layout in a layout is badfor performance.
Consider using compound drawables or other tricks forreducing the number of views in this layout.
The maximum view count defaults to 80 but can be configuredwith the environment variable ANDROID_LINT_MAX_VIEW_COUNT.
---------
未被使用的id,没有足够的理由就删除掉。
Summary: Looksfor unused id's
Priority: 1 / 10
Severity: Warning
Category:Performance
NOTE: This issue is disabled by default! You can enable itby adding --enable UnusedIds
This resource id definition appears not to be needed sinceit is not referenced from anywhere. Having id definitions, even if unused, isnot necessarily a bad idea since they make working on layouts and menus easier,so there is not a strong reason to delete these.
====================
----------------
特殊字符需用编码代替:“–”需要用“–”;“—”需要用“—”
Summary: Looksfor usages of hyphens which can be replaced by n dash and m dash characters
Priority: 5 / 10
Severity: Warning
Category:Usability:Typography
The "n dash" (–, –) and the "mdash" (—,—) characters are used for ranges (n dash) and breaks (m dash). Usingthese instead of plain hyphens can make text easier to read and yourapplication will look more polished.
More information: http://en.wikipedia.org/wiki/Dash
------------------
特殊字符需用编码代替:“…”需要用“…”
Summary: Looksfor ellipsis strings (...) which can be replaced with an ellipsis character
Priority: 5 / 10
Severity: Warning
Category:Usability:Typography
You can replace the string "..." with a dedicatedellipsis character, ellipsis character (…, …). This can help make thetext more readable.
More information: http://en.wikipedia.org/wiki/Ellipsis
-------------------
特殊字符需用编码代替:“½”需要用“½”;“¼”需要用“¼”
Summary: Looksfor fraction strings which can be replaced with a fraction character
Priority: 5 / 10
Severity: Warning
Category:Usability:Typography
You can replace certain strings, such as 1/2, and 1/4, withdedicated characters for these, such as ½ (½) and ¼ (¼). This can help make thetext more readable.
More information: http://en.wikipedia.org/wiki/Number_Forms
----------------
引号的使用
Summary: Looksfor straight quotes which can be replaced by curvy quotes
Priority: 5 / 10
Severity: Warning
Category:Usability:Typography
NOTE: This issue is disabled by default! You can enable itby adding --enable TypographyQuotes
Straight single quotes and double quotes, when used as apair, can be replaced by "curvy quotes" (or directional quotes). Thiscan make the text more readable.
Note that you should never use grave accents and apostrophesto quote, `like this'. (Also note that you should not use curvy quotes for codefragments.)
More information:http://en.wikipedia.org/wiki/Quotation_mark
---------------
错误的将“(c)”用“©”代替
Summary: Looksfor miscellaneous typographical problems like replacing (c) with ©
Priority: 3 / 10
Severity: Warning
Category:Usability:Typography
This check looks for miscellaneous typographical problemsand offers replacement sequences that will make the text easier to read andyour application more polished.
===============
---------
Icon在nodpi和指定dpi的目录下都出现。
Summary: Findsicons that appear in both a -nodpi folder and a dpi folder
Priority: 7 / 10
Severity: Warning
Category: Usability:Icons
Bitmaps that appear in drawable-nodpi folders will not bescaled by the Android framework. If a drawable resource of the same nameappears *both* in a -nodpi folder as well as a dpi folder such asdrawable-hdpi, then the behavior is ambiguous and probably not intentional.Delete one or the other, or use different names for the icons.
--------
Image不要用GIF,最好用PNG,可以用JPG。
Summary: Checksfor images using the GIF file format which is discouraged
Priority: 5 / 10
Severity: Warning
Category:Usability:Icons
The .gif file format is discouraged. Consider using .png(preferred) or .jpg (acceptable) instead.
More information:http://developer.android.com/guide/topics/resources/drawable-resource.html#Bitmap
-----------
Summary: Ensuresthat icons across densities provide roughly the same density-independent size
Priority: 5 / 10
Severity: Warning
Category:Usability:Icons
Checks the all icons which are provided in multipledensities, all compute to roughly the same density-independent pixel (dip)size. This catches errors where images are either placed in the wrong folder,or icons are changed to new sizes but some folders are forgotten.
--------------------
Summary: Findsicons that have identical bitmaps across various configuration parameters
Priority: 5 / 10
Severity: Warning
Category:Usability:Icons
If an icon is provided under different configurationparameters such as drawable-hdpi or -v11, they should typically be different.This detector catches cases where the same icon is provided in differentconfiguration folder which is usually not intentional.
----------------
Summary: Ensuresthat launcher icons, notification icons etc have the correct size
Priority: 5 / 10
Severity: Warning
Category:Usability:Icons
NOTE: This issue is disabled by default! You can enable itby adding --enable IconExpectedSize
There are predefined sizes (for each density) for launchericons. You should follow these conventions to make sure your icons fit in withthe overall look of the platform.
More information:http://developer.android.com/design/style/iconography.html
------------
Summary: Ensuresthat images are not defined in the density-independent drawable folder
Priority: 5 / 10
Severity: Warning
Category:Usability:Icons
The res/drawable folder is intended for density-independentgraphics such as shapes defined in XML. For bitmaps, move it to drawable-mdpiand consider providing higher and lower resolution versions in drawable-ldpi,drawable-hdpi and drawable-xhdpi. If the icon *really* is density independent(for example a solid color) you can place it in drawable-nodpi.
More information:http://developer.android.com/guide/practices/screens_support.html
-------------
Summary: Ensuresthat icons provide custom versions for all supported densities
Priority: 4 / 10
Severity: Warning
Category:Usability:Icons
Icons will look best if a custom version is provided foreach of the major screen density classes (low, medium, high, extra high). Thislint check identifies icons which do not have complete coverage across thedensities.
Low density is not really used much anymore, so this checkignores the ldpi density. To force lint to include it, set the environmentvariable ANDROID_LINT_INCLUDE_LDPI=true. For more information on currentdensity usage, seehttp://developer.android.com/resources/dashboard/screens.html
More information:http://developer.android.com/guide/practices/screens_support.html
--------------
Summary: Findsduplicated icons under different names
Priority: 3 / 10
Severity: Warning
Category:Usability:Icons
If an icon is repeated under different names, you canconsolidate and just use one of the icons and delete the others to make yourapplication smaller. However, duplicated icons usually are not intentional andcan sometimes point to icons that were accidentally overwritten or accidentallynot updated.
------------------------
Summary: Ensuresthat all the density folders are present
Priority: 3 / 10
Severity: Warning
Category:Usability:Icons
Icons will look best if a custom version is provided foreach of the major screen density classes (low, medium, high, extra high). Thislint check identifies folders which are missing, such as drawable-hdpi.
Low density is not really used much anymore, so this checkignores the ldpi density. To force lint to include it, set the environmentvariable ANDROID_LINT_INCLUDE_LDPI=true. For more information on currentdensity usage, seehttp://developer.android.com/resources/dashboard/screens.html
More information:http://developer.android.com/guide/practices/screens_support.html
=========
-----------
Summary: Ensuresthe dismissive action of a dialog is on the left and affirmative on the right
Priority: 8 / 10
Severity: Warning
Category:Usability
According to the Android Design Guide, "Action buttonsare typically Cancel and/or OK, with OK indicating the preferred or most likelyaction. However, if the options consist of specific actions such as Close orWait rather than a confirmation or cancellation of the action described in thecontent, then all the buttons should be active verbs. As a rule, the dismissiveaction of a dialog is always on the left whereas the affirmative actions are onthe right."
This check looks for button bars and buttons which look likecancel buttons, and makes sure that these are on the left.
More information: http://developer.android.com/design/building-blocks/dialogs.html
----------
Android中不要设计有Back的按钮,Android中一般有Back的硬按键。
Summary: Looksfor Back buttons, which are not common on the Android platform.
Priority: 6 / 10
Severity: Warning
Category:Usability
NOTE: This issue is disabled by default! You can enable itby adding --enable BackButton
According to the Android Design Guide, "Other platformsuse an explicit back button with label to allow the user to navigate up theapplication's hierarchy. Instead, Android uses the main action bar's app iconfor hierarchical navigation and the navigation bar's back button for temporalnavigation."
This check is not very sophisticated (it just looks forbuttons with the label "Back"), so it is disabled by default to nottrigger on common scenarios like pairs of Back/Next buttons to paginate throughscreens.
More information:http://developer.android.com/design/patterns/pure-android.html
----------
Summary: Looksfor text fields missing inputType or hint settings
Priority: 5 / 10
Severity: Warning
Category:Usability
Providing an inputType attribute on a text field improvesusability because depending on the data to be input, optimized keyboards can beshown to the user (such as just digits and parentheses for a phone number).Similarly, a hint attribute displays a hint to the user for what is expected inthe text field.
If you really want to keep the text field generic, you cansuppress this warning by setting inputType="text".
----------------
Summary: Checksfor uses of showAsAction="always" and suggests showAsAction="ifRoom"instead
Priority: 3 / 10
Severity: Warning
Category:Usability
Using showAsAction="always" in menu XML, orMenuItem.SHOW_AS_ACTION_ALWAYS in Java code is usually a deviation from theuser interface style guide. Use "ifRoom" or the correspondingMenuItem.SHOW_AS_ACTION_IF_ROOM instead.
If "always" is used sparingly there are usually noproblems and behavior is roughly equivalent to "ifRoom" but withpreference over other "ifRoom" items. Using it more than twice in thesame menu is a bad idea.
This check looks for menu XML files that contain more thantwo "always" actions, or some "always" actions and no"ifRoom" actions. In Java code, it looks for projects that containreferences to MenuItem.SHOW_AS_ACTION_ALWAYS and no references toMenuItem.SHOW_AS_ACTION_IF_ROOM.
More information:http://developer.android.com/design/patterns/actionbar.html
---------------
Summary: Checksthat custom views define the expected constructors
Priority: 3 / 10
Severity: Warning
Category:Usability
Some layout tools (such as the Android layout editor forEclipse) needs to find a constructor with one of the following signatures:
* View(Context context)
* View(Context context, AttributeSet attrs)
* View(Context context, AttributeSet attrs, int defStyle)
If your custom view needs to perform initialization whichdoes not apply when used in a layout editor, you can surround the given codewith a check to see if View#isInEditMode() is false, since that method willreturn false at runtime but true within a user interface editor.
----------
Button的“Ok”/“Cancel”显示大小写一定,不要全大写或全小写。有标准的资源的字符串,不要自己再定义,而要用系统定义的:@android:string/ok和@android:string/cancel
Summary: Ensuresthat Cancel/OK dialog buttons use the canonical capitalization
Priority: 2 / 10
Severity: Warning
Category:Usability
The standard capitalization for OK/Cancel dialogs is"OK" and "Cancel". To ensure that your dialogs use thestandard strings, you can use the resource strings @android:string/ok and@android:string/cancel.
=============
------------------
ImageView和ImageButton应该提供contentDescription
Summary: Ensuresthat image widgets provide a contentDescription
Priority: 3 / 10
Severity: Warning
Category:Accessibility
Non-textual widgets like ImageViews and ImageButtons shoulduse the contentDescription attribute to specify a textual description of thewidget such that screen readers and other accessibility tools can adequatelydescribe the user interface.
====================
-------------
硬编码的字符串应该在资源里定义
Summary: Looksfor hardcoded text attributes which should be converted to resource lookup
Priority: 5 / 10
Severity: Warning
Category: Internationalization
Hardcoding text attributes directly in layout files is badfor several reasons:
* When creating configuration variations (for example forlandscape or portrait)you have to repeat the actual text (and keep it up todate when making changes)
* The application cannot be translated to other languages byjust adding new translations for existing string resources.
-----------
所有XML资源文件都应该以UTF-8编码
Summary: Checksthat all XML resource files are using UTF-8 as the file encoding
Priority: 2 / 10
Severity: Warning
Category:Internationalization
XML supports encoding in a wide variety of character sets.However, not all tools handle the XML encoding attribute correctly, and nearlyall Android apps use UTF-8, so by using UTF-8 you can protect yourself againstsubtle bugs when using non-ASCII characters.