在使用Android Studio提供的工具配置了掃描範圍和檢查項以後,經過lint.xml文件列出issue列表,對靜態掃描進行補充。屬於手動運行檢查中的步驟,參照使用Android Studio Lint靜態分析(一)。php
文件名約定:
1. 把Inspections對話框中配置生成的文件命名爲inspection.xml。
2. lint.xml文件名是固定的。
複製代碼
❣️特別提醒:Inspections對話框中的配置,保存在工程目錄下的 .idea/inspectionProfiles/inspection.xml 中。api
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Default" />
<inspection_tool class="AndroidLintUnusedResources" enabled="false" level="ERROR" enabled_by_default="false" />
</profile>
</component>
複製代碼
- enabled:是否對此項進行檢查
- level: 問題警告級別
- class: class的值與lint.xml文件中的issue.id是對應的, class=AndroidLint${issue.id}
lint.xml文件的文件名是固定的,放在項目的根目錄。lint.xml文件內定義的規則,是對已設置的檢查項作排除--禁用某些已經啓用的檢查項。bash
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<!-- Disable the given check in this project -->
<issue id="UnusedResources" severity="ignore"/>
<issue id="Deprecated" severity="warning">
<ignore regexp="singleLine"/>
<ignore path="aaa.txt" />
</issue>
</lint>
複製代碼
每個issue標籤指定一個規則。指定禁用規則的方法有兩種:less
Android Studio支持的檢查項是Android Lint的超集。dom
lint.xml支持的規則包含在Android->Lint內。如圖2、圖三所示,Android Lint支持的規則有🤙種類型共304個小項。ide
類型 | 數量 | 檢查項 |
---|---|---|
Accessibility | 5 | ClickableViewAccessibility、ContentDescription、GetContentDescriptionOverride、KeyboardInaccessibleWidget、LabelFor |
Internationalization | 9 | ByteOrderMark、EnforceUTF八、HardcodedText、RelativeOverlap、RtlCompat、RtlEnabled、RtlHardcoded、RtlSymmetry、SetTextI18n |
Performance | 32 | AnimatorKeep、DevModeObsolete、DisableBaselineAlignment、DrawAllocation、DuplicateDivider、FloatMath、HandlerLeak、InefficientWeight、LogConditional、MergeRootFrame、NestedWeights、ObsoleteLayoutParam、ObsoleteSdkInt、Overdraw、Recycle、StaticFieldLeak、TooDeepLayout、TooManyViews、UnpackedNativeCode、UnusedIds、UnusedResources、UseCompoundDrawables、UseOfBundledGooglePlayServices、UseSparseArrays、UseValueOf、UselessLeaf、UselessParent、VectorPath、ViewHolder、ViewTag、WakelockTimeout、WearableBindListener |
Security | 34 | AddJavascriptInterface、JavascriptInterface、AllowAllHostnameVerifier、AllowBackup、AuthLeak、BadHostnameVerifier、EasterEgg、ExportedContentProvider、ExportedPreferenceActivity、ExportedReceiver、ExportedService、GetInstance、GrantAllUris、HardcodedDebugMode、HardwareIds、InvalidPermission、PackageManagerGetSignatures、PackagedPrivateKey、SSLCertificateSocketFactoryCreateSocket、SSLCertificateSocketFactoryGetInsecure、SecureRandom、SetJavaScriptEnabled、SetWorldReadable、SetWorldWritable、SignatureOrSystemPermissions、TrustAllX509TrustManager、UnprotectedSMSBroadcastReceiver、UnsafeDynamicallyLoadedCode、UnsafeNativeCodeLocation、UnsafeProtectedBroadcastReceiver、UseCheckPermission、UsingHttp、WorldReadableFiles、WorldWriteableFiles |
Usability | 14 | AlwaysShowAction、AppLinkUrlError、BackButton、ButtonCase、ButtonOrder、ButtonStyle、GoogleAppIndexingApiWarning、GoogleAppIndexingWarning、MenuTitle、NegativeMargin、SelectableText、SmallSp、TextFields、ViewConstructor |
Usability.Typography | 6 | AllCaps、TypographyDashes、TypographyEllipsis、TypographyFractions、TypographyOther、TypographyQuotes |
Usability.Icons | 18 | ConvertToWebp、GifUsage、IconColors、IconDensities、IconDipSize、IconDuplicates、IconDuplicatesConfig、IconExpectedSize、IconExtension、IconLauncherShape、IconLocation、IconMissingDensityFolder、IconMixedNinePatch、IconNoDpi、IconXmlAndPng、MipmapIcons、MissingApplicationIcon、WebpUnsupported |
Correctness | 173 | AaptCrash、AccidentalOctal、AdapterViewChildren、AppCompatCustomView、AppCompatMethod、AppCompatResource、AppIndexingService、AppLinksAutoVerifyError、AppLinksAutoVerifyWarning、ApplySharedPref、Assert、BatteryLife、CheckResult、CommitPrefEdits、CommitTransaction、CustomViewStyleable、CutPasteId、DefaultLocale、Deprecated、DeviceAdmin、DuplicateActivity、DuplicateDefinition、DuplicateIds、DuplicateIncludedIds、DuplicatePlatformClasses、DuplicateUsesFeature、EllipsizeMaxLines、ExifInterface、ExtraText、FindViewByIdCast、FontValidationError、FontValidationWarning、FullBackupContent、GetLocales、GradleCompatible、GradleDependency、GradleDeprecated、GradleDynamicVersion、GradleGetter、GradleIdeError、GradleOverrides、GradlePath、GradlePluginVersion、GridLayout、HalfFloat、HighAppVersionCode、IllegalResourceRef、ImpliedTouchscreenHardware、InOrMmUsage、IncludeLayoutParam、IncompatibleMediaBrowserServiceCompatVersion、InconsistentArrays、InconsistentLayout、InflateParams、InlinedApi、InnerclassSeparator、InstantApps、InvalidAnalyticsName、InvalidId、InvalidImeActionId、InvalidResourceFolder、InvalidUsesTagAttribute、InvalidVectorPath、InvalidWearFeatureAttribute、JobSchedulerService、LibraryCustomView、LocalSuppress、LocaleFolder、LogTagMismatch、LongLogTag、MangledCRLF、ManifestOrder、ManifestResource、MergeMarker、MinSdkTooLow、MissingBackupPin、MissingConstraints、MissingFirebaseInstanceTokenRefresh、MissingId、MissingIntentFilterForMediaSearch、MissingLeanbackLauncher、MissingLeanbackSupport、MissingMediaBrowserServiceIntentFilter、MissingOnPlayFromSearch、MissingPermission、MissingPrefix、MissingSuperCall、MissingTvBanner、MissingVersion、MockLocation、MultipleUsesSdk、NamespaceTypo、NestedScrolling、NetworkSecurityConfig、NewApi、NewerVersionAvailable、NfcTechWhitespace、NotInterpolated、NotSibling、ObjectAnimatorBinding、OldTargetApi、OnClick、Orientation、Override、OverrideAbstract、ParcelClassLoader、ParcelCreator、PendingBindings、PermissionImpliesUnsupportedHardware、PinSetExpiry、PrivateApi、PrivateResource、Proguard、ProguardSplit、PropertyEscape、ProtectedPermissions、PxUsage、Range、RecyclerView、ReferenceType、Registered、RequiredSize、ResAuto、ResourceAsColor、ResourceCycle、ResourceName、ResourceType、RestrictedApi、SQLiteString、ScrollViewCount、ScrollViewSize、SdCardPath、ServiceCast、ShiftFlags、ShortAlarm、ShowToast、SimpleDateFormat、SpUsage、StateListReachable、StopShip、StringShouldBeInt、SupportAnnotationUsage、Suspicious0dp、SuspiciousImport、SwitchIntDef、TestAppLink、TextViewEdits、UniqueConstants、UniquePermission、UnknownId、UnknownIdInLayout、UnlocalizedSms、UnsupportedTvHardware、UnusedAttribute、UseAlpha二、UsesMinSdkAttributes、ValidFragment、ValidRestrictions、VectorDrawableCompat、VectorRaster、VisibleForTests、WearStandaloneAppFlag、WebViewLayout、WifiManagerLeak、WifiManagerPotentialLeak、WrongCall、WrongCase、WrongConstant、WrongFolder、WrongRegion、WrongThread、WrongThreadInterprocedural、WrongViewCast |
Correctness.Messages | 11 | ExtraTranslation、ImpliedQuantity、MissingQuantity、MissingTranslation、PluralsCandidate、StringEscaping、StringFormatCount、StringFormatInvalid、StringFormatMatches、UnusedQuantity、Typos |
Correctness.Chrome OS | 2 | PermissionImpliesUnsupportedChromeOsHardware、UnsupportedChromeOsHardware |
合計 | 304 |
規則項目太多並且沒有說明,這樣閱讀比較困難對實際應用沒有太多做用,但願後面會有時間整理。工具