I am trying to use an external shared library for ...
# multiplatform
m
I am trying to use an external shared library for some platform of a multiplatform project. This works perfectly but IntelliJ is just not able to resolve the generated code. More details inside the thread.
In IntelliJ I only get this:
I’ve put the libdemomodel.def, all .h files and the .dylib into there respective places and added the following entry to the build.gradle.kts file.
Copy code
kotlin {
    ...
    macosX64 {
        compilations.getByName("main") {
            cinterops {
                val libdemomodel by creating
            }
        }
        binaries {
            ...
        }
    }
    ...
}
As I already said. This compiles and works perfectly but IntelliJ is just not able to resolve it. Does anybody have an idea what might be missing?
p
Try adding
Copy code
kotlin.mpp.enableCInteropCommonization=true
to your
gradle.properties
file. The rest of my cinterop config isn’t vastly different to yours.
l
It looks like you’re only applying the .def for macosX64. Is the error you posted in macosX64Main, or are there other targets in the source set? You have to apply the def file to all targets of a source set if you want to use the generated code.
m
@psh I just gave that a try but it did not make any difference. This may be enabled already by default like the other two properties mentioned in this context https://kotlinlang.org/docs/whatsnew1530.html#ability-to-use-custom-cinterop-libraries-in-shared-native-code
@Landry Norris I only use the shared library for macosX64. I have a function defined for all targets via expect/actual but only the macosX64 actual implementation of this function is not a no-op and uses the shared lib. As I already said, building and running the app works for all platforms without problem and does exactly what it is supposed to do. It is just IntelliJ again which gets confused (and me of course about IntelliJ 😉).
l
What version of intellij?
m
IntelliJ IDEA 2022.3 RC (Community Edition) Build #IC-223.7571.123, built on November 23, 2022 Runtime version: 17.0.5+1-b653.14 x86_64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 12.6.1 GC: G1 Young Generation, G1 Old Generation Memory: 2048M Cores: 12 Metal Rendering is ON Non-Bundled Plugins: com.intellij.javafx (1.0.4) com.gluonhq.plugin.intellij (2.8.6) org.asciidoctor.intellij.asciidoc (0.37.54) com.squareup.sqldelight (1.5.3) androidx.compose.plugins.idea (223.7571.123) Kotlin: 223-1.7.20-release-201-IJ7571.123
l
Also, does a full gradlew build complete successfully? I’ve seen times where IntelliJ is trying to tell me that I’m in nativeMain and I only configured the def file for macosArm64. It builds fine for macosArm64 in this case, but a gradlew build errors on other targets.
It could also be the current state of IntelliJ. I just switched back to a project in IntelliJ and it suddenly shows errors for all native methods.
m
I just ran the app for all configured targets (android, desktop, JS, macOS, UiKit) without problem.
l
Then it’s likely just an IntelliJ bug.
m
Yes, I also think so. Have a good night.
l
Manually triggering a sync helped my issue, if that helps. Do you see any interesting output when you sync? It’s easy to miss sometimes.