我已经编写了一个基于Android插件的Gradle插件:对于每个变体,插件定义了一个任务generate variant Stuff,它生成一个资产,我需要merge变量Assets(由AGP定义)将我的资产作为输入,因此merge变体Assets任务必须依赖于我的generate变体Stuff任务。
我的插件与AGP 4.2.2一起正常工作。
AGP 7.0.0不赞成com.android.build.gradle.api.ApplicationVariant,代之以com.android.build.api.variant.ApplicationVariant,因此我还必须用com.android.build.api.variant.ApplicationAndroidComponentsExtension替换com.android.build.gradle.AppExtension,并替换变体上的循环。现在,当Android构建模型时,会出现以下错误:
A problem occurred configuring project ':app'.
> Task with name 'mergeDebugAssets' not found in project ':app'.但是在Android的Gradle视图中,a可以看到mergeDebugAssets任务。
似乎在方法AppExtension.getApplicationVariants().all() (AGP 4.2.2)期间,AGP已经定义了它的任务,而在方法ApplicationAndroidComponentsExtension.onVariants() (AGP 7.0.0)期间,AGP还没有定义它的任务。
您可以在https://gist.github.com/dscoppelletti/d4ca0e1a19ed4ba4aaea99cf48ae930a上看到示例代码
任何帮助都是非常感谢的。
发布于 2021-08-06 12:34:11
我也有类似的问题。我有一个聚合任务,它从每个变体收集工件并将它们复制到给定的路径,但是在ApplicationAndroidComponentsExtension.onVariants()期间无法为变体组装任务。
https://stackoverflow.com/questions/68657155
复制相似问题