多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > 綜合技術 > Android靜態代碼檢查-Lint

Android靜態代碼檢查-Lint

來源:程序員人生   發布時間:2016-02-28 11:45:14 閱讀次數:2545次

參考文章:
Improving Your Code with lint
lint
使用 lint 增強你的代碼
Android Lint簡介

gradle lint

gradle中有lint任務,可以直接履行lint靜態代碼檢查,但是條件是你的build.gradle設置了lintOptions選項:

android { compileSdkVersion 23 buildToolsVersion "21.1.2" lintOptions { abortOnError false }

然后我們在項目的根目錄下履行gradle lint:

localhost:Sunshine-Version⑵ wuxian$ gradle lint :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72102Library UP-TO-DATE :app:prepareComAndroidSupportSupportV42102Library UP-TO-DATE :app:prepareDebugDependencies :app:compileDebugAidl UP-TO-DATE :app:compileDebugRenderscript UP-TO-DATE :app:generateDebugBuildConfig UP-TO-DATE :app:generateDebugAssets UP-TO-DATE :app:mergeDebugAssets UP-TO-DATE :app:generateDebugResValues UP-TO-DATE :app:generateDebugResources UP-TO-DATE :app:mergeDebugResources UP-TO-DATE :app:processDebugManifest UP-TO-DATE :app:processDebugResources UP-TO-DATE :app:generateDebugSources UP-TO-DATE :app:processDebugJavaRes UP-TO-DATE :app:compileDebugJavaWithJavac UP-TO-DATE :app:compileLint :app:checkReleaseManifest :app:prepareReleaseDependencies :app:compileReleaseAidl UP-TO-DATE :app:compileReleaseRenderscript UP-TO-DATE :app:generateReleaseBuildConfig UP-TO-DATE :app:generateReleaseAssets UP-TO-DATE :app:mergeReleaseAssets UP-TO-DATE :app:generateReleaseResValues UP-TO-DATE :app:generateReleaseResources UP-TO-DATE :app:mergeReleaseResources UP-TO-DATE :app:processReleaseManifest UP-TO-DATE :app:processReleaseResources UP-TO-DATE :app:generateReleaseSources UP-TO-DATE :app:processReleaseJavaRes UP-TO-DATE :app:compileReleaseJavaWithJavac UP-TO-DATE :app:lint Ran lint on variant release: 58 issues found Ran lint on variant debug: 58 issues found Wrote HTML report to file:/Users/wuxian/Documents/sourcecode/self/Sunshine-Version⑵/app/build/outputs/lint-results.html Wrote XML report to /Users/wuxian/Documents/sourcecode/self/Sunshine-Version⑵/app/build/outputs/lint-results.xml BUILD SUCCESSFUL Total time: 17.941 secs This build could be faster, please consider using the Gradle Daemon: http://gradle.org/docs/2.4/userguide/gradle_daemon.html

在build/outputs/目錄下會生成1個lint-result.html文件,打開1看以下:這里寫圖片描述

報告做的太次了

更多參數

lintOptions { // set to true to turn off analysis progress reporting by lint quiet true // if true, stop the gradle build if errors are found abortOnError false // if true, only report errors ignoreWarnings true // if true, emit full/absolute paths to files with errors (true by default) //absolutePaths true // if true, check all issues, including those that are off by default checkAllWarnings true // if true, treat all warnings as errors warningsAsErrors true // turn off checking the given issue ids disable TypographyFractions,TypographyQuotes // turn on the given issue ids enable RtlHardcoded,RtlCompat, RtlEnabled // check *only* the given issue ids check NewApi, InlinedApi // if true, dont include source code lines in the error output noLines true // if true, show all locations for an error, do not truncate lists, etc. showAll true // Fallback lint configuration (default severities, etc.) lintConfig file("default-lint.xml") // if true, generate a text report of issues (false by default) textReport true // location to write the output; can be a file or stdout textOutput stdout // if true, generate an XML report for use by for example Jenkins xmlReport false // file to write report to (if not specified, defaults to lint-results.xml) xmlOutput file("lint-report.xml") // if true, generate an HTML report (with issue explanations, sourcecode, etc) htmlReport true // optional path to report (default will be lint-results.html in the builddir) htmlOutput file("lint-report.html") // set to true to have all release builds run lint on issues with severity=fatal // and abort the build (controlled by abortOnError above) if fatal issues are found checkReleaseBuilds true // Set the severity of the given issues to fatal (which means they will be // checked during release builds (even if the lint target is not included) fatal NewApi, InlineApi // Set the severity of the given issues to error error Wakelock, TextViewEdits // Set the severity of the given issues to warning warning ResourceAsColor // Set the severity of the given issues to ignore (same as disabling the check) ignore TypographyQuotes }

總結

這類方式合適自動化CI系統中收集結果。

手動分析

這里寫圖片描述

選在分析代碼后,彈出對話框,你可以選擇分析全部項目/單個模塊/文件bulabula:

這里寫圖片描述

點擊OK后,等待1段時間后分析終了,會自動彈出結果窗口

這里寫圖片描述

這里寫圖片描述
會根據檢查類型不同分不同菜單,點擊相應菜單進入不同的問題點:

這里寫圖片描述

點擊問題點后右側會出現該問題的詳細信息,文件名,文件位置,出現問題的點在文件中的位置和問題描寫,還會告知你疏忽這個問題的解決方法,有可能還會顯示解決方法。

總結

這個方法合適開發自查!

lint命令行

lint工具位于sdk目錄下的tools下,如果在命令行履行lint找不到該命令,那末需要將lint的根目錄配置到環境變量中,配置成功后,履行lint命令輸出以下:

58deMacBook-Pro-5:tools wuxian$ lint Usage: lint [flags]Flags: --help This message. --helpHelp on the given topic, such as "suppress". --list List the available issue ids and exit. --version Output version information and exit. --exitcode Set the exit code to 1 if errors are found. --show List available issues along with full explanations. --showShow full explanations for the given list of issue ids. Enabled Checks: --disableDisable the list of categories or specific issue ids. The list should be a comma-separated list of issue ids or categories. --enableEnable the specific list of issues. This checks all the default issues plus the specifically enabled issues. The list should be a comma-separated list of issue ids or categories. --checkOnly check the specific list of issues. This will disable everything and re-enable the given list of issues. The list should be a comma-separated list of issue ids or categories. -w, --nowarn Only check for errors (ignore warnings) -Wall Check all warnings, including those off by default -Werror Treat all warnings as errors --configUse the given configuration file to determine whether issues are enabled or disabled. If a project contains a lint.xml file, then this config file will be used as a fallback. Output Options: --quiet Dont show progress. --fullpath Use full paths in the error output. --showall Do not truncate long messages, lists of alternate locations, etc. --nolines Do not include the source file lines with errors in the output. By default, the error output includes snippets of source code on the line containing the error, but this flag turns it off. --htmlCreate an HTML report instead. If the filename is a directory (or a new filename without an extension), lint will create a separate report for each scanned project. --url filepath=url Add links to HTML report, replacing local path prefixes with url prefix. The mapping can be a comma-separated list of path prefixes to corresponding URL prefixes, such as C: empProj1=http://buildserver/sources/temp/Proj1. To turn off linking to files, use --url none --simplehtmlCreate a simple HTML report --xmlCreate an XML report instead. Project Options: --resourcesAdd the given folder (or path) as a resource directory for the project. Only valid when running lint on a single project. --sourcesAdd the given folder (or path) as a source directory for the project. Only valid when running lint on a single project. --classpathAdd the given folder (or jar file, or path) as a class directory for the project. Only valid when running lint on a single project. --librariesAdd the given folder (or jar file, or path) as a class library for the project. Only valid when running lint on a single project. Exit Status: 0 Success. 1 Lint errors detected. 2 Lint usage. 3 Cannot clobber existing file. 4 Lint help. 5 Invalid command-line argument.

版權聲明:本文為博主原創文章,未經博主允許不得轉載。

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 欧美猛交xxxx免费看 | 亚洲欧美中文字幕专区 | 亚洲一区二区三区精品视频 | 亚洲国产精品一区二区首页 | 国产成人a福利在线观看 | 一区二区三区不卡在线观看 | 天堂在线www | 欧美精品免费一区欧美久久优播 | 日本免费网站视频www区 | 欧美70一80老妇性大片 | 日韩久久一区二区三区 | 最近高清中文字幕大全免费1 | 亚洲欧美色中文字幕 | 91亚洲免费 | 成人午夜精品网站在线观看 | 亚洲不卡视频在线观看 | 羞羞免费网页登界面入口 | 国产亚洲欧美另类一区二区三区 | 最近中文字幕大全2019 | 欧美一级看片免费观看视频在线 | 久久黄色毛片 | 欧美一级大黄特黄毛片视频 | 91精品国产综合久久久久久 | 国产高清乱码无卡女大生 | 成年人在线视频免费观看 | 另类亚洲图片 | 在线观看国产小视频 | 宇都宫紫苑在线播放 rmvb | 成人男女啪啪免费观看网站 | 亚洲欧美日韩不卡一区二区三区 | 欧美亚洲偷图色综合91 | 成人精品国产亚洲欧洲 | 国产成人亚洲精品2020 | 欧美人xxxx另类 | 久草午夜 | 韩国三级一线观看久 | 欧美人与动人物姣配xxxx | 最近中文字幕免费完整国语 | 一区二区三区鲁丝不卡麻豆 | 天码毛片一区二区三区入口 | 欧美性色欧美a在线观看 |