如何只为项目库启用lint检查?

时间:2018-02-26 08:51:17

标签: android gradle lint

我的项目包含许多模块,我想为其中一些模块启用静态代码分析。因此我做了以下测试,但失败了。下面是我的图书馆的build.gradle。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.hp.myapplication"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError true
        ignoreWarnings false
        checkReleaseBuilds true
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile project(':mylibrary')

}

以下是我应用的build.gradle。

hpdeMac-Pro:MyApplication hp$ ./gradlew mylibrary:lint

> Configure project :app
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.

> Task :mylibrary:lint
Ran lint on variant release: 2 issues found
Ran lint on variant debug: 2 issues found
Wrote HTML report to file:///Users/hp/Downloads/MyApplication/mylibrary/build/reports/lint-results.html
Wrote XML report to file:///Users/hp/Downloads/MyApplication/mylibrary/build/reports/lint-results.xml


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':mylibrary:lint'.
> Lint found errors in the project; aborting build.

  Fix the issues identified by lint, or add the following to your build script to proceed with errors:
  ...
  android {
      lintOptions {
          abortOnError false
      }
  }
  ...

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
23 actionable tasks: 7 executed, 16 up-to-date
hpdeMac-Pro:MyApplication hp$ ./gradlew assembleRelease

> Configure project :app
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.


BUILD SUCCESSFUL in 0s
51 actionable tasks: 1 executed, 50 up-to-date
hpdeMac-Pro:MyApplication hp$ 

我在我的库中添加了一个lint错误,下面是mylibrary lint和./gradlew assembleRelease result

{{1}}

您想解释为什么./gradlew assembleRelease无法找到lint错误以及如何仅为模块启用静态代码检查?非常感谢。

0 个答案:

没有答案