There is an gradle plugin in my submodule. This plugin will generate some files in the afterEvaluate callback and put them in the assets folder. The main project will package these files into the apk when compiling. These codes work when using gradle 7.5 and agp 7.4.2.
When I upgrade gradle to 8.0+, agp to 8.2.2 and compile again, the log shows:
Reason: Task ‘:app:mergeProductFreeDebugAssets’ uses this output of task ‘:app:costomTask’ without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
Where ‘Product’ and ‘free’ are my productFlavors. So mergeProductFreeDebugAssets is a predefined task of agp.
I tried to set the dependencies between tasks in buildSrc. However, the following two methods cannot be compiled and still report the above error.
project.getGradle().getTaskGraph().whenReady(taskGraph -> {
mergeProductFreeDebugAssets.dependsOn(costomTaskName);
});
project.afterEvaluate(p -> {
mergeProductFreeDebugAssets.dependsOn(costomTaskName);
});
I modified the plugin code of the submodule to generate those files in the apply function instead of in the afterEvaluate callback. And set the dependencies between tasks in buildSrc. Then I recompiled the main project, and this time it compiled and installed normally.
Is there any way to compile normally without modifying the submodule plugin, just modify the main project buildSrc code?