Skip to content

lintChecks with AGP7 #56

Open
Open
@androideveloper

Description

@androideveloper

We are currently migrating to AGP 7 and noticed that our custom lint rules are not included in the lint checks.
We previously included them using lintChecks project(":libraries:lint-rules") and we only need them for local code check, so no publishing needed. Is there anything specific that needs to be changed to make it work with AGP 7?

Activity

tnorbye

tnorbye commented on Sep 10, 2021

@tnorbye
Collaborator

Do you mean that they're not packaged (e.g. the AAR file does not contain a lint.jar) or that somehow the checks aren't working/being applied?

androideveloper

androideveloper commented on Sep 13, 2021

@androideveloper
Author

the checks aren't working/being applied

this.

An example of a lint check we have is below. And to test the setup, we previously added a usage of SimpleDateFormat and could see it in the lint report. After updating to AGP 7 we don't see it in the lint report.

@Suppress("UnstableApiUsage")
class LegacyDateNamingPatternDetector : Detector(), Detector.UastScanner {
    override fun getApplicableUastTypes() = listOf(UImportStatement::class.java)

    override fun createUastHandler(context: JavaContext) = LegacyDateInvalidImportHandler(context)
}

class LegacyDateInvalidImportHandler(private val context: JavaContext) : UElementHandler() {
    override fun visitImportStatement(node: UImportStatement) {
        node.importReference?.let { importReference ->
            if (importReference.asSourceString().contains("java.text.SimpleDateFormat")) {
                context.report(IssueLegacyDateImport, node, context.getLocation(importReference), "Forbidden import of Legacy Date API")
            }
        }
    }
}


class IssueRegistry : IssueRegistry() {
    override val issues: List<Issue> = listOf(
        IssueLegacyDateImport,
        IssueContextCompatIncorrectUsage
    )

    override val api: Int = CURRENT_API

    override val vendor: Vendor = Vendor(
        vendorName = "placeholder",
        feedbackUrl = "placeholder",
        contact = "placeholder"
    )
}

val IssueLegacyDateImport = Issue.create(
    id = "LegacyDateImport",
    briefDescription = "Old Java date APIs used",
    explanation = "Use Java 8 dates instead. See DateTimeExt class for more info.",
    category = CORRECTNESS,
    priority = 5,
    severity = Severity.WARNING,
    implementation = Implementation(
        LegacyDateNamingPatternDetector::class.java,
        EnumSet.of(Scope.JAVA_FILE, Scope.TEST_SOURCES)
    )
)
glorinli

glorinli commented on Jan 12, 2022

@glorinli

Same issue with AGP 7.0.3 and lint 30.0.3.

glorinli

glorinli commented on Jan 12, 2022

@glorinli

I figured out that in my case it's caused by the maven publish plugin since I used third party maven plugin and seems it doesn't work well with AGP 7.0.3.

It's ok when I switch to builtin maven-publish plugin.

apkelly

apkelly commented on Jan 13, 2022

@apkelly

I have the same problem, but I'm not using the maven-publish plugin at all, and I'm not publishing my lint checks via a library module, I'm just using them locally.

I am using kotlin for my build scripts, not groovy.....would that make a difference?

Android Studio Bumblebee | 2021.1.1 Beta 4
AGP=7.1.0-beta04
Lint=30.1.0-beta04

I've literally just included the code from this repo and have a Log.println() in my MainActivity which doesn't get highlighted when I run ./gradlew lintDebug or inside Android Studio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @tnorbye@androideveloper@apkelly@glorinli

        Issue actions

          lintChecks with AGP7 · Issue #56 · googlesamples/android-custom-lint-rules