환경 설정 (Kotlin 멀티플랫폼)
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Kotlin 멀티플랫폼 (KMP)을 사용하면 여러 플랫폼에서 Kotlin 코드를 공유할 수 있습니다. KMP로 앱 빌드를 시작하기 전에 이 문서에 설명된 대로 환경을 설정해야 합니다. JetBrain의 공식 문서를 참고할 수도 있습니다.
필수 도구 설치 또는 업데이트
- Android 스튜디오의 최신 안정화 버전을 설치하거나 업데이트합니다.
- 호환성 문제를 방지하려면 Android 스튜디오와 번들로 제공되는 Kotlin 플러그인을 최신 버전으로 업데이트하세요.
- (선택사항) iOS 개발의 경우 Xcode를 설치하여 UI를 빌드하고 필요에 따라 Swift 또는 Objective-C 코드를 추가합니다.
Kotlin 멀티플랫폼 프로젝트 만들기
JetBrains의 Kotlin 멀티플랫폼 마법사를 사용하여 새 KMP 프로젝트를 만들 수 있습니다. UI를 네이티브로 유지하려면 UI 공유 안 함 옵션을 선택해야 합니다.
프로젝트 구조
KMP 프로젝트는 Android 프로젝트와 유사한 프로젝트 구조를 따릅니다.
KMP 프로젝트에는 공유 모듈과 함께 플랫폼별 모듈이 포함됩니다.
관련 모듈에 플랫폼별 코드를 추가합니다. 예를 들어 androidApp 모듈에 Android 앱 UI를 추가하고 iosApp에 iOS 앱 UI를 추가합니다.
플랫폼 간에 공유하려는 모든 코드는 shared 모듈에 포함됩니다.
공유 모듈은 나머지 프로젝트와 마찬가지로 Gradle을 빌드 시스템으로 사용합니다. 소스 세트를 사용하여 공통 및 플랫폼별 종속 항목을 선언할 수 있습니다. 예를 들어 앱에서 네트워킹에 Ktor를 사용하는 경우 Android용 OkHttp 종속 항목과 iOS용 darwin 종속 항목을 추가해야 합니다. 일부 라이브러리에는 공통 종속 항목만 필요하고 플랫폼별 종속 항목은 필요하지 않습니다.
sourceSets {
commonMain.dependencies {
//put your multiplatform dependencies here
//...
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.content.negotiation)
implementation(libs.ktor.serialization.kotlinx.json)
//...
}
androidMain.dependencies {
implementation(libs.ktor.client.okhttp)
}
iosMain.dependencies {
implementation(libs.ktor.client.darwin)
}
}
앱의 공유 모듈에 새 라이브러리를 추가할 때는 각 플랫폼에 필요한 종속 항목을 확인해야 합니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Setup your environment (Kotlin Multiplatform)\n\n[Kotlin Multiplatform](https://kotlinlang.org/lp/mobile/) (KMP) enables sharing Kotlin code across\ndifferent platforms. Before you start building apps with KMP, you'll need to\nset up your environment as described in this document. You can also refer to\nJetBrain's [official documentation](https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-setup.html).\n\nInstall or update required tools\n--------------------------------\n\n- Install or update to the latest stable version of [Android Studio](/studio).\n- Update the [Kotlin plugin](https://kotlinlang.org/docs/releases.html#update-to-a-new-release) that is bundled with Android Studio to the latest version to avoid compatibility issues.\n- (Optional) For iOS development, install [Xcode](https://apps.apple.com/us/app/xcode/id497799835) to build the UI and add Swift or Objective-C code as needed.\n\nCreate a Kotlin Multiplatform project\n-------------------------------------\n\nYou can use the [Kotlin Multiplatform wizard](https://kmp.jetbrains.com/) from JetBrains to\ncreate a new KMP project. Make sure to choose the **Do not\nshare UI** option to keep the UI native.\n\n### Project structure\n\nKMP projects follow a project structure similar to Android projects.\n\nA KMP project contains platform-specific modules along with a shared module.\nAdd your platform-specific code to the relevant module. For example, add your\nAndroid app UI in the **androidApp** module and your iOS app UI in **iosApp** .\nAny code you want to share between platforms goes in the **shared** module.\n\nThe shared module uses Gradle as the build system just like the rest of the\nproject. You can declare common and platform-specific dependencies using\nsourcesets. For example, if your app uses Ktor for networking, you need to add\nan OkHttp dependency for Android and a darwin dependency for iOS. Note that some\nlibraries require only common dependencies and don't need platform-specific\ndependencies. \n\n sourceSets {\n commonMain.dependencies {\n //put your multiplatform dependencies here\n //...\n implementation(libs.ktor.client.core)\n implementation(libs.ktor.client.content.negotiation)\n implementation(libs.ktor.serialization.kotlinx.json)\n //...\n }\n androidMain.dependencies {\n implementation(libs.ktor.client.okhttp)\n }\n iosMain.dependencies {\n implementation(libs.ktor.client.darwin)\n }\n }\n\nWhen you add a new library to your app's shared module, make sure to check for\nthe required dependencies for each platform."]]