https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
s

Sylvain Patenaude

11/15/2019, 9:52 PM
Slowly but surely. When I build on iOS with
gradlew build iosTest
, I get an error like this:
Task 'iosTest' is ambiguous in root project 'MySDK'. Candidates are: 'iosTestBinaries', 'iosTestKlibrary', 'iosTestProcessResources'.
The iOS part of my build.gradle looks like this: kotlin { iosX64("ios") { binaries { framework() } } sourceSets { commonMain { dependencies { implementation kotlin('stdlib-common') } } iosMain { } iosTest { } } }
r

russhwolf

11/16/2019, 2:04 AM
K/N doesn’t automatically create test tasks for cross-compiled targets. You need to define it yourself. eg https://github.com/russhwolf/multiplatform-hello/blob/master/shared/build.gradle.kts#L67-L77
👍 1
s

Sylvain Patenaude

11/18/2019, 7:15 PM
Ok, thanks for that @russhwolf. I added the
iosTest
task. Now I have this error:
Execution failed for task ':iosTest'.
> Process 'command 'xcrun'' finished with non-zero exit value 165
And this also if it helps:
An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=165):
Invalid device state
It links back to this line (the exec line) in the build.gradle: exec { <-- this line commandLine 'xcrun', 'simctl', 'spawn', ... }
I fiddled with my build.gradle file and it works now. I noticed that the "common" tests are run automatically, no need to add an explicit task. I think it's because of a dependency with the
iosTest
task or it's an implicitely generated task based on the
commonTest
sourceSet.
@russhwolf The thing I don't fully understand is how to avoid running the task
iosTest
in my Android/JVM build since it's in the *shared/*build.gradle.kts in your GitHub example. If I remove the line
check.dependsOn(iosTest)
, it isn't run in any of my builds (Android, iOS), but with the line, both builds run it (because of the
check
dependency I guess).
What I want to achieve, for instance, is: 1. For my iOS build pipeline: run tests that are in
iosTest
and
commonTest
(but not those in
jvmTest
). 2. For my Android build pipeline: run tests that are in
jvmTest
and
commonTest
(but not those in
iosTest
). Do I need to move the
iosTest
task down in the iosTest sub-folder or can/should I achieve this by tailoring my YAML build files accordingly? (I have 2 separate build files, android.yml and ios.yml, but they both call 'gradlew *build*' for now.)
r

russhwolf

11/19/2019, 7:49 PM
The setup on that project is for running all tests for all platforms via
gradlew check
. If you want to do separate pipelines for each, probably you should remove the
check.dependsOn(...)
and just manually call the
iosTest
task as part of your ios pipeline.
s

Sylvain Patenaude

11/19/2019, 8:08 PM
Thank you Russell, I will try this. If I may ask: what makes this setup running all tests for all platforms? Is it like this by default and it requires a filtering/restricting approach to be scripted explicitely? Also, what's the best approach if I want to filter out the whole
jvm
target of my iOS build pipeline? Not only the test part, but the build part as well. For instance, is
iosBuild
(instead of just
build
) also a predefined task for the
ios
target?
All right, I tweaked my .yml files and have them call Gradle like this and it seems to work fine: 1. iOS: gradlew iosBinaries iosTest 2. Android: gradlew jvmJar jvmTest
16 Views