JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.11k stars 1.17k forks source link

[Component.Resources] Generating an APK throws error due to task dependency implication #4085

Closed yuroyami closed 8 months ago

yuroyami commented 9 months ago

Kotiln: 2.0.0-Beta1 and 1.9.21 Compose version: 1.6.0-dev1350

When I try to release an APK from my project, two tasks throw an error, both of which say that "they use output from this task :shared:copyFontsToAndroidAssets without declaring an explicit or implicit dependency".

These two tasks are: :shared:generateReleaseLintVitalModel and :shared:lintVitalAnalyzeRelease

The stacktrace:

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
A problem was found with the configuration of task ':shared:generateReleaseLintVitalModel' (type 'LintModelWriterTask').
  - Gradle detected a problem with the following location: '/Users/mac/WORKSTATION/SyncplayMobile/shared/build/generated/compose/resourceGenerator/androidFonts'.

    Reason: Task ':shared:generateReleaseLintVitalModel' uses this output of task ':shared:copyFontsToAndroidAssets' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

    Possible solutions:
      1. Declare task ':shared:copyFontsToAndroidAssets' as an input of ':shared:generateReleaseLintVitalModel'.
      2. Declare an explicit dependency on ':shared:copyFontsToAndroidAssets' from ':shared:generateReleaseLintVitalModel' using Task#dependsOn.
      3. Declare an explicit dependency on ':shared:copyFontsToAndroidAssets' from ':shared:generateReleaseLintVitalModel' using Task#mustRunAfter.

    For more information, please refer to https://docs.gradle.org/8.5/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem was found with the configuration of task ':shared:lintVitalAnalyzeRelease' (type 'AndroidLintAnalysisTask').
  - Gradle detected a problem with the following location: '/Users/mac/WORKSTATION/SyncplayMobile/shared/build/generated/compose/resourceGenerator/androidFonts'.

    Reason: Task ':shared:lintVitalAnalyzeRelease' uses this output of task ':shared:copyFontsToAndroidAssets' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

    Possible solutions:
      1. Declare task ':shared:copyFontsToAndroidAssets' as an input of ':shared:lintVitalAnalyzeRelease'.
      2. Declare an explicit dependency on ':shared:copyFontsToAndroidAssets' from ':shared:lintVitalAnalyzeRelease' using Task#dependsOn.
      3. Declare an explicit dependency on ':shared:copyFontsToAndroidAssets' from ':shared:lintVitalAnalyzeRelease' using Task#mustRunAfter.

    For more information, please refer to https://docs.gradle.org/8.5/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
==============================================================================
yuroyami commented 9 months ago

As a workaround, adding this to my shared module's build.gradle.kts would resolve the issue:

tasks.withType<AndroidLintAnalysisTask>{
    dependsOn("copyFontsToAndroidAssets")
}

tasks.withType<LintModelWriterTask>{
    dependsOn("copyFontsToAndroidAssets")
}

This might be a Gradle plugin/wrapper incompatibility though. I am still not sure. I am using Gradle 8.5 and AGP 8.2.0.

eymar commented 9 months ago

Could you please provide a minimal reproducer project?

Have you tried other gradle and AGP versions?

These two tasks are: :shared:generateReleaseLintVitalModel and :shared:lintVitalAnalyzeRelease

These two tasks are not added by Compose Multiplatform. I guess they're added by AGP. So I think it's worth trying with different AGP versions.

eskatos commented 8 months ago

It looks to me this is related with the new resources in 1.6.0

Gradle detected a problem with the following location: '/path/to/project/build/generated/compose/resourceGenerator/androidFonts'.
arkivanov commented 8 months ago

I've also encountered this. Steps to reproduce:

  1. Generate a new project using the KMP Wizard
  2. Update compose-plugin dependency from 1.6.0-alpha01 to 1.6.0-beta01
  3. Run ./gradlew :composeApp:build

It fails with:

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':composeApp:lintVitalAnalyzeRelease' (type 'AndroidLintAnalysisTask').
  - Gradle detected a problem with the following location: '/Users/arkivanov/Downloads/Miner/composeApp/build/generated/compose/resourceGenerator/androidFonts'.

    Reason: Task ':composeApp:lintVitalAnalyzeRelease' uses this output of task ':composeApp:copyFontsToAndroidAssets' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

    Possible solutions:
      1. Declare task ':composeApp:copyFontsToAndroidAssets' as an input of ':composeApp:lintVitalAnalyzeRelease'.
      2. Declare an explicit dependency on ':composeApp:copyFontsToAndroidAssets' from ':composeApp:lintVitalAnalyzeRelease' using Task#dependsOn.
      3. Declare an explicit dependency on ':composeApp:copyFontsToAndroidAssets' from ':composeApp:lintVitalAnalyzeRelease' using Task#mustRunAfter.

    For more information, please refer to https://docs.gradle.org/8.4/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.

