Kotlin-native: Problem with auto-generated names of the ObjC methods

Created on 17 Aug 2018  路  9Comments  路  Source: JetBrains/kotlin-native

Most helpful comment

I'm working with Kotlin New Multiplatform Project style (refering : https://github.com/h0tk3y/k-new-mpp-samples)

The kotlinx.serialization's jsonparser(0.7.0) classes goes invalid objC header too.
I did the same workaround, by deleting invalid objC properties in header file with gradle script.

build.gradle

afterEvaluate {
    [linkMainReleaseFrameworkIosArm64, linkMainDebugFrameworkIosArm64,
        linkMainReleaseFrameworkIosX64, linkMainDebugFrameworkIosX64].forEach { task ->
        task.doLast {
            def target = compilation.target.disambiguationClassifier
            def buildType = compilation.buildTypes.find{ it.debuggable == debuggable }.name.toLowerCase()
            def header = new File(buildDir, "bin/$target/${compilation.name}/$buildType/framework/${ios_framework_name}.framework/Headers/${ios_framework_name}.h").absolutePath
            ant.replace(file: header, token: '@property (readonly) double double;', value: '')
            ant.replace(file: header, token: '@property (readonly) float float;', value: '')
            ant.replace(file: header, token: '@property (readonly) int32_t int;', value: '')
            ant.replace(file: header, token: '@property (readonly) int64_t long;', value: '')
        }
    }
}

All 9 comments

Any workaround to be done at least?

You can make every coroutines related part to be internal for now

As a workaround, I am currently using a custom shell script build phase in the Xcode project, to replace all "Kotlinx-coroutines-core-native" strings with "" in the Kotlin framework's header file.

Order this build script after the Kotlin/Native compiler script.

In my case the Kotlin framework is common.framework, so the shell script looks like this:

cd \"$CONFIGURATION_BUILD_DIR\"
sed -i -e 's/Kotlinx-coroutines-core-native//g' common.framework/Headers/common.h

I don't understand enough about compilers and linkers to know why this doesn't cause linker or runtime errors, but it works! Perhaps because, in my case, the only way that those symbols are referenced from Swift is when they are returned out of the Kotlin framework (I'm not instantiating any of those symbols from Swift).

Hope this helps!

Can anyone comment if the above workaround is safe or if there is some other way around?

I'm working with Kotlin New Multiplatform Project style (refering : https://github.com/h0tk3y/k-new-mpp-samples)

The kotlinx.serialization's jsonparser(0.7.0) classes goes invalid objC header too.
I did the same workaround, by deleting invalid objC properties in header file with gradle script.

build.gradle

afterEvaluate {
    [linkMainReleaseFrameworkIosArm64, linkMainDebugFrameworkIosArm64,
        linkMainReleaseFrameworkIosX64, linkMainDebugFrameworkIosX64].forEach { task ->
        task.doLast {
            def target = compilation.target.disambiguationClassifier
            def buildType = compilation.buildTypes.find{ it.debuggable == debuggable }.name.toLowerCase()
            def header = new File(buildDir, "bin/$target/${compilation.name}/$buildType/framework/${ios_framework_name}.framework/Headers/${ios_framework_name}.h").absolutePath
            ant.replace(file: header, token: '@property (readonly) double double;', value: '')
            ant.replace(file: header, token: '@property (readonly) float float;', value: '')
            ant.replace(file: header, token: '@property (readonly) int32_t int;', value: '')
            ant.replace(file: header, token: '@property (readonly) int64_t long;', value: '')
        }
    }
}

I have same bug
Screen Shot 2019-03-28 at 6 01 18 PM

@irgaly Can U show full build.gradle. I don't understand [linkMainReleaseFrameworkIosArm64, linkMainDebugFrameworkIosArm64, linkMainReleaseFrameworkIosX64, linkMainDebugFrameworkIosX64] what does this mean. And compilation.name, ios_framework_name is your config?

Help me, thank!!!

Screen Shot 2019-03-29 at 10 37 20 AM
I fixed this by script. Thank @brettwillis

@elizarov @SvyatoslavScherbina anything left here?

All reported cases are already fixed.

Was this page helpful?
0 / 5 - 0 ratings