gpt4 book ai didi

android - 如何从多项目目录的顶层禁用 Android Gradle 插件中的 lint abortOnError

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:40:07 25 4
gpt4 key购买 nike

我有一个顶级 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 错误而失败。

有没有人有一个干净的解决方案来从顶层注入(inject)这些设置?

更新:

重新排列子项目和 afterEvaluate 或使用 allprojects 仍然会出现以下相同类型的错误:

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 build,但我想在不使用命令行选项的情况下进行构建。

最佳答案

我也遇到过类似的情况,但我没有直接修改 DSL,而是调用了configure:

configure(android.lintOptions) {
abortOnError false
}

因此,我能够为我想要的子项目禁用 abortOnError。最重要的是,您的 subproject block 应该如下所示:

subprojects {

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

println name // for debugging

configure(android.lintOptions) {
abortOnError false
}
}

}
}

关于android - 如何从多项目目录的顶层禁用 Android Gradle 插件中的 lint abortOnError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24420391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com