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

curioustechizen

02/05/2020, 3:41 PM
My use-case: I already have a modular Android app and I want to add iOS. Here's the structure
Copy code
MyApp
  - app
  - feature1_domain
  - feature1_presentation
  - feature2_domain
  - feature2_presentation
  - and so on
All the _`domain` modules serve the purpose of
common
in KMP (they have platform-agnostic code already).
app
, and all the
_presentation
modules have Android-specific code. Wondering what's the best approach to add iOS here. From what I understand, the goal is to generate a single
.framework
from the common code for use in iOS. I did not find any examples of this
k

Kris Wong

02/05/2020, 3:49 PM
i would separate cross-platform code into modules based on function
1
and yes, you will need to pull all your iOS modules into one umbrella framework
s

Sam

02/05/2020, 3:51 PM
Something like:
Copy code
MyApp //Android depends on MyAppLib
  - app
  - feature1_presentation
  - feature2_presentation
  - and so on
MyAppIOS //depends on MyAppLib.framework (umbrella framework)
MyAppLib //Android & iOS lib
  - feature1_domain
  - feature2_domain
  - and so on
c

curioustechizen

02/05/2020, 4:35 PM
I'm not sure I understand. The structure I presented is a single project with multiple gradle modules. Are you suggesting making sub-projects?
k

Kris Wong

02/05/2020, 4:36 PM
or separate repos
c

curioustechizen

02/05/2020, 4:38 PM
So there isn't a way to create a "shell" module that depends on other platform-agnostic modules and generates a .framework out of them?
k

Kris Wong

02/05/2020, 4:40 PM
yes, you can do that
c

curioustechizen

02/05/2020, 4:41 PM
Thinking out aloud, all my
_domain
modules are currently are
apply plugin: 'kotlin'
and
apply plugin: 'java-library'
I could turn them all into
Copy code
apply plugin: 'org.jetbrains.kotlin.multiplatform'
Wait I'm confused now. I still don't know how the sourceSet setup works with gradle modules. Maybe I should give it a try first 😄
k

Kris Wong

02/05/2020, 4:43 PM
would probably help make it clearer
There is a little problem with the setup, but we found 2 workaround to fix on android. Ios works, the result 1 single framework dependency.
👍 1
k

Kurt Renzo Acosta

02/07/2020, 9:28 AM
What I did was create another module just for iOS.
Copy code
Android:
- app
- feature-1
- feature-2

Shared:
- shared-feature-1 (domain and data)
- shared-feature-2 (domain and data)
- shared-ios
shared-ios
just exports the modules through
export(project(:shared-feature-1
and all other modules and you can consume it in android normally.
👍 1
11 Views