gradle build fails on lint task
With 0.7.0 there comes extended support for Lint, however, it does not work always properly. (Eg. the butterknife library)
Solution is to disable aborting build on found lint errors
I took the inspiration from
https://android.googlesource.com/platform/tools/base/+/e6a5b9c7c1bca4da402de442315b5ff1ada819c7
(implementation:
https://android.googlesource.com/platform/tools/base/+/e6a5b9c7c1bca4da402de442315b5ff1ada819c7/build-system/gradle/src/main/groovy/com/android/build/gradle/internal/model/DefaultAndroidProject.java )
(discussion: https://plus.google.com/+AndroidDevelopers/posts/ersS6fMLxw1 )
android {
// your build config
defaultConfig { ... }
signingConfigs { ... }
compileOptions { ... }
buildTypes { ... }
// This is important, it will run lint checks but won't abort build
lintOptions {
abortOnError false
}
}
And if you need to disable just particular Lint rule and keep the build failing on others, use this:
/*
* Use only 'disable' or only 'enable', those configurations exclude each other
*/
android {
lintOptions {
// use this line to check all rules except those listed
disable 'RuleToDisable', 'SecondRuleToDisable'
// use this line to check just listed rules
enable 'FirstRuleToCheck', 'LastRuleToCheck'
}
}
Gradle build: Execution failed for task ':app:lint'
Add this in your app/build.gradle
file
android {
//...
lintOptions {
abortOnError false
}
}
How to make Android Studio build fail on lint errors
If there's a lint check for that you can change the severity to FATAL
and then when building the release version of your APK it should fail.
android {
lintOptions {
fatal 'MY_LINT_CHECK_ID'
}
}
Also you can execute the Gradle lint
task which will fail. If you also want warnings to let your build fail you can use this.
android {
lintOptions {
warningsAsErrors true
}
}
Gradle build fails due to lint classpath error on Android
I have figured out what the problem is. I use the build parameter 'dev' (Pbuild=dev
) to make sure that the CI (Travis, in this case) uses the mock version of my google-services.json
file placed in the app/src/dev
folder. However, I forgot to configure the 'dev' build variant in the build.gradle files of my modules.
Solution is to add the dev
build type in all modules, like this:
build.gradle
android {
...
buildTypes {
release {
...
}
debug {
...
}
dev {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Please note that you will have to do this for all the modules in your project.
Gradle build tools 4.1.0 failing sync in Android Studio when there is a lintCheck dependency
This problem is being reported under ticket https://issuetracker.google.com/issues/170656529
The way to workaround this for now is to skip the logic causing issues on the IDE testing for idea.active
system property:
if(System.getProperty("idea.active") != "true"){
tasks.whenTaskAdded {
(...)
}
}
(Thanks Jerry for finding the ticket)
How to make Grade release build fail using Lint Option StopShip?
I finally cracked it! fatal 'StopShip'
. That's what finally did it! Leaving my discovery in case it helps anyone.
Replacing error 'StopShip'
with fatal 'StopShip'
in my build.gradle
config solved the problem.
I don't fully understand why my previous attempts with error 'StopShip'
didn't work, as the abortOnError docs clearly state:
Whether lint should set the exit code of the process if errors are found
and I was marking the StopShip
check severity as error. It looks like abortOnError
will only make the Gradle build abort for FATAL errors. Can anyone confirm?
Of course, if it anyone offers a better solution/explanation, please do share.
Android Studio: Adding Kotlin to existing Java app ends up in Internal error: unexpected lint return value -1 when building
OK, don't know why, but after removing
apply plugin: 'kotlin-android'
from my 'Core' and 'Global' modules build.gradle now the app builds successfully.
I don't know why the other modules accept the apply plugin: 'kotlin-android' in build.gradle and not 'Core' and 'Global' and I don't even know if I'll be able to use Kotlin in those two modules then, but for the moment the app builds just fine.
Related Topics
Write Android Logcat Data to a File
Getapplicationcontext(), Getbasecontext(), Getapplication(), Getparent()
Android Speech Recognition Continuous Service
How to Include a Username When Storing Email and Password Using Firebase (Baas) in an Android App
How to Open a PDF Stored Either in Res/Raw or Assets Folder
Android: How to Make Keyboard Enter Button Say "Search" and Handle Its Click
Viewpager in a Nestedscrollview
How to Share a Single Library Source Across Multiple Projects
Gradle Version 2.2 Is Required. Current Version Is 2.10
Android + Pair Devices via Bluetooth Programmatically
How to Use Getsharedpreferences in Android
Why Do I Get Com.Google.Android.Gms.Common.Api.Apiexception: 10:
Error Message:This Android Sdk Requires Android Developer Toolkit Version 22.6.1 or Above
How to Sign an APK with More Than One Certificate
Override Android Backbutton Behavior Only Works on the First Page with Phonegap
How to Synchronise Projects to Github with Android Studio
How to Use Autocompletetextview and Populate It with Data from a Web API