我们有一个带有自定义 lint 检查的 Android 多模块项目,我们一直在尝试迁移到 Android gradle build tools 4.1.0,但 Android Studio 4.1.0 gradle sync 一直失败。
假设我们有两个模块(加上一些不相关的“库”模块):
app
(主应用模块)lintchecks
(自定义 lint 规则)
app
使用自定义lintchecks
模块,在app/build.gradle
:
lintChecks project(":lintchecks")
现在,假设有一些自定义插件(例如 in buildSrc
)或使用 和 组合的subprojects
配置tasks.whenTaskAdded
。例如,在./build.gradle
:
subprojects {
tasks.whenTaskAdded {
// content not important
}
}
配置没有什么特别之处lintcheck
。例如在lintchecks/build.gradle
:
apply plugin: 'kotlin'
dependencies {
compileOnly "com.android.tools.lint:lint-api:27.1.0"
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation "com.android.tools.lint:lint:27.1.0"
testImplementation "com.android.tools.lint:lint-tests:27.1.0"
testImplementation "com.android.tools:testutils:27.1.0"
}
jar {
manifest {
attributes("Lint-Registry-v2": "com.company.lintrules.IssueRegistry")
}
}
它在 Android Studio 同步上一直失败,错误类似于:
A problem occurred evaluating project ':lintrules'.
> Failed to apply plugin 'kotlin'.
> Gradle#projectsEvaluated(Action) on build 'MyCompanyBuild' cannot be executed in the current context.
总之
看来问题是Android Studio 4.1.0 + build gradle tools 4.1.0 ++的组合。lintCheck()
tasks.whenTaskAdded {}
我试过的
- 不同的插件
lintrules/build.xml
,例如maven-publish
,,org.jetbrains.kotlin.jvm
相同的错误结果 - 声明插件的不同方式,例如
plugins { id (...) }
vsapply plugin: '...'
,相同的错误结果 - 旧版本的 lint 依赖项
- 删除
lintCheck
,或删除tasks.whenTaskAdded
,或降级到 gradle 构建工具4.0.1
,其中任何一个都会使它再次工作 - 在终端上运行任何命令,在 Android Studio 之外,它工作正常,问题似乎只在 AS 同步操作上。
问题
其他人还有相同的疑问么?