gpt4 book ai didi

android - 如何将显式 API 模式应用于除 app 模块之外的所有模块?

转载 作者:行者123 更新时间:2023-12-03 04:54:04 25 4
gpt4 key购买 nike

我喜欢申请 explicit API modethis Android project 中的所有模块除了 app模块。通过将以下配置添加到每个模块的 build.gradle 文件中,这可以正常工作。

// build.gradle of a module

kotlin {
explicitApi()
}
但是我喜欢避免使用 重复 宣言。因此,我的目标是在 中的 build.gradle 文件中配置它。项目根目录 .我尝试了以下方法:
// build.gradle in project root

allprojects {
apply plugin: "kotlin"
kotlin {
if (project.name != "app") {
explicitApi()
}
}
}
这与模块中的插件定义冲突:

Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin 'kotlin-android'.
Caused by: java.lang.IllegalArgumentException: Cannot add extension with name 'kotlin', as there is an extension already registered with that name.
Caused by: com.android.build.gradle.internal.BadPluginException: The 'java' plugin has been applied, but it is not compatible with the Android plugins.


有关的
  • Gradle Multi Module Project: Apply module dependency to all subprojects except for itself
  • 最佳答案

    您的 build.gradle在子项目应用 Android 插件之前将 Kotlin 插件应用到子项目,这不起作用 - 它需要反过来。
    尝试将操作推迟到评估项目之后,例如

    gradle.afterProject { project ->
    if (project.name == "app") return
    project.extensions.findByName("kotlin")?.explicitApi()
    }

    关于android - 如何将显式 API 模式应用于除 app 模块之外的所有模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64451067/

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