在我的项目中,我想生成一个包含有关我的动态功能信息的类。动态功能以这种方式添加:
// In the base module’s build.gradle file.
android {
...
// Specifies dynamic feature modules that have a dependency on
// this base module.
dynamicFeatures = [":dynamic_feature", ":dynamic_feature2"]
}
来源:https ://developer.android.com/guide/app-bundle/at-install-delivery#base_feature_relationship
几天以来,我一直在寻找解决方案,但没有找到太多。目前,我的插件如下所示:
class MyPlugin : Plugin<Project> {
override fun apply(project: Project) {
if (project == rootProject) {
throw Exception("This plugin cannot be applied to root project")
}
val parent = project.parent ?: throw Exception("Parent of project cannot be null")
val extension = project.extensions.getByName("android") as BaseAppModuleExtension?
?: throw Exception("Android extension cannot be null")
extension.dynamicFeatures
}
}
不幸的是,即使我的插件应用于具有动态功能的 build.gradle 文件,extension.dynamicFeatures 也是空的。