https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
b

bmo

03/04/2021, 8:36 AM
Hello everyone, I'm trying to create a multi-module library in Kotlin Multiplatform to be used in iOS, Android and Web but I have issues with iOS. I created a stackoverflow post. If anyone can help, it would be greatly appreciated! https://stackoverflow.com/questions/66471115/how-to-make-a-multi-module-kotlin-multiplatform-library-for-ios
a

Artyom Degtyarev [JB]

03/04/2021, 1:30 PM
Hello, @bmo. First of all, can you please clarify why you want to use CocoaPods plugin for both of those modules? As far as I understand, you’d like to use it only for the
:example
module. The other problem I see is that you define
export(...)
over the framework, which is not being used by the CocoaPods plugin. To access the right one, I would recommend to get rid of the current
framework{…}
block, and to specify those export as
Copy code
targets.withType<KotlinNativeTarget>{

        binaries.withType<org.jetbrains.kotlin.gradle.plugin.mpp.Framework>{
            //Specify things here
        }
    }
b

bmo

03/04/2021, 2:37 PM
Hello @Artyom Degtyarev [JB], I have no idea what I'm doing. That's why ^^ Could you tell me how I should specify the things there? Because I don't see how what you propose for the export is going to be different than having :
Copy code
ios("ios") {
  binaries {
    framework("Example") {
      // Specify things here
    }
  }
}
a

Artyom Degtyarev [JB]

03/04/2021, 2:52 PM
CocoaPods plugin adds its own framework internally. See, at the doc:
Adds both 
debug
 and 
release
 frameworks as output binaries for all macOS, iOS, tvOS, and watchOS targets.
This framework’s name will be set by the
frameworkName
option, and none of your options defined at the
ios().binaries.framework
block will be applied.
In fact, there are two main options when you produce an iOS framework. 1. You define a framework binary, specify all its details, produce it using
link<Debug|Release>Framework<targetName>
and add it to the Xcode - manually or using
packForXcode
task, as the documentation and all wizards do 2. You use the CocoaPods plugin to set dependency on a pod, AND to deliver your framework to the Xcode project Mixing those is not a good idea, this way one could confuse oneself easily.
b

bmo

03/04/2021, 3:15 PM
Thank you very much, I'll try that !
@Artyom Degtyarev [JB], I have tried this morning many configuration but none seems to work. Also, when I change for :
Copy code
targets.withType<KotlinNativeTarget>{
    binaries.withType<org.jetbrains.kotlin.gradle.plugin.mpp.Framework>{
        baseName = "Example"
        export(project(":common")) {
            isStatic = true
        }
    }
}
The import in Android Studio takes a very long time to finish (it's been running for 20 minutes) and the tasks which takes the longer seems to be :
Copy code
:example:generateDummyFramework
:example:podImport
Also, I have changed `common`'s
build.gradle.kts
to remove the cocoapods part and said that the binary is a
staticLib
When I do a
pod install
with only
example
in my
Podfile
, nothing changes. I still have classes generated in the framework which matches the interface in
common
but no class from
common
Finally, I realized I wasn't clear yesterday but the reason why I had
common
as a cocoapods is because later, I want more than 1 module like
example
and they all need to depend on the same
common
(but I'll figure this part later)
a

Artyom Degtyarev [JB]

03/05/2021, 11:53 AM
1.
isStatic
parameter makes sense only for a framework block. I’m not sure this syntax works correctly. 2. Have you tried adding
transitiveExport = true
?
Copy code
targets.withType<KotlinNativeTarget>{
    binaries.withType<org.jetbrains.kotlin.gradle.plugin.mpp.Framework>{
        baseName = "Example"
        export(project(":common"))
        isStatic = true
        transitiveExport = true
    }
}
b

bmo

03/05/2021, 1:49 PM
Thanks, I'll try that
h

Hiresh Pillay

08/11/2022, 11:16 AM
I’m having a similar case where a KMM module is dependent on another KMM module. Using export breaks the code as there are also cases where I will be using both the modules together on iOS native. Where you guys able to find out a solution for this?
23 Views