How to integrate Mapbox iOS framework into Kotlin native

Michael Krussel

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:

  • Kotlin version 1.3.72
  • Xcode version 11.5 (11E608c)

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
Michael Krussel

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.

edited at
0

Comments

0 comments
Login to comment

Related

Integrate GoogleMaps with Mapbox iOS sdk

How to integrate React Native to existing iOS project

How to integrate native ios third party library into react native app?

How to integrate Mapbox SDK with SwiftUI

How to integrate the unity ios project into native ios swift project?

How to integrate third-part iOS sdk to react native

Is there a web framework for kotlin native

How to integrate Vimeo in IOS?

How to generate a .framework depending from another with Kotlin/native?

How to integrate maven framework with Jenkins

How to integrate wicket framework with mongoDB?

How to integrate a custom framework into backbone?

Kotlin Native compile jar and framework

Kotlin/Native framework with platform libs

Import Kotlin/Native framework in Cocoapod

Microsoft Cognitive Services Face API - How to integrate iOS Framework without cocoa pods?

How to add two or more kotlin native modules on an iOS project

How to integrate mobileiron sdk in iOS

Integrate react-native-navigation with react-native-callkit in iOS

How to parse response of Mapbox reverse geocoding in Kotlin

How to integrate Google GSI with Kotlin/JS

How to integrate react native checkbox with formik

How to integrate twilio in react native for android?

How to integrate orientation in react-native

How to Integrate Crashlytics with React Native app

How to integrate React-native with backend server?

How to integrate Crisp SDK in react native

How to integrate NestJS/passport with React Native/Expo?

How to integrate Git with other native issue tracker?

TOP Ranking

HotTag

Archive