Skip to content

Kotlin Multiplatform Mobile Weather App 2022

License

Notifications You must be signed in to change notification settings

whether-jacket/weather-app-2022-kmm

Repository files navigation


Weather App 2022 KMM


Built With

Prerequisites

Installation

Java
1. Java Home variable is set
echo $JAVA_HOME

Should see

/Library/Java/JavaVirtualMachines/jdk-11.0.13.jdk/Contents/Home

If you see it, you can skip the two steps below.

2. Java version is downloaded
/usr/libexec/java_home -V

Should see installed JDKs:

17.0.1 (x86_64) "Oracle Corporation" - "Java SE 17.0.1" /Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home
16.0.1 (x86_64) "Oracle Corporation" - "OpenJDK 16.0.1" /Users/user/Library/Java/JavaVirtualMachines/openjdk-16.0.1/Contents/Home
11.0.13 (x86_64) "Oracle Corporation" - "Java SE 11.0.13" /Library/Java/JavaVirtualMachines/jdk-11.0.13.jdk/Contents/Home
...

If not found, have not downloaded the JDK properly.

3. Correct JDK v11 is showing
/usr/libexec/java_home -v 11

Should see

/Library/Java/JavaVirtualMachines/jdk-11.0.13.jdk/Contents/Home

If you see a non-Oracle JDK, like open JDK, you need to uninstall it first.

4. Set Java Home variable

Find out what shell version you're using:

echo $SHELL

If you're using ZSH: you ought to be updating ~/.zshrc else ~/.bash_profile for the following steps.

Update your profile:

[emacs/vim/atom] ~/.zshrc

Add the following line:

export JAVA_HOME=$(/usr/libexec/java_home -v 11)

Update shell profile

source ~/.zshrc
Mac Developer Tools
1. Install Mac dev tools

Install Mac dev tools:

xcode-select --install

Accept dev tools agreement:

sudo xcodebuild -license
2. Enable command line tools

Xcode -> Preferences -> Locations -> Command Line Tools -> [Select latest]

If you don't do this, on builds you may see the following errors:

Kotlin/Native: KonanExternalToolFailure "The /usr/bin/xcrun command returned non-zero exit code: 72"
xcrun: error: unable to find utility "xcodebuild", not a developer tool or in PATH
Android Studio
1. Android Studio Install

When installing Android Studio, choose custom:

Insert custom directory for Android SDK:

2. Set Android shell variables

After installation flow, set ANDROID_HOME & ADB variables in shell:

export ANDROID_HOME="/Applications/AndroidSDK/"
export adb="/Applications/AndroidSDK/platform-tools/adb"
export ADB="/Applications/AndroidSDK/platform-tools/adb"
3. Create an Android Emulator
  • Open the Android Virtual Device (AVD) Manager: Tools -> AVD Manager
  • Select + Create New Virtual Device....
  • From the large devices list, select latest Pixel, i.e. Pixel 3 XL.
  • Next you need to select an image: Select newest API level/x86_64/Google Play
  • Last step, select Advanced -> Graphics -> Hardware
Cocoapods
1. Ensure correct Ruby version

Ensure Ruby v2.6 is installed. Note: does not work on v3+.

ruby -v
2. Install cocoapods
sudo gem install cocoapods -v 1.8.4
3. Error

If you have installation issues, check here for solutions.

Build Android
1. Open project in Android Studio

Open the project in Android Studio.
Wait for indexing to finish.
Make sure you see the run config for the app:

Run the Android app on either emulator or phone.
2. Error: Android Gradle requires Java 11 to run

If you see following error:

Go to Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle -> Select Gradle JDK

3. Error: SDK location not found

If you see the following error:

SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting up the sdk.dir path in your project's local properties file...

Project does not know the location of your local Android SDK.
Open local.properties

sdk.dir=[ANDROID_SDK_ROOT location as used during installation]
4. Gradle Sync Fail: 'pod install' fail

If you see the following error:

Please, check that file "../iosApp/Podfile" contains following lines in header: source 'https://cdn.cocoapods.org'

Open ios directory.

sudo gem install cocoapods

After successful pod generation close the terminal.

sudo gem install cocoapods-generate

Close and reopen the terminal again
Edit ~/.zshrc& add the following:

export LANG=en_US.UTF-8

source ~/.zshrc or quit & reopen terminal
Source: https://stackoverflow.com/questions/69805554/kmm-project-setup-with-cocoapods-fails-on-first-compile

Build iOS
1. Gradle Build

Go to project folder:

cd weather-app-2022-kmm

Run gralde build:

./gradlew build

Open Xcode workspace project in the ios/ folder: KaMPKitiOS.xcworkspace.
Run the iOS app on Simulator.

2. Error: No such module

If you get the following compilation error:

no such module: 'shared'

Close Xcode.
Delete Pods/ folder located in the root directory of the iOS project.
Run the command pod install in that same iOS root directory (which is /weather-app-2022-kmm/ios/ to be specific).
This will generate a new Pods folder. Reopen the .xcworkspace file and try to build again.

3. Error: Framework not found

If you see the following error:

Framework not found shared_umbrella

You probably opened the .xcodeproj file instead of the .xcworkspace.
Close out the .xcodeproj and open the .xcworkspace and run again.