Codelab - Mature KMP Team Adoption Models

· 2 min read

Author: Kevin Galligan

Prep

Clean up old repos

gh repo delete kpgalligan/GitPortalTemplateLibrary --yes
gh repo delete kpgalligan/GitPortalDemoAndroid --yes
gh repo delete kpgalligan/GitPortalDemoIos --yes
rm -rdf *

Part 1

Create a folder

Follow steps from doc: https://touchlab.co/kc-team-codelab

Create the repos

Link repos. This actually add the KMP code to the repos. GitPortal is loosely based on git subrepo. It’s sort of like git submodules, but without the problems. Sort of like git subtree, but avoids some issues

Open local repos in Intellij

idea GitPortalDemoAndroid
idea GitPortalDemoIos
idea GitPortalTemplateLibrary

Open Android in Intellij

Open terminal (option+f12)

gitportal setup library -r https://github.com/kpgalligan/GitPortalTemplateLibrary.git -t 0.1.0

In the library folder, there’s a config file. That tracks things for you. It’s in the library folder, but

Open Ios in Intellij

Open terminal (option+f12)

gitportal setup library -r https://github.com/kpgalligan/GitPortalTemplateLibrary.git -t 0.1.0

Open Template in Intellij

Open terminal (option+f12)

gitportal deploykey -k kpgalligan/GitPortalTemplateLibrary \
    -a kpgalligan/GitPortalDemoAndroid -a kpgalligan/GitPortalDemoIos

Show repos and what it does

Open https://github.com/kpgalligan/GitPortalTemplateLibrary

Open Settings, Deploy Keys

Open https://github.com/kpgalligan/GitPortalDemoAndroid

Open Settings, Actions Secrets

Wire android

Open Intellij

Open settings.gradle.kts

Change projects

Open app/build.gradle.kts

Uncomment

implementation(project(":analytics"))
implementation(project(":breeds"))

Wire iOS

Open Intellij

Open terminal (option+f12)

open ios.xcproject

“I’ll show this, but probably best to do on your own, as Xcode will probably be less familiar”

“We’re going to use direct linking instead of CocoaPods or other options”

Add Run Script

Add, move to top

Copy into field

cd "$SRCROOT/library"
./gradlew embedAndSignAppleFrameworkForXcode

In “Other Linker Flags” add -framework allshared

In “Framework Search Paths” add

$(SRCROOT)/library/allshared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)

Build the app

Part 2

Show how to check

Open Android in Intellij

Open terminal (option+f12)

gitportal check library

Add a comment to build gradle

gitportal check library

Push code

Show fail

Run check again, copy diff apply line, run

Add/commit

Run check again

push

Open GitPortalTemplateLibrary in Intellij

Make the same change

Open terminal (option+f12)

Add/commit

Create a new version

git tag -a "0.1.1" -m "Version 0.1.1"
git push origin --tags

Open android in Intellij

Open terminal (option+f12)

gitportal pull library -t "0.1.1"

Open .gitportal and show changes

Part 3

Open Android in Intellij

Open DatabaseHelper and add another comment

Open terminal (option+f12)

Add/commit

gitportal push library -b "newcomment"

Run check

gitportal check library

Fail, explain

Open Ios in Intellij

Open terminal (option+f12)

gitportal pull library -b "newcomment"

“Now we can do iOS stuff, then submit”

Open https://github.com/kpgalligan/GitPortalTemplateLibrary

Create PR, Merge

Create release in Browser

0.1.2

“That also creates a tag”

Open Android

gitportal pull library pull -t "0.1.2" -f

OK