Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard.

Steps to enable checkstyle for Android Project

Create checkstyle.xml

Create folder checkstyle inside Android Project app folder. Create file checkstyle.xml Reference

<?xml version="1.0"?>
    "-//Puppy Crawl//DTD Check Configuration 1.2//EN"

  Checkstyle configuration that checks the sun coding conventions from:
    - the Java Language Specification at
    - the Sun Code Conventions at
    - the Javadoc guidelines at
    - the JDK Api documentation
    - some best practices
  Checkstyle is very configurable. Be sure to read the documentation at (or in your downloaded distribution).
  Most Checks are configurable, be sure to consult the documentation.
  To completely disable a check, just comment it out or delete it from the file.
  Finally, it is worth reading the documentation.

<module name="Checker">
        If you set the basedir property below, then all reported file
        names will be relative to the specified directory. See
        <property name="basedir" value="${basedir}"/>

    <!-- Checks that a file exists for each package.     -->
    <!-- See -->
    <module name="JavadocPackage"/>

    <!-- Checks whether files end with a new line.                        -->
    <!-- See -->
    <module name="NewlineAtEndOfFile"/>

    <!-- Checks that property files contain the same keys.         -->
    <!-- See -->
    <module name="Translation"/>

    <!-- Checks for Size Violations.                    -->
    <!-- See -->
    <module name="FileLength"/>

    <!-- Checks for whitespace                               -->
    <!-- See -->
    <module name="FileTabCharacter"/>

    <!-- Miscellaneous other checks.                   -->
    <!-- See -->
    <module name="RegexpSingleline">
       <property name="format" value="\s+$"/>
       <property name="minimum" value="0"/>
       <property name="maximum" value="0"/>
       <property name="message" value="Line has trailing spaces."/>

    <module name="TreeWalker">

        <!-- Checks for Javadoc comments.                     -->
        <!-- See -->
        <module name="JavadocMethod"/>
        <module name="JavadocType"/>
        <module name="JavadocVariable"/>
        <module name="JavadocStyle"/>

        <!-- Checks for Naming Conventions.                  -->
        <!-- See -->
        <module name="ConstantName"/>
        <module name="LocalFinalVariableName"/>
        <module name="LocalVariableName"/>
        <module name="MemberName"/>
        <module name="MethodName"/>
        <module name="PackageName"/>
        <module name="ParameterName"/>
        <module name="StaticVariableName"/>
        <module name="TypeName"/>

        <!-- Checks for Headers                                -->
        <!-- See   -->
        <!-- <module name="Header">                            -->
            <!-- The follow property value demonstrates the ability     -->
            <!-- to have access to ANT properties. In this case it uses -->
            <!-- the ${basedir} property to allow Checkstyle to be run  -->
            <!-- from any directory within a project. See property      -->
            <!-- expansion,                                             -->
            <!--        -->
            <!-- <property                                              -->
            <!--     name="headerFile"                                  -->
            <!--     value="${basedir}/java.header"/>                   -->
        <!-- </module> -->

        <!-- Following interprets the header file as regular expressions. -->
        <!-- <module name="RegexpHeader"/>                                -->

        <!-- Checks for imports                              -->
        <!-- See -->
        <module name="AvoidStarImport"/>
        <module name="IllegalImport"/> <!-- defaults to sun.* packages -->
        <module name="RedundantImport"/>
        <module name="UnusedImports"/>

        <!-- Checks for Size Violations.                    -->
        <!-- See -->
        <module name="LineLength"/>
        <module name="MethodLength"/>
        <module name="ParameterNumber"/>

        <!-- Checks for whitespace                               -->
        <!-- See -->
        <module name="EmptyForIteratorPad"/>
        <module name="GenericWhitespace"/>
        <module name="MethodParamPad"/>
        <module name="NoWhitespaceAfter"/>
        <module name="NoWhitespaceBefore"/>
        <module name="OperatorWrap"/>
        <module name="ParenPad"/>
        <module name="TypecastParenPad"/>
        <module name="WhitespaceAfter"/>
        <module name="WhitespaceAround"/>

        <!-- Modifier Checks                                    -->
        <!-- See -->
        <module name="ModifierOrder"/>
        <module name="RedundantModifier"/>

        <module name="AvoidNestedBlocks"/>
        <module name="EmptyBlock"/>
        <module name="LeftCurly"/>
        <module name="NeedBraces"/>
        <module name="RightCurly"/>
        <module name="AvoidInlineConditionals"/>
        <module name="DoubleCheckedLocking"/>    <!-- MY FAVOURITE -->
        <module name="EmptyStatement"/>
        <module name="EqualsHashCode"/>
        <module name="HiddenField"/>
        <module name="IllegalInstantiation"/>
        <module name="InnerAssignment"/>
        <module name="MagicNumber"/>
        <module name="MissingSwitchDefault"/>
        <module name="RedundantThrows"/>
        <module name="SimplifyBooleanExpression"/>
        <module name="SimplifyBooleanReturn"/>
        <module name="DesignForExtension"/>
        <module name="FinalClass"/>
        <module name="HideUtilityClassConstructor"/>
        <module name="InterfaceIsType"/>
        <module name="VisibilityModifier"/>



Create checkstyle.gradle

Create checkstyle.gradle inside app folder (at same level where build.gradle exists)

apply plugin: 'checkstyle'

checkstyle {
    description: 'code style check'
    group 'verification'
    configFile file('checkstyle/checkstyle.xml)

task checkstyle(type: Checkstyle, group: 'verification') {
    source 'src'
    include '**/*.java'
    exclude '**/gen/**'
    exclude '**/'
    classpath = files()

Enable checkstyle.gradle

Edit build.gradle(Project:**) and add

    apply from:"checkstyle.gradle"
        check.dependsOn 'checkstyle'


Run/Build application (preBuild.dependsOn('checkstyle') will force the build to fail if checkstyle finds any violation); or Open Terminal and execute gradle check --stacktrace

You can see HTML violations report at app/build/reports/checkstyle/checkstyle.html