Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build failure on iOS #141

Open
mipastgt opened this issue Jan 16, 2025 · 10 comments
Open

Build failure on iOS #141

mipastgt opened this issue Jan 16, 2025 · 10 comments

Comments

@mipastgt
Copy link

I am using your plugin/library in commonTest to read in some resource file text. This works nicely for desktop and Android but fails at build time for iOS. The message is:

FAILURE: Build failed with an exception.
* What went wrong:
A problem was found with the configuration of task ':composeApp:assembleIosX64TestResources' (type 'AssembleTargetResourcesTask').
  - Gradle detected a problem with the following location: '/Users/mpaus/Projects/tmp/KotlinWasmBridgeDemo/composeApp/build/generated/compose/resourceGenerator/assembledResources/iosX64Test'.
    
    Reason: Task ':composeApp:copyResourcesDebugTestIosX64' uses this output of task ':composeApp:assembleIosX64TestResources' 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:assembleIosX64TestResources' as an input of ':composeApp:copyResourcesDebugTestIosX64'.
      2. Declare an explicit dependency on ':composeApp:assembleIosX64TestResources' from ':composeApp:copyResourcesDebugTestIosX64' using Task#dependsOn.
      3. Declare an explicit dependency on ':composeApp:assembleIosX64TestResources' from ':composeApp:copyResourcesDebugTestIosX64' using Task#mustRunAfter.
    
    For more information, please refer to https://docs.gradle.org/8.11.1/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.

I guess this should work without any extra steps on my side for iOS.

@goncalossilva
Copy link
Owner

Hey @mipastgt, thanks for the report! You're right that this should work without any extra steps on iOS. There is something about that particular environment that is breaking the build. Is this an OSS project that I can try running myself?

@mipastgt
Copy link
Author

This is not an OSS project but I can try to create a little reproducer.

@goncalossilva
Copy link
Owner

Thanks! I'd be happy to dig in if you do.

@mipastgt
Copy link
Author

I tried to set up a simple example but I could not reproduce the error with that. So I send you an example with a slightly more complex project setup which I derived from my original project and there the error can be reproduced.
The project has one test in KotlinWasmBridgeDemo/composeApp/src/commonTest/kotlin/de/mpmediasoft/wasm/KotlinWasmChasmTest.kt. This test builds and runs without problems on desktop and Android but fails to build on iOS.

KotlinWasmBridgeDemo.zip

I hope this helps. The other code in there should not be relevant for this problem because the test only uses your lib. I assume the problem is related to the general project setup which is actually pretty standard. The only difference is that I have configured a jvmCommon source set, but this should also not be relevant because it is not used for the test in question.

@goncalossilva
Copy link
Owner

Great, thank you for this! I can't have a look at this right away but I'll block time next week.

@goncalossilva
Copy link
Owner

Unfortunately, I haven't been able to run the demo. Gradle is unable to sync due to:

Execution failed for task ':composeApp:compileKotlinDesktop'.
> Could not resolve all files for configuration ':composeApp:desktopCompileClasspath'.
   > Could not find de.mpmediasoft.apptools:apptools-core:1.0.0-SNAPSHOT.
     Searched in the following locations:
       - file:/Users/goncalossilva/.m2/repository/de/mpmediasoft/apptools/apptools-core/1.0.0-SNAPSHOT/maven-metadata.xml
       - file:/Users/goncalossilva/.m2/repository/de/mpmediasoft/apptools/apptools-core/1.0.0-SNAPSHOT/apptools-core-1.0.0-SNAPSHOT.pom
       - https://repo.maven.apache.org/maven2/de/mpmediasoft/apptools/apptools-core/1.0.0-SNAPSHOT/maven-metadata.xml
       - https://repo.maven.apache.org/maven2/de/mpmediasoft/apptools/apptools-core/1.0.0-SNAPSHOT/apptools-core-1.0.0-SNAPSHOT.pom
     Required by:
         project :composeApp

However, I've briefly researched the error (disclaimer: I have zero experience with compose) and found this.

Could you please give that option a try, and report back?

I'm thinking that, out of the box, compose is incompatible with kotlinx-resources. The latter copies resource files which the former seems to be picking up. If I understand what that option above does, that should stop happening. And if it stops happening, I will look into establishing that dependency per the error message. I'd like to confirm if that's the issue first, though. Ideally, we would have a compose module in resources-test, but as said, I'm not exactly sure how compose is set up so that requires some investigation.

@goncalossilva
Copy link
Owner

And if it stops happening, I will look into establishing that dependency per the error message. I'd like to confirm if that's the issue first, though.

It appears compose already disables resources automatically for some other libraries that also handle resources.

@mipastgt
Copy link
Author

mipastgt commented Feb 1, 2025

This is issue starts driving me nuts :-( I downloaded and tried the example code which I sent you but I could not reproduce the error anymore with that code. I then verified it in the original project where this example was derived from and the problem still exists. I then added this

# Test https://github.com/goncalossilva/kotlinx-resources/issues/141#issuecomment-2628680702
org.jetbrains.compose.ios.resources.sync=false

to the gradle.properties file of this project and I can confirm that the tests now work on iOS too. BUT when you toggle this flag on or off, you explicitly have to clean the project because the dependencies on this flag don't seem to be handled correctly by the involved plugins.

So this indeed seems to be a conflict between Compose resource handling and your resource handling.

@mipastgt
Copy link
Author

mipastgt commented Feb 1, 2025

I have to somehow revert my above statement. The whole issue does not seem to be really deterministic. Even without the above flag I can get the iOS tests to work if I do a Gradle clean and then run the iOS tests first. If I then run the same test a second time it fails with the above reported error message.

I have attached the whole project again with the missing dependency removed so that you should now be able to build it. The current state is that if I execute the following steps:

  1. Do a Gradle clean
  2. Execute Gradle with :composeApp:cleanIosX64Test :composeApp:iosX64Test --tests "de.mpmediasoft.wasm.KotlinWasmChasmTest" (This should succeed.)
  3. Execute step 2 again. (This should fail.)

KotlinWasmBridgeDemo.zip

@goncalossilva
Copy link
Owner

Thanks for digging deeper into this @mipastgt, I appreciate it!

to the gradle.properties file of this project and I can confirm that the tests now work on iOS too. BUT when you toggle this flag on or off, you explicitly have to clean the project because the dependencies on this flag don't seem to be handled correctly by the involved plugins.

This probably means there are some left-overs (either by kotlinx-resources or compose) that get picked up as a dependency, but are cleaned if a gradle clean is issued. I can actually check for this using your repro steps.

So this indeed seems to be a conflict between Compose resource handling and your resource handling.

This is my suspicion, considering how those other projects work similarly to this one.

Even without the above flag I can get the iOS tests to work if I do a Gradle clean and then run the iOS tests first. If I then run the same test a second time it fails with the above reported error message.

But with the flag, after a gradle clean, it never fails, correct?

I have attached the whole project again with the missing dependency removed so that you should now be able to build it.

Appreciated, I'll have a crack at this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants