在使用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 |
规则项目太多并且没有说明,这样阅读比较困难对实际应用没有太多做用,但愿后面会有时间整理。工具