**This article is a part of _Configuring Android Project_ series:** 1. [Little Things That Matter](https://medium.com/@dmytrodanylyk/configuring-android-project-little-things-that-matter-d6a9d34c1ce0#.nnc4yq8ur) 2. [Version Name & Code](https://medium.com/@dmytrodanylyk/configuring-android-project-version-name-code-b168952f3323#.uccnmsg8b) 3. [Static Code Analysis Tools](https://medium.com/@dmytrodanylyk/configuring-android-project-static-code-analysis-tools-b6dd83282921#.n6ulbiupn) 4. Continuous Integration > Everything we have discussed in current article is available in [template](https://github.com/dmytrodanylyk/template) project. ### Static Code Analysis Tools Static code analysis tools — analyze code without executing it. Generally used to find bugs or ensure conformance to coding guidelines. Helps to keep your code healthy and maintain code quality. On _Android_ the most popular code analysis tools are: * Lint * PMD * Findbugs I usually keep static code analysis scripts and related file in [_separate folder_](https://github.com/dmytrodanylyk/template/tree/master/tools). ### Lint > The lint tool checks your Android project source files for potential bugs and optimization improvements for correctness, security, performance, usability, accessibility, and internationalization. #### Config To add _lint_ to your android project create [_script-lint.gradle_](https://github.com/dmytrodanylyk/template/blob/master/tools/script-lint.gradle) file. <a href="https://medium.com/media/e1c1a139f832df2c153e1e8545138ce5/href">https://medium.com/media/e1c1a139f832df2c153e1e8545138ce5/href</a> Important _lint_ options: * _lintConfig_ — path to lint rulesets file where you can suppress issues. * _htmlOutput_ — path where html report will be generated. Import _script-lint.gradle_ to your [_build.gradle_](https://github.com/dmytrodanylyk/template/blob/master/app/build.gradle#L4) file. <a href="https://medium.com/media/16aa0e976adcf7c7749861fc8ff5c035/href">https://medium.com/media/16aa0e976adcf7c7749861fc8ff5c035/href</a> #### Test Rebuild your project and then run _lint_ with _./gradlew lint_ command. In case it finds some issues you will see similar output. ./gradlew lint Execution failed for task ':app:lint. Lint found errors in the project; aborting build. Wrote HTML report to: template/app/build/outputs/lint/lint.html When you open _lint.html_ report file you will see list of issues with description and advices how to fix them. In case you want to ignore this issues add following rule to [_rules-lint.xml_](https://github.com/dmytrodanylyk/template/blob/master/tools/rules-lint.xml) file. <a href="https://medium.com/media/619666e58f5a5652f89442c84b2de41c/href">https://medium.com/media/619666e58f5a5652f89442c84b2de41c/href</a> **_Note:_** _there are other ways how you can_ [_suppress lint warnings_](http://tools.android.com/tips/lint/suppressing-lint-warnings)_. More information about lint is available on_ [_official site_](http://tools.android.com/tips/lint)_._ ### **Findbugs** > Static code analysis tool that analyses Java bytecode and detects a wide range of problems. #### Config To add _findbugs_ to your android project create [_script-findbugs.gradle_](https://github.com/dmytrodanylyk/template/blob/master/tools/script-findbugs.gradle) file. <a href="https://medium.com/media/66e837890a9d6b6124c1e0a27664aa1a/href">https://medium.com/media/66e837890a9d6b6124c1e0a27664aa1a/href</a> Important _findbugs_ options: * _excludeFilter_ — path to _findbugs_ rulesets file where you can suppress issues. * _classes_ — path to generated classes _(if you have more then one flavor, path consists of flavor name, in current case ‘dev’)._ * _source_ — path to source code. * _html.destination_ — path where html report will be generated. Import _script-findbugs.gradle_ to your [_build.gradle_](https://github.com/dmytrodanylyk/template/blob/master/app/build.gradle#L3) file. <a href="https://medium.com/media/150d839a15607039ff56c49a48969eb3/href">https://medium.com/media/150d839a15607039ff56c49a48969eb3/href</a> #### Test For testing purposes we will create following method. <a href="https://medium.com/media/e64a6d52e65f83728c86a201568def86/href">https://medium.com/media/e64a6d52e65f83728c86a201568def86/href</a> Rebuild your project and then run _findbugs_ with _./gradlew findbugs_ command. In case it finds some issues you will see similar output. >./gradlew findbugs Execution failed for task ':app:findbugs'. FindBugs rule violations were found. See the report at: template/app/build/outputs/findbugs/findbugs.html When you open _findbugs.html_ report file you will see list of issues with description and advices how to fix them.  In case you want to ignore this issues add following rule to [_rules-findbugs.xml_](https://github.com/dmytrodanylyk/template/blob/master/tools/rules-findbugs.xml) file. <a href="https://medium.com/media/8b0789ec964d2c9fd255fbffeedb3d5c/href">https://medium.com/media/8b0789ec964d2c9fd255fbffeedb3d5c/href</a> **_Note:_** _there are other ways how you can_ [_suppress findbugs warnings_](http://findbugs.sourceforge.net/manual/filter.html)_. More information about findbugs is available on_ [_official site_](http://findbugs.sourceforge.net/manual/index.html)_._ ### PMD > PMD is a source code analyzer. It finds common programming flaws like unused variables, empty catch blocks, unnecessary object creation, and so forth. #### Config To add _pmd_ to your android project create [_script-pmd.gradle_](https://github.com/dmytrodanylyk/template/blob/master/tools/script-pmd.gradle) file. <a href="https://medium.com/media/eeebcff2d66f7f242a2997bfd3c2f062/href">https://medium.com/media/eeebcff2d66f7f242a2997bfd3c2f062/href</a> Important _pmd_ options: * _ruleSetFiles_ — path to _pmd_ rulesets file where you can suppress issues and define which issues to track. * _source_ — path to source code. * _html.destination_ — path where html report will be generated. Import _script-pmd.gradle_ to your [_build.gradle_](https://github.com/dmytrodanylyk/template/blob/master/app/build.gradle#L5) file. <a href="https://medium.com/media/96f7bed2efff2bf44e6a48d857ddbcb5/href">https://medium.com/media/96f7bed2efff2bf44e6a48d857ddbcb5/href</a> #### Test For testing purposes we will create following method. <a href="https://medium.com/media/18c8b8e281468c7517007365b77def14/href">https://medium.com/media/18c8b8e281468c7517007365b77def14/href</a> Rebuild your project and then run _pmd_ with _./gradlew pmd_ command. In case it finds some issues you will see similar output. >./gradlew pmd Execution failed for task ':app:pmd. 7 PMD rule violations were found. See the report at: template/app/build/outputs/pmd/pmd.html When you open _pmd.html_ report file you will see list of issues with description and advices how to fix them.  In case you want to ignore this issues add following rule to [_rules-pmd.xml_](https://github.com/dmytrodanylyk/template/blob/master/tools/rules-pmd.xml) file. <a href="https://medium.com/media/e62e195c7b0a0e091f455ace252a7e25/href">https://medium.com/media/e62e195c7b0a0e091f455ace252a7e25/href</a> **_Note:_** _there are other ways how you can_ [_suppress pmd warnings_](https://pmd.github.io/pmd-5.5.4/usage/suppressing.html)_. More information about pmd is available on_ [_official site_](https://pmd.github.io/pmd-5.5.4/index.html)_._