Skip to content

Android: Add failOnWarnings check to android build.gradle and configure lint as warnings as error #12040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
18 changes: 17 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ android {
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions { abortOnError true }

// fail on android lint warnings if failOnWarning is set true
lintOptions {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are doing this anyway, lintOptions is deprecated. Use lint instead. (Wait for Eric's comment on this before working)

abortOnError true
if (rootProject.hasProperty("failOnWarnings") && rootProject.failOnWarnings.toBoolean()) {
warningsAsErrors true
}
}

publishing {
singleVariant('release') {
withSourcesJar()
Expand All @@ -44,6 +52,14 @@ dependencies {
testImplementation libraries.truth
}

// Enforce -Werror on java compiler if failOnWarning is set
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may remove the comments as they are self explanatory.

tasks.withType(JavaCompile).configureEach {
it.options.compilerArgs += ["-Xlint:all"]
if (rootProject.hasProperty("failOnWarnings") && rootProject.failOnWarnings.toBoolean()) {
it.options.compilerArgs += ["-Werror"]
}
}

tasks.register("javadocs", Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.getBootClasspath())
Expand Down