I'm trying to integrate Mapbox's frameworks into my Kotlin multiplatform library. But I'm getting a compile error with the cinterop portion.
First problem was with the compile step with MapboxMobileEvents framework. The MapboxMobileEvents.h
has import statements referring to a MapboxMobileEvents
directory that doesn't exist. I created a symbolic link to get around that.
After that I'm getting an error from clang.
Exception in thread "main" java.lang.IllegalStateException: clang_parseTranslationUnit2 failed with CXError_ASTReadError;
sourceFile = /var/folders/vj/mvxq9qtn1r9_8x2c7zyx04_m0000gn/T/tmp6661284981682757951tmp8536987580934998728.m
arguments = -fmodules -isystem /Users/mkrussel/.konan/dependencies/clang-llvm-apple-8.0.0-darwin-macos/lib/clang/8.0.0/include -B/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin -fno-stack-protector -stdlib=libc++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.5.sdk -miphoneos-version-min=9.0 -O2 -I/Users/mkrussel/pangea/mapbox-native/pangea-mapbox/frameworks/MapboxMobileEvents.framework/Headers -fobjc-arc -include-pch /var/folders/vj/mvxq9qtn1r9_8x2c7zyx04_m0000gn/T/tmp1085765932502683439.pch -Werror=implicit-function-declaration -ferror-limit=0
The tmp6661284981682757951tmp8536987580934998728.m
name changes on every build, but the file is always empty, which is what I assume is causing the problem.
What I cannot figure out is what causes the file to be empty.
Did I configure the cinterop wrong?
Is the Kotlin plugin broken?
Is something with the Mapbox frameworks incompatible with Kotlin native?
My gradle file looks like
iOSTarget("ios") {
compilations {
@Suppress("UNUSED_VARIABLE")
val main by getting {
kotlinOptions.freeCompilerArgs = listOf("-Xobjc-generics")
val frameworksDir = "$projectDir/frameworks"
cinterops(Action {
val mapboxEvents by creating {
defFile("$frameworksDir/mapbox-events.def")
includeDirs.allHeaders("$frameworksDir/MapboxMobileEvents.framework/Headers")
}
})
cinterops(Action {
val mapbox by creating {
defFile("$frameworksDir/mapbox.def")
includeDirs.allHeaders("$frameworksDir/Mapbox.framework/Headers")
}
})
}
}
}
mapbox-events.def
package = framework.mapbox.events
language = Objective-C
headers = MapboxMobileEvents.h
headersFilter = **
compilerOpts = -F/Users/mkrussel/pangea/mapbox-native/pangea-mapbox/frameworks -framework MapboxMobileEvents -fmodules
linkerOpts = -F/Users/mkrussel/pangea/mapbox-native/pangea-mapbox/frameworks -framework MapboxMobileEvents
mapbox.def
package = framework.mapbox
language = Objective-C
headers = Mapbox.h
headersFilter = **
compilerOpts = -F/Users/mkrussel/pangea/mapbox-native/pangea-mapbox/frameworks -framework Mapbox -fmodules
linkerOpts = -F/Users/mkrussel/pangea/mapbox-native/pangea-mapbox/frameworks -framework Mapbox
Using full path names in the .def
files to make sure that there's no relative path problems. Trying to use just one of the mapbox.def
or the mapbox-events.def
file still produces the same error.
Using:
Tried this also, and I get the same failure.
iOSTarget("ios") {
val frameworksDir = "$projectDir/frameworks"
compilations {
@Suppress("UNUSED_VARIABLE")
val main by getting {
kotlinOptions.freeCompilerArgs = listOf("-Xobjc-generics")
cinterops(Action {
val mapboxEvents by creating {
defFile("$frameworksDir/mapbox-events.def")
packageName("com.mapbox.events")
header("$frameworksDir/MapboxMobileEvents.framework/Headers/MapboxMobileEvents.h")
compilerOpts("-fmodules")
includeDirs.allHeaders("$frameworksDir/MapboxMobileEvents.framework/Headers")
}
})
cinterops(Action {
val mapbox by creating {
defFile("$frameworksDir/mapbox.def")
packageName("com.mapbox")
header("$frameworksDir/Mapbox.framework/Headers/Mapbox.h")
compilerOpts("-fmodules")
includeDirs.allHeaders("$frameworksDir/Mapbox.framework/Headers")
}
})
}
}
binaries {
executable {
linkerOpts = mutableListOf("-F$frameworksDir", "-framework", "Mapbox", "-framework", "MapboxMobileEvents")
}
}
}
mapbox-event.def
language = Objective-C
mapbox.def
language = Objective-C
I eventually got this to work.
mapbox.def
language = Objective-C
modules = Mapbox
linkerOpts = -framework Mapbox
in build.gradle.kts
kotlin {
ios {
val frameworkLocation = File(rootDir, "native/TestApp/Pods/Mapbox-iOS-SDK/dynamic/").absolutePath
val frameworks = "-F$frameworkLocation"
compilations {
@Suppress("UNUSED_VARIABLE")
val main by getting {
cinterops {
val mapbox by creating {
defFile = File("$projectDir/libs/mapbox.def")
packageName("com.mapbox")
compilerOpts(frameworks)
}
}
}
}
binaries.matching { it is org.jetbrains.kotlin.gradle.plugin.mpp.Framework }
.configureEach {
val framework = this as org.jetbrains.kotlin.gradle.plugin.mpp.Framework
framework.linkerOpts(frameworks)
}
}
}
Seems like one of the big pieces I was missing was the modules line
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments