103

I have a simple android project that I created with Android Studio 0.4.0. I use Gradle 1.9 and Gradle Android Plugin 0.7. Yesterday I've added Jake Wharton's ButterKnife library in my gradle build script:

dependencies {
            compile 'com.android.support:support-v4:19.0.0'
            compile 'com.android.support:appcompat-v7:19.0.0'

            // Butterknife
            compile 'com.jakewharton:butterknife:4.0.1'
}

When I run the application from Android Studio, the build runs fine and executes correctly on my devices. But when I try (from the command line) gradle build the build fails. Here is a part from my lint report:

InvalidPackage: Package not included in Android

/home/yami/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife/4.0.1/f43b36925363701633d01adb8e54df7150397a78/butterknife-4.0.1.jar: Invalid package reference in library; not included in Android: javax.annotation.processing. Referenced from butterknife.internal.InjectViewProcessor.
/home/yami/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife/4.0.1/f43b36925363701633d01adb8e54df7150397a78/butterknife-4.0.1.jar: Invalid package reference in library; not included in Android: javax.annotation.processing. Referenced from butterknife.internal.InjectViewProcessor.
/home/yami/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife/4.0.1/f43b36925363701633d01adb8e54df7150397a78/butterknife-4.0.1.jar: Invalid package reference in library; not included in Android: javax.annotation.processing. Referenced from butterknife.internal.InjectViewProcessor.
/home/yami/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife/4.0.1/f43b36925363701633d01adb8e54df7150397a78/butterknife-4.0.1.jar: Invalid package reference in library; not included in Android: javax.annotation.processing. Referenced from butterknife.internal.InjectViewProcessor.
/home/yami/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife/4.0.1/f43b36925363701633d01adb8e54df7150397a78/butterknife-4.0.1.jar: Invalid package reference in library; not included in Android: javax.annotation.processing. Referenced from butterknife.internal.InjectViewProcessor.

Maybe I'm missing something, but not to be able to build the project in the terminal blocks the possibility of CI for Android projects.

Any help would be great.

Carl Manaster
  • 39,912
  • 17
  • 102
  • 155
Serj Lotutovici
  • 4,370
  • 5
  • 32
  • 41

11 Answers11

146

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'
  }
}
Marek Sebera
  • 39,650
  • 37
  • 158
  • 244
  • 19
    If you want you can only disable the package check with `disable 'InvalidPackage'` – Calin Dec 20 '13 at 13:38
  • Is there a way to do this from the root build.gradle so that I don't have to fork a bunch of different submodules? – ankushg Dec 27 '13 at 22:08
  • 2
    @AnkushGupta you can put it in root `android{}` block of course – Marek Sebera Dec 29 '13 at 02:44
  • @MarekSebera Does that work if you have a number of Android libraries and an Android application? I didn't get it to work. Could you show an example on how? – riper Jan 21 '14 at 09:32
  • @riper it may be necessary to put the `lintOptions` in the libraries, but it should work if you put this into root `android` block, try creating separate question, if it doesn't work for you somehow. – Marek Sebera Jan 21 '14 at 11:20
  • I disagree with the comments you put above the `enable` and `disable` options. What I understand from your comments is that they FORCE to enable JUST the listed rules and actually ENABLE all checks except for the ones you explicitly DISABLE. That would be pretty limiting, I believe these features work more like on/off flags, don't they? – acrespo Nov 03 '15 at 15:42
  • my build.gradle already has below code. lintOptions { abortOnError false } still it fails. Also tried with checkReleaseBuilds, disable options in build.gradle etc. but no luck. – Nik Jan 09 '18 at 09:26
57

if abortOnError false will not resolve your problem, you can try this.

lintOptions {
    checkReleaseBuilds false
}
Marek Sebera
  • 39,650
  • 37
  • 158
  • 244
panwy
  • 628
  • 5
  • 4
49

You can select proper options from here

android {
    lintOptions {
        // set to true to turn off analysis progress reporting by lint
        quiet true
        // if true, stop the gradle build if errors are found
        abortOnError false
        // if true, only report errors
        ignoreWarnings true
        // if true, emit full/absolute paths to files with errors (true by default)
        //absolutePaths true
        // if true, check all issues, including those that are off by default
        checkAllWarnings true
        // if true, treat all warnings as errors
        warningsAsErrors true
        // turn off checking the given issue id's
        disable 'TypographyFractions','TypographyQuotes'
        // turn on the given issue id's
        enable 'RtlHardcoded','RtlCompat', 'RtlEnabled'
        // check *only* the given issue id's
        check 'NewApi', 'InlinedApi'
        // if true, don't include source code lines in the error output
        noLines true
        // if true, show all locations for an error, do not truncate lists, etc.
        showAll true
        // Fallback lint configuration (default severities, etc.)
        lintConfig file("default-lint.xml")
        // if true, generate a text report of issues (false by default)
        textReport true
        // location to write the output; can be a file or 'stdout'
        textOutput 'stdout'
        // if true, generate an XML report for use by for example Jenkins
        xmlReport false
        // file to write report to (if not specified, defaults to lint-results.xml)
        xmlOutput file("lint-report.xml")
        // if true, generate an HTML report (with issue explanations, sourcecode, etc)
        htmlReport true
        // optional path to report (default will be lint-results.html in the builddir)
        htmlOutput file("lint-report.html")

        // set to true to have all release builds run lint on issues with severity=fatal
        // and abort the build (controlled by abortOnError above) if fatal issues are found
        checkReleaseBuilds true
        // Set the severity of the given issues to fatal (which means they will be
        // checked during release builds (even if the lint target is not included)
        fatal 'NewApi', 'InlineApi'
        // Set the severity of the given issues to error
        error 'Wakelock', 'TextViewEdits'
        // Set the severity of the given issues to warning
        warning 'ResourceAsColor'
        // Set the severity of the given issues to ignore (same as disabling the check)
        ignore 'TypographyQuotes'
    }
}
Biswajit Karmakar
  • 9,799
  • 4
  • 39
  • 41
15

I had some lint errors in Android Studio that occurred only when I generated a signed APK.

To avoid it, I added the following to build.gradle

android {
    lintOptions {
        checkReleaseBuilds false
    }
}
Erik Ghonyan
  • 427
  • 4
  • 12
Asaf Pinhassi
  • 15,177
  • 12
  • 106
  • 130
11

Add these lines to your build.gradle file:

android { 
  lintOptions { 
    abortOnError false 
  }
}

Then clean your project :D

jheimbouch
  • 969
  • 8
  • 20
Muhamet Aljobairi
  • 1,627
  • 4
  • 19
  • 25
8

If you want avoid the "abortInError false" option, take a look at build/lint-results-release-fatal.html file. Here are the erros detected by lint.

I hope this can help somebody!

Daniel S.
  • 2,629
  • 2
  • 21
  • 19
4

In Android Studio v1.2, it tells you how to fix it:

enter image description here

Allen
  • 6,745
  • 5
  • 41
  • 59
3

Got same error on AndroidStudio version 0.51

Build was working fine and suddenly, after only changing the version code value, I got a Lint related build error.

Tried to change build.gradle, cleared AndroidStudio cache and restart, but no change.

Finally I returned to original code (causing the error), and removed android:debuggable="false" from AndroidManifest.xml, causing the build to succeed.

I added it again and it still works... Don't ask me why :S

Cedric Simon
  • 4,571
  • 4
  • 40
  • 52
3

As for me, it's a bad and quick solution for your problem :

android { 
  lintOptions { 
    abortOnError false 
  }
}

Better solution is solving problem in your code, because lint tool checks your Android project source files for potential bugs and optimization improvements for correctness, security, performance, usability, accessibility, and internationalization.

This problem most frequently occurring when:

  • Layout include unresolved symbols or missing some attribute
  • Other structural issues, such as use of deprecated elements or API calls that are not supported by the target API versions, might lead to code failing to run correctly.

Find your bugs by Inspect Code in Android Studio: Improve Your Code with Lint

Dmytro Melnychuk
  • 2,285
  • 21
  • 23
  • 1
    Thanks for pointing out the opposite of a **bad and quick** solution. I've discovered a lot of issues on the report generated by _lint_ available at `Application/build/reports/lint-results.html`. The report is very detailed and helpful. – jgrocha Dec 18 '17 at 23:58
1

Add

android.lintOptions.abortOnError false

to your app\build.gradle

Mpak
  • 26
  • 2
0

If you set abortOnError false, you will see a warning:

Cannot access 'abortOnError': it is private in 'LintOptions'

enter image description here

Thanks to erluxman you can simply press Ctrl+Space on empty space inside lintOptions {} block to see properties and write:

lintOptions {
    // if true, stop the gradle build if errors are found
    isAbortOnError = false
    // if true, show all locations for an error, do not truncate lists, etc.
    isShowAll = true
}
CoolMind
  • 26,736
  • 15
  • 188
  • 224