如何在多项目目录顶层的Android Gradle Plugin中禁用lint abortOnError

前端之家收集整理的这篇文章主要介绍了如何在多项目目录顶层的Android Gradle Plugin中禁用lint abortOnError前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个顶级的 Android Gradle项目.这个项目下面嵌套了多个子项目(有时它们是2级深),即:
top level project
   |
project1

vendor libraries
      |
     lib1

     lib2

lint正在中断一些图书馆项目的建设.我可以编辑每个图书馆项目的build.gradle来解决问题

android {
   lintOptions {
      abortOnError false
   }
}

但是,我更喜欢在顶级build.gradle脚本中的以下代码

subprojects {

    afterEvaluate {
        if (getPlugins().hasPlugin('android') ||
            getPlugins().hasPlugin('android-library')) {

            println name // for debugging

            android {
                lintOptions {
                    abortOnError false
                }
            }
        }

    }
}

条件语句确保仅使用Android插件挂接到项目中.我只能使用afterEvaluate来工作.但是,我的构建仍然是失败的lint错误.

有谁有一个干净的解决方案从顶层注入这些设置?

更新:

重新安排子项目,并在评估或使用所有项目后仍然会产生相同的以下错误

7: Task Failed with an exception.
-----------
* What went wrong:
Execution Failed for task ':3rdparty:OrmLiteQueryBuilder:lint'.
> [Ljava/util/HashMap$Entry;

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

BUILD Failed

Total time: 40.528 secs

堆栈跟踪:

7: Task Failed with an exception.
-----------
* What went wrong:
Execution Failed for task ':3rdparty:OrmLiteQueryBuilder:lint'.
> [Ljava/util/HashMap$Entry;

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

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution Failed for task ':3rdparty:OrmLiteQueryBuilder:lint'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:286)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
        at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
Caused by: java.lang.NoClassDefFoundError: [Ljava/util/HashMap$Entry;
        at com.android.build.gradle.internal.dsl.LintOptionsImpl$1.$getStaticMetaClass(LintOptionsImpl.groovy)
        at com.android.build.gradle.internal.dsl.LintOptionsImpl$1.<init>(LintOptionsImpl.groovy)
        at com.android.build.gradle.internal.dsl.LintOptionsImpl.syncTo(LintOptionsImpl.groovy:450)
        at com.android.build.gradle.internal.dsl.LintOptionsImpl$syncTo.call(Unknown Source)
        at com.android.build.gradle.tasks.Lint.lintAllVariants(Lint.groovy:105)
        at com.android.build.gradle.tasks.Lint$lintAllVariants.callCurrent(Unknown Source)
        at com.android.build.gradle.tasks.Lint.lint(Lint.groovy:63)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:219)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:212)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:201)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:530)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:513)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
        ... 13 more
Caused by: java.lang.ClassNotFoundException: java.util.HashMap$Entry
        ... 28 more

==============================================================================

BUILD Failed

Total time: 2 mins 20.757 secs

我可以使用-x lint选项成功运行gradle构建,但是希望在不使用命令行选项的情况下进行构建.

解决方法

我也面临类似的情况,而不是直接修改DSL,而是在其上调用configure:
configure(android.lintOptions) {
    abortOnError false
}

因此,我能够为我想要的子项目禁用abortOnError.底线,您的子项目块应如下所示:

subprojects {

    afterEvaluate {
        if (getPlugins().hasPlugin('android') ||
            getPlugins().hasPlugin('android-library')) {

            println name // for debugging

            configure(android.lintOptions) {
                abortOnError false
            }
        }

    }
}
原文链接:https://www.f2er.com/android/311850.html

猜你在找的Android相关文章