If I updated AGP from 8.1.4 to 8.2.2, then the build fails with:

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':composeApp:generateReleaseLintVitalReportModel' (type 'LintModelWriterTask').
  - Gradle detected a problem with the following location: '/Users/arkivanov/Downloads/Miner/composeApp/build/generated/compose/resourceGenerator/androidFonts'.

    Reason: Task ':composeApp:generateReleaseLintVitalReportModel' uses this output of task ':composeApp:copyFontsToAndroidAssets' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

    Possible solutions:
      1. Declare task ':composeApp:copyFontsToAndroidAssets' as an input of ':composeApp:generateReleaseLintVitalReportModel'.
      2. Declare an explicit dependency on ':composeApp:copyFontsToAndroidAssets' from ':composeApp:generateReleaseLintVitalReportModel' using Task#dependsOn.
      3. Declare an explicit dependency on ':composeApp:copyFontsToAndroidAssets' from ':composeApp:generateReleaseLintVitalReportModel' using Task#mustRunAfter.

    For more information, please refer to https://docs.gradle.org/8.4/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.
alpine12 commented 8 months ago

As a workaround, adding this to my shared module's build.gradle.kts would resolve the issue:

tasks.withType<AndroidLintAnalysisTask>{
    dependsOn("copyFontsToAndroidAssets")
}

tasks.withType<LintModelWriterTask>{
    dependsOn("copyFontsToAndroidAssets")
}

This might be a Gradle plugin/wrapper incompatibility though. I am still not sure. I am using Gradle 8.5 and AGP 8.2.0.

This saved me from errors after updating to version 1.6.0-beta01.

terrakok commented 8 months ago

https://github.com/JetBrains/compose-multiplatform/pull/4247

skolson commented 8 months ago

In case this is helpful, I'm also seeing this, on release builds only, using these:

Project uses the composeResources support for a few drawables (PNG images). In this project all the compose multiplatform code is in a separate module named "uiCommon". There are 4 other modules in the project, and only the uiCommon module gets these gradle errors that make release builds fail. The gradle errors displayed all suggest the gradle task dependencies below are required and are missing (I'm cherry-picking from the output):

A problem was found with the configuration of task ':uiCommon:generateReleaseLintModel' (type 'LintModelWriterTask').
      1. Declare task ':uiCommon:copyFontsToAndroidAssets' as an input of ':uiCommon:generateReleaseLintModel'.

A problem was found with the configuration of task ':uiCommon:lintVitalAnalyzeRelease' (type 'AndroidLintAnalysisTask').
      1. Declare task ':uiCommon:copyFontsToAndroidAssets' as an input of ':uiCommon:lintVitalAnalyzeRelease'.

A problem was found with the configuration of task ':uiCommon:generateReleaseLintVitalModel' (type 'LintModelWriterTask').
      1. Declare task ':uiCommon:copyFontsToAndroidAssets' as an input of ':uiCommon:generateReleaseLintVitalModel'.

So it looks like at a minimum tasks generateReleaseLintVitalModel, lintVitalAnalyzeRelease, and generateReleaseLintModel all need task copyFontsToAndroidAssets as an input or an explicit dependency.

skolson commented 8 months ago

Oh, and I forgot to mention I can confirm that the same work-around from alpine12 also fixes my build.

terrakok commented 8 months ago

https://github.com/JetBrains/compose-multiplatform/pull/4247

Junzz0 commented 3 months ago

gradle = gradle-8.8-all.zip androidGradlePlugin = "8.2.0" composeMultiplatform = "1.7.0-dev1698" kotlin = "2.0.0"

Still having the same issue.

Because IDEA 2024.1.4 only supports 8.2.0, AGP cannot be upgraded temporarily.

@terrakok

Junzz0 commented 3 months ago

If I need to upgrade AGP, then I need to wait for 2024.2 to be released.

https://www.jetbrains.com/idea/nextversion/

okushnikov commented 1 month ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.