I am making an app that connects customers and businesses. Now I’d like to pack it into a single project as they are thematically connected and might share some of the logic. This would be simple enough with a native app but for multiplatform I am unsure as how to have them organized. Eg I’d have two IOS and two Android modules, but for the shared code, I’d need 3 shared libraries, sharedBussiness, sharedCustomer and common. Would this seperation be too difficult to handle when it comes to generating frameworks and dependencies? As the sharedBusiness/ Customer would depend on the common module, and on the ios side there are frameworks that have to be generated and handled. Is this a common approach/ would it work?
Question posted in Android Studio
The official documentation can be found here.
The official documentation can be found here.
2
Answers
This should work without any problems. If you split your code in many modules, you can include only needed ones for each platform or app.
It’s not that easy to add many KMM modules to an iOS app, but you don’t need to.
So your may have
sharedBusiness
andsharedCustomer
KMM modules, each included by a corresponding application, and both may be just a combination of other KMM modules, depend oncommon
in your case.By default it’ll only export classes used by headers of the
shared
module.Like, if you have
data class SharedBusiness(let common: SomeCommonClass)
, theSomeCommonClass
will be exported, otherwise – it’ll not.So if you need to export all classes and functions from
common
module to iOS framework, you can do it using this docsYou can achieve this using Android Build variant (
productFlavor
), You would have 1 Main source code with the shared logic, and then you create new package one for your Customer and one for your Business and inside you put the difference code only.to read more check this out build-variants