Importing KMM library in multiple iOS modules via Cocoapods results in "... implemented in both ..." - cocoapods

I have been maintaining a shared library built with Kotlin Multiplatform for our Android and iOS native apps for quite some time now. Was working great until I decided to split the iOS app into multiple modules (frameworks). For starters I have one iOS app project and two dynamic frameworks, which are used by the app project. All 3 projects are using Cocoapods for 3rd party dependency management. Own modules are imported via framework embedding. No Cocoapods for the own modules needed, because we don't plan to make them available to other projects.
So the issue I am facing now is that whenever I import the KMM framework into more than one of the modules via Cocoapods, the build succeeds, but I receive errors at runtime like
Class MyClassInKMMProject is implemented in both
/Users/{user}/Library/Developer/Xcode/DerivedData/MyApp-hcbcxlfmsfiiqaccahedgcclxmiq/Build/Products/Debug-iphonesimulator/Common.framework/Common
(0x1189318d0) and
/Users/{user}/Library/Developer/Xcode/DerivedData/MyApp-hcbcxlfmsfiiqaccahedgcclxmiq/Build/Products/Debug-iphonesimulator/Core.framework/Core
(0x112a77ea8). One of the two will be used. Which one is undefined.
Since I need the shared KMM library basically in every module, I am stuck right now with this issue.
In some community I remember that someone mentioned static libraries can be imported only once when using multiple modules. But as far as I understand KMM generated frameworks and not static libraries.
I also tried using XCFrameworks instead of Frameworks, but it didn't change anything.
Anyone here knows how I can fix this?

Tried to find a solution for several days, but just found it after writing this question.
Adding isStatic=false to Gradle was the solution, which I got from this post: https://stackoverflow.com/a/65420364/390542

Related

Is there a WebSocket client library for iOS when using Kotlin?

I am looking for a WebSocket library that I can use in a Kotlin Multiplatform project for my iOS implementation. This project is currently in IntelliJ and I am using Gradle to manage dependencies.
I have not been able to find a library that supports iOS and that I can specifically pull into my project via Gradle.
The likes of Starscream, Socket.io, SocketRocket etc seem to only have a means of importing dependencies within Xcode/CocaoPods and nothing via Gradle for my IntelliJ project.
To give some more context I have the following for my project
Kotlin Common code for all my common functionality for the project
Platform specific code for my WebSocket implementations for Java, JavaScript and iOS/Swift
The reason for the platform specific implementations is because I have not found a common library that supports WebSockets for all platforms.
Ktor comes close, but from what I see in their documentation their WebSocket client does not support iOS while their Http client supports all platforms.
If anyone has any recommendations that would be really helpful.
The guys from ktor said that they are working on bringing Websockets to iOS but it's still a few months from release.
I haven't tried it yet but you can import cocoapods to an multiplatform project so maybe you can use it that way, but note that it will only compile in xcode.
Also you should join kotlinlang on slack, the guys from jetbrains are really active there and will usually have an answer in a day.

Why I can't add aar file to our library project and distribute it without aar?

we are getting really frustrated both financially and also in our project level. The root problem is that we have build an android library project, which uses another aar as a dependency. The clients which integrate our library have to manually include the aar and it does not work in all cases..
​
I can't understand why does https://bintray.com/ does not allow to publish library with added aar file inside of it? We have tried to create a same maven and even publish additional library, but client still need to include both libraries and not a single one..
Android team endorses multi module approach, so why there are no tools to easily integrate library, which has another library as a dependency?
Maybe someone had solved this issue or knows how to do what I have done?

Should you use targets for code you don't own?

I am using this third-party view control in my project https://github.com/nicklockwood/SwipeView That project does not support CocoaPods or Carthage.
Note: my entire project is Swift and this other code is Objective-C.
To integrate this into my project I just dragged in the .h and .m files into my project.
Is this the proper approach? Instead should I have created a new target and put those files in there? Are there any considerations for me to make this choice?
I've used this technique (separate targets building static libraries) for third party code - even when that library does support CocoaPods or Carthage.
One benefit for me was when there were breaking changes, particularly with newer versions of the tool chain, before the third party code was updated. It was straightforward to disable e.g. certain newer compiler warnings in that target alone while keeping the rest of the project as clean / safe as possible.
It's also reasonably tidy when mixing Obj-C and Swift.
I haven't found a downside, as long as you're happy to manage the project integration yourself (that might otherwise be handled by CocoaPods). I only tend to have one or two third-party libraries in my macOS projects.

How to create custom library with gradle `compile` support in AndroidStudio?

I'd like to create my own gradle library, that can be compiled into other projects using gradle compile statement.
Example from Picasso's README:
Download the latest JAR or grab via Gradle:
compile 'com.squareup.picasso:picasso:2.5.2'
I'm developing few applications that share common source: fragments, views, some logic... Sometimes I extend these sources while I'm developing app A, sometimes while I'm developing app B,... And I feel that copy-paste of packages/classes in Android Library Module is not an proper solution.
So I would like to setup my own library, that:
it could be easily deployed to as gradle library that could be used by compile.
I can easily develop/extend it together with currently developed application
Disclaimer: I had been googling it a lot, but without luck.
If you want to reuse a library across completely separate projects then you'll want to publish your library to repository. Assuming this is open source and you don't mind sharing, you could use JCenter, which is already added as a repository to Android projects by default.
https://www.virag.si/2015/01/publishing-gradle-android-library-to-jcenter/

How to build and include a 3rd party C library in Xcode 6.0

I'm trying to build a 3rd party C library and include it in my project. The library is the Swiss Ephemeris and I'm trying to use the preconfigured Xcode project here https://github.com/dwlnetnl/SwissEphemeris.
I can get the framework to build properly, but I don't know how to include it in my project. Ideally, I want to store the framework within the project so that I can commit it to a repository and have developers check out the file, and build the project without the need to have the framework installed locally first. I'm not sure if that's possible?
So, if someone can explain:
How to include the built framework into my project
How to 'embed' it
within the project so that the framework can be stored within the
project.
it would be greatly appreciated.
Static libraries are unsupported in Swift 1. You can use Objective-C to call the library.

Resources