Setting LINT_API_DATABASE

117 views
Skip to first unread message

César Puerta

unread,
Nov 23, 2021, 12:48:16 PM11/23/21
to lint-dev
I'd like to configure the API database explicitly for the following reasons:

* Enable ApiDetector in Java projects.
* Guarantee the use of a consistent API database by checking it into the repo (since the platform tools it's distributed with are not versioned).

As far as I can tell, the only way to do this is to set the LINT_API_DATABASE environment variable or system property. I tried setting the systemProp.LINT_API_DATABASE in my root gradle.properties, but the relative path is not resolved correctly. The alternative is to go with something like this, which is.. not ideal:

tasks.withType<AndroidLintTask>().configureEach {
    val lintApiDatabasePath = project.rootProject.layout.projectDirectory.file("config/lint/api-database.xml").asFile.absolutePath
    doFirstAction {
        System.setProperty("LINT_API_DATABASE", lintApiDatabasePath)
    }
}

Is there  better way to do this? Would it make sense to make this configurable through a file option for {{ApiDetector}} in {{lint.xml}}?

Thanks,
César

Tor Norbye

unread,
Nov 24, 2021, 2:34:03 PM11/24/21
to lint-dev
On Tuesday, November 23, 2021 at 9:48:16 AM UTC-8 cesa...@gmail.com wrote:
I'd like to configure the API database explicitly for the following reasons:

* Enable ApiDetector in Java projects.

For Java projects that are intended to be consumed in Android projects I assume. We've been talking about adding some additional flags to the lintOptions DSL used by the standalone Gradle plugin to let you for example set minSdkVersion, and arguably we should let you set compileSdkVersion too, and these would be used by the standalone lint Gradle plugin to infer that this is Android-targeted Java code and to include the various Android-specific lint checks. E
 
* Guarantee the use of a consistent API database by checking it into the repo (since the platform tools it's distributed with are not versioned).

Initially, the API database was distributed with the platform-tools which is not versioned, but several years ago (Android O I think, 2017) we started including it with the platform itself, and the platform-tools distribution is only a fallback.

So if you for example have "compileSdkVersion 26" it should be using $ANDROID_HOME/platforms/android-26/data/api-versions.xml.

(Technically there can be revisions of the platforms, but these really shouldn't be touching the API surface without bumping the API level.)

As far as I can tell, the only way to do this is to set the LINT_API_DATABASE environment variable or system property. I tried setting the systemProp.LINT_API_DATABASE in my root gradle.properties, but the relative path is not resolved correctly. The alternative is to go with something like this, which is.. not ideal:
 

tasks.withType<AndroidLintTask>().configureEach {
    val lintApiDatabasePath = project.rootProject.layout.projectDirectory.file("config/lint/api-database.xml").asFile.absolutePath
    doFirstAction {
        System.setProperty("LINT_API_DATABASE", lintApiDatabasePath)
    }
}

Is there  better way to do this? Would it make sense to make this configurable through a file option for {{ApiDetector}} in {{lint.xml}}?

Correct, it's currently only configurable via system properties and environment variables. Re: the gradle.properties question -- I don't know this really well; I think Gradle tries to isolate the environment a bit, but there may be something you have to do to expose it. Maybe try asking the Gradle people on slack. I'm not sure it makes a lot of sense to make this configurable; it's a pretty niche thing (maybe the above explanation that it should no longer be dependent on platform-tools helps) ? The primary usecase for making it configurable right now is that we use it when we run lint directly on the Android platform source code itself where there isn't a public SDK to point it to.

-- Tor

Reply all
Reply to author
Forward
0 new messages