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

Add ios target support #40

Merged
merged 1 commit into from
Sep 7, 2021
Merged

Conversation

makindotcc
Copy link
Contributor

Dunno if this is 100% correct as it's my first days with kotlin multiplatform, but it compiles! also basic serialization on ios seems to work.

@esensar
Copy link
Owner

esensar commented Sep 6, 2021

Hello @makindotcc 👋

Thank you for your contribution. I don't think that library needs to have ios defined as a target for the library to work on iOS. All code is supported on all platforms, since it is using only common source set. Other targets are defined only for testing purposes. This would only be needed if we wanted to run iOS specific tests for the library, which is not required I think.

Let me know if you run into issues using library this way. I believe you should be able to just add this library to your multiplatform project as instructed in README:

implementation("com.ensarsarajcic.kotlinx:serialization-msgpack:${kotlinxSerializationMsgPackVersion}")

And you should be able to target iOS without any issues in your multiplatform project.

@makindotcc
Copy link
Contributor Author

makindotcc commented Sep 6, 2021

Hello 👋

When I try to use main version, like that:

        val commonMain by getting {
            dependencies {
                implementation("com.ensarsarajcic.kotlinx:serialization-msgpack:0.2.0")
            }
        }

then I get following errors:

❯ ./gradlew build

[...]

> Task :shared:compileKotlinIos FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':shared:compileKotlinIos'.
> Could not resolve all files for configuration ':shared:iosCompileKlibraries'.
   > Could not resolve com.ensarsarajcic.kotlinx:serialization-msgpack:0.2.0.
     Required by:
         project :shared
      > No matching variant of com.ensarsarajcic.kotlinx:serialization-msgpack:0.2.0 was found. The consumer was configured to find a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native', attribute 'org.jetbrains.kotlin.native.target' with value 'ios_x64' but:
          - Variant 'js-api' capability com.ensarsarajcic.kotlinx:serialization-msgpack:0.2.0 declares a usage of 'kotlin-api' of a component:
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attribute:
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_x64')
          - Variant 'js-runtime' capability com.ensarsarajcic.kotlinx:serialization-msgpack:0.2.0:
              - Incompatible because this component declares a usage of 'kotlin-runtime' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js' and the consumer needed a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attribute:
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_x64')
          - Variant 'jvm-api' capability com.ensarsarajcic.kotlinx:serialization-msgpack:0.2.0 declares an API of a component:
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attribute:
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_x64')
          - Variant 'jvm-runtime' capability com.ensarsarajcic.kotlinx:serialization-msgpack:0.2.0 declares a runtime of a component:
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attribute:
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_x64')
          - Variant 'metadata-api' capability com.ensarsarajcic.kotlinx:serialization-msgpack:0.2.0 declares a usage of 'kotlin-api' of a component:
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attribute:
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_x64')
          - Variant 'native-api' capability com.ensarsarajcic.kotlinx:serialization-msgpack:0.2.0 declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'ios_x64'

[...]

I saw, like you said, that the library is based only on "common" source set, so maybe there is a better way to add support for all targets instead of adding every target manually?

@esensar
Copy link
Owner

esensar commented Sep 6, 2021

I think you are right... Looking at kotlinx-serialization, it seems all targets are added manually: https://github.com/Kotlin/kotlinx.serialization/blob/master/gradle/native-targets.gradle

@esensar esensar merged commit fa9341c into esensar:main Sep 7, 2021
@esensar
Copy link
Owner

esensar commented Sep 7, 2021

Thank you once again for your contribution @makindotcc. This should be available in version 0.2.1. Can you confirm it is working as expected?

@makindotcc
Copy link
Contributor Author

Yes, it works as expected ❤️. Thank you and have a nice day.
Working serialization on iOS

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

Successfully merging this pull request may close these issues.

None yet

2 participants