Code Monkey home page Code Monkey logo

kotlin-multiplatform-template's Introduction

This is a Compose Multiplatform application.

Note The iOS part of Compose Multiplatform is in Alpha. It may change incompatibly and require manual migration in the future. If you have any issues, please report them on GitHub.

PS This template is a fork from Jetbrains' compose multiplatform template

Set up the environment

Warning You need a Mac with macOS to write and run iOS-specific code on simulated or real devices. This is an Apple requirement.

To work with this project, you need the following:

Check your environment

Before you start, use the KDoctor tool to ensure that your development environment is configured correctly:

  1. Install KDoctor with Homebrew:

    brew install kdoctor
    
  2. Run KDoctor in your terminal:

    kdoctor
    

    If everything is set up correctly, you'll see valid output:

    Environment diagnose (to see all details, use -v option):
    [✓] Operation System
    [✓] Java
    [✓] Android Studio
    [✓] Xcode
    [✓] Cocoapods
    
    Conclusion:
      ✓ Your system is ready for Kotlin Multiplatform Mobile development!
    

Otherwise, KDoctor will highlight which parts of your setup still need to be configured and will suggest a way to fix them.

Examine the project structure

Open the project in Android Studio and switch the view from Android to Project to see all the files and targets belonging to the project:

Your Compose Multiplatform project includes 4 modules:

shared

This is a Kotlin module that contains the logic common for desktop, Android, and iOS applications, that is, the code you share between platforms.

This shared module is also where you'll write your Compose Multiplatform code. In shared/src/commonMain/kotlin/App.kt, you can find the shared root @Composable function for your app.

It uses Gradle as the build system. You can add dependencies and change settings in shared/build.gradle.kts. The shared module builds into a Java library, an Android library, and an iOS framework.

desktopApp

This is a Kotlin module that builds into a desktop application. It uses Gradle as the build system. The desktopApp module depends on and uses the shared module as a regular library.

androidApp

This is a Kotlin module that builds into an Android application. It uses Gradle as the build system. The androidApp module depends on and uses the shared module as a regular Android library.

iosApp

This is an Xcode project that builds into an iOS application. It depends on and uses the shared module as a CocoaPods dependency.

Run your application

On desktop

To run your desktop application in Android Studio, select desktopApp in the list of run configurations and click Run:


You can also run Gradle tasks in the terminal:

  • ./gradlew run to run application
  • ./gradlew package to store native distribution into build/compose/binaries

On Android

To run your application on an Android emulator:

  1. Ensure you have an Android virtual device available. Otherwise, create one.

  2. In the list of run configurations, select androidApp.

  3. Choose your virtual device and click Run:


Alternatively, use Gradle

To install an Android application on a real Android device or an emulator, run ./gradlew installDebug in the terminal.

On iOS

Running on a simulator

To run your application on an iOS simulator in Android Studio, modify the iosApp run configuration:

  1. In the list of run configurations, select Edit Configurations:

  2. Navigate to iOS Application | iosApp.

  3. In the Execution target list, select your target device. Click OK:

  4. The iosApp run configuration is now available. Click Run next to your virtual device:

Running on a real iOS device

You can run your Compose Multiplatform application on a real iOS device for free. To do so, you'll need the following:

  • The TEAM_ID associated with your Apple ID
  • The iOS device registered in Xcode

Note Before you continue, we suggest creating a simple "Hello, world!" project in Xcode to ensure you can successfully run apps on your device. You can follow the instructions below or watch this Stanford CS193P lecture recording.

How to create and run a simple project in Xcode
  1. On the Xcode welcome screen, select Create a new project in Xcode.
  2. On the iOS tab, choose the App template. Click Next.
  3. Specify the product name and keep other settings default. Click Next.
  4. Select where to store the project on your computer and click Create. You'll see an app that displays "Hello, world!" on the device screen.
  5. At the top of your Xcode screen, click on the device name near the Run button.
  6. Plug your device into the computer. You'll see this device in the list of run options.
  7. Choose your device and click Run.
Finding your Team ID

In the terminal, run kdoctor --team-ids to find your Team ID. KDoctor will list all Team IDs currently configured on your system, for example:

3ABC246XYZ (Max Sample)
ZABCW6SXYZ (SampleTech Inc.)
Alternative way to find your Team ID

If KDoctor doesn't work for you, try this alternative method:

  1. In Android Studio, run the iosApp configuration with the selected real device. The build should fail.
  2. Go to Xcode and select Open a project or file.
  3. Navigate to the iosApp/iosApp.xcworkspace file of your project.
  4. In the left-hand menu, select iosApp.
  5. Navigate to Signing & Capabilities.
  6. In the Team list, select your team.

If you haven't set up your team yet, use the Add account option and follow the steps.

To run the application, set the TEAM_ID:

  1. In the template, navigate to the iosApp/Configuration/Config.xcconfig file.
  2. Set your TEAM_ID.
  3. Re-open the project in Android Studio. It should show the registered iOS device in the iosApp run configuration.

How to configure the iOS application

To get a better understanding of this project's setup and learn how to configure the basic properties of your iOS app without Xcode, open the iosApp/Configuration/Config.xcconfig file in Android Studio. The configuration file contains:

To configure the APP_NAME option, open Config.xcconfig in any text editor before opening the project in Android Studio, and then set the desired name.

If you need to change this option after you open the project in Android Studio, do the following:

  1. Close the project in Android Studio.
  2. Run ./cleanup.sh in your terminal.
  3. Change the setting.
  4. Open the project in Android Studio again.

To configure advanced settings, use Xcode. After opening the project in Android Studio, open the iosApp/iosApp.xcworkspace file in Xcode and make changes there.

Hooray 🥳

Now you are ready to fly ✈️, this project was configured, built and made with ❤️ by Ahmed Nassar, for any questions, enhancements, new feature enquiries or bug fixes please head to Issues Section and don't hesitate to share with me your thoughts 👀.

Happy coding 💻.

kotlin-multiplatform-template's People

Contributors

ranger163 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

kotlin-multiplatform-template's Issues

Add support for general logger

Is your feature request related to a problem? Please describe.
Yes, we need to add logger for logging events that happen in the app.

Describe the solution you'd like
Use Napier logger would be good.

Move "app" from suffix to prefix in native modules

It would be nice to have "app" as prefix, not a suffix for native modules by default in template - that way they will be grouped together in a project / IDE / filesystem browser and not spread across other folders

e.g.

  • androidApp -> appAndroid or app-android
  • iosApp -> appIos or app-Ios
  • desktopApp -> appDesktop or app-desktop

Thanks!

Add support for the web (WASM) target

Would be great to add the web (WASM) support too, to complete the list of supported platforms.

P.S. Do you accept PR's if I add this (and can also address the neighbour feature request for renaming the native modules folders too) ?

Add support for app theme and dark theme

Is your feature request related to a problem? Please describe.
Yes, we need support for app themes like dark and light themes.

Describe the solution you'd like
Implementing app themes that has different color implementations for dark and light modes.

Handling versions and dependencies in a better way

Is your feature request related to a problem? Please describe.
Not exactly, but the versions file needs to be more organized.

Describe the solution you'd like
Need to organize versions and dependencies files to be more categories instead of being all together.

Describe alternatives you've considered
NA

Additional context
NA

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.