Kotlin Multiplatform에는 라이브러리 모듈을 구성하는 Gradle 플러그인이 있습니다.
com.android.kotlin.multiplatform.library 플러그인은 일반 Android 라이브러리 Gradle 플러그인 (com.android.library)을 사용하여 KMP 라이브러리에 Android 타겟을 추가하는 이전 방법을 공식적으로 대체합니다.
이전 접근 방식은 이제 Android-KMP 플러그인이라고도 하는 플러그인으로 대체되어 지원 중단됩니다. KMP용 com.android.library 플러그인을 계속 사용하면 JetBrains에서 더 이상 지원하지 않으며 향후 업데이트 및 개선사항의 혜택을 누릴 수 없습니다.
Android-KMP 플러그인은 KMP 프로젝트에 맞게 특별히 조정되었으며 다음과 같은 여러 주요 측면에서 표준 com.android.library 플러그인과 다릅니다.
단일 변형 아키텍처: 플러그인은 단일 변형을 사용하여 제품 버전과 빌드 유형 지원을 삭제하므로 구성이 간소화되고 빌드 성능이 향상됩니다.
KMP에 최적화: 이 플러그인은 공유 Kotlin 코드와 상호 운용성에 중점을 두고 Android 전용 네이티브 빌드, AIDL, RenderScript 지원을 생략하여 KMP 라이브러리용으로 설계되었습니다.
기본적으로 사용 중지된 테스트: 빌드 속도를 높이기 위해 단위 테스트와 기기 (계측) 테스트가 모두 기본적으로 사용 중지됩니다. 필요한 경우 사용 설정할 수 있습니다.
최상위 Android 확장 프로그램 없음: 구성은 Gradle KMP DSL 내의 androidLibrary 블록으로 처리되어 일관된 KMP 프로젝트 구조를 유지합니다. 최상위 android 확장 프로그램 차단이 없습니다.
선택적 Java 컴파일: Java 컴파일은 기본적으로 사용 중지되어 있습니다. androidLibrary 블록에서 withJava()를 사용하여 사용 설정합니다. 이렇게 하면 Java 컴파일이 필요하지 않은 경우 빌드 시간이 개선됩니다.
Android-KMP 라이브러리 플러그인의 이점
Android-KMP 플러그인은 KMP 프로젝트에 다음과 같은 이점을 제공합니다.
빌드 성능 및 안정성 개선: KMP 프로젝트 내에서 최적화된 빌드 속도와 향상된 안정성을 위해 설계되었습니다. KMP 워크플로에 중점을 두어 더 효율적이고 안정적인 빌드 프로세스를 지원합니다.
향상된 IDE 통합: KMP Android 라이브러리로 작업할 때 더 나은 코드 완성, 탐색, 디버깅, 전반적인 개발자 환경을 제공합니다.
간소화된 프로젝트 구성: 이 플러그인은 빌드 변형과 같은 Android 관련 복잡성을 제거하여 KMP 프로젝트의 구성을 간소화합니다. 이렇게 하면 더 깔끔하고 유지관리 가능한 빌드 파일이 생성됩니다.
이전에는 KMP 프로젝트에서 com.android.library 플러그인을 사용하면 androidAndroidTest과 같은 혼동스러운 소스 세트 이름이 생성될 수 있었습니다. 이 명명 규칙은 표준 KMP 프로젝트 구조에 익숙한 개발자에게는 직관적이지 않았습니다.
기존 모듈에 Android-KMP 플러그인 적용
기존 KMP 라이브러리 모듈에 Android-KMP 플러그인을 적용하려면 다음 단계를 따르세요.
버전 카탈로그에서 플러그인 선언 버전 카탈로그 TOML 파일(일반적으로 gradle/libs.versions.toml)을 열고 플러그인 정의 섹션을 추가합니다.
# To check the version number of the latest Kotlin release, go to# https://kotlinlang.org/docs/releases.html[versions]androidGradlePlugin="8.12.0"kotlin="KOTLIN_VERSION"[plugins]kotlin-multiplatform={id="org.jetbrains.kotlin.multiplatform",version.ref="kotlin"}android-kotlin-multiplatform-library={id="com.android.kotlin.multiplatform.library",version.ref="androidGradlePlugin"}
루트 빌드 파일에 플러그인 선언을 적용합니다. 프로젝트의 루트 디렉터리에 있는 build.gradle.kts 파일을 엽니다. apply false을 사용하여 플러그인 별칭을 plugins 블록에 추가합니다. 이렇게 하면 플러그인 로직을 루트 프로젝트 자체에 적용하지 않고도 모든 하위 프로젝트에서 플러그인 별칭을 사용할 수 있습니다.
Kotlin
// Root build.gradle.kts fileplugins{alias(libs.plugins.kotlin.multiplatform)applyfalse// Add the followingalias(libs.plugins.android.kotlin.multiplatform.library)applyfalse}
Groovy
// Root build.gradle fileplugins{alias(libs.plugins.kotlin.multiplatform)applyfalse// Add the followingalias(libs.plugins.android.kotlin.multiplatform.library)applyfalse}
KMP 라이브러리 모듈 빌드 파일에 플러그인을 적용합니다. KMP 라이브러리 모듈에서 build.gradle.kts 파일을 열고 plugins 블록 내 파일 상단에 플러그인을 적용합니다.
Kotlin
// Module-specific build.gradle.kts fileplugins{alias(libs.plugins.kotlin.multiplatform)// Add the followingalias(libs.plugins.android.kotlin.multiplatform.library)}
Groovy
// Module-specific build.gradle fileplugins{alias(libs.plugins.kotlin.multiplatform)// Add the followingalias(libs.plugins.android.kotlin.multiplatform.library)}
Android KMP 타겟을 구성합니다. Android 타겟을 정의하도록 Kotlin Multiplatform 블록(kotlin)을 구성합니다. kotlin 블록 내에서 androidLibrary를 사용하여 Android 타겟을 지정합니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-08-21(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-08-21(UTC)"],[],[],null,["# Migrate to the Android-KMP library plugin\n\nKotlin Multiplatform has a Gradle plugin to configure the\n[library module](/studio/projects/android-library).\n\nThe `com.android.kotlin.multiplatform.library` plugin is the official\nreplacement for the previous method of adding Android targets to KMP libraries\nusing the regular Android library Gradle plugin (`com.android.library`).\n\nThe previous approach is now deprecated in favor of the plugin, also referred to\nas the **Android-KMP plugin** . Continuing to use the `com.android.library`\nplugin for KMP will no longer be supported by JetBrains and won't benefit from\nfuture updates and improvements.\n| **Note:** Configuring the Android **application** module using `com.android.application` doesn't change.\n\nTo migrate to this plugin, refer to the [Apply the Android-KMP plugin](#apply)\nsection.\n\nKey features and differences\n----------------------------\n\nThe Android-KMP plugin is tailored specifically for KMP projects and differs\nfrom the standard `com.android.library` plugin in several key aspects:\n\n- **Single variant architecture:** The plugin uses a single variant, removing\n support for product flavors and build types, which simplifies configuration\n and enhances build performance.\n\n- **Optimized for KMP:** The plugin is designed for KMP libraries, focusing on\n shared Kotlin code and interoperability, omitting support for\n Android-specific native builds, AIDL, and RenderScript.\n\n- **Tests disabled by default:** Both unit and device (instrumentation) tests\n are disabled by default to enhance build speed. You can enable them if\n required.\n\n- **No top-Level Android extension:** Configuration is handled with an\n `androidLibrary` block within the Gradle KMP DSL, maintaining a consistent\n KMP project structure. There's no top-level `android` extension block.\n\n- **Opt-in Java compilation:** Java compilation is disabled by default. Use\n `withJava()` in the `androidLibrary` block to enable it. This improves build\n times when Java compilation is not needed.\n\nBenefits of the Android-KMP library plugin\n------------------------------------------\n\nThe Android-KMP plugin provides the following benefits for KMP projects:\n\n- **Improved build performance and stability:** It's engineered for optimized\n build speeds and enhanced stability within KMP projects. It's focus on KMP\n workflows contribute to a more efficient and reliable build process.\n\n- **Enhanced IDE integration:** It provides better code completion,\n navigation, debugging, and overall developer experience when working with\n KMP Android libraries.\n\n- **Simplified project configuration:** The plugin simplifies configuration\n for KMP projects by removing Android-specific complexities like build\n variants. This leads to cleaner and more maintainable build files.\n Previously, using the `com.android.library` plugin in KMP project could\n create confusing source set names, such as `androidAndroidTest`. This naming\n convention was less intuitive for developers familiar with standard KMP\n project structures.\n\nApply the Android-KMP plugin to an existing module\n--------------------------------------------------\n\nTo apply the Android-KMP plugin to an existing KMP library module, follow these\nsteps:\n\n1. **Declare plugins in version catalog.** Open the version catalog TOML file\n (usually `gradle/libs.versions.toml`) and add the plugin definitions\n section:\n\n # To check the version number of the latest Kotlin release, go to\n # https://kotlinlang.org/docs/releases.html\n\n [versions]\n androidGradlePlugin = \"8.12.0\"\n kotlin = \"\u003cvar translate=\"no\"\u003eKOTLIN_VERSION\u003c/var\u003e\"\n\n [plugins]\n kotlin-multiplatform = { id = \"org.jetbrains.kotlin.multiplatform\", version.ref = \"kotlin\" }\n android-kotlin-multiplatform-library = { id = \"com.android.kotlin.multiplatform.library\", version.ref = \"androidGradlePlugin\" }\n\n2. **Apply the plugin declaration in root build file.** Open the\n `build.gradle.kts` file located in the root directory of your project. Add\n the plugin aliases to the `plugins` block using `apply false`. This makes\n the plugin aliases available to all subprojects without applying the plugin\n logic to the root project itself.\n\n ### Kotlin\n\n ```kotlin\n // Root build.gradle.kts file\n\n plugins {\n alias(libs.plugins.kotlin.multiplatform) apply false\n\n // Add the following\n alias(libs.plugins.android.kotlin.multiplatform.library) apply false\n }\n ```\n\n ### Groovy\n\n ```groovy\n // Root build.gradle file\n\n plugins {\n alias(libs.plugins.kotlin.multiplatform) apply false\n\n // Add the following\n alias(libs.plugins.android.kotlin.multiplatform.library) apply false\n }\n ```\n3. **Apply the plugin in a KMP library module build file.** Open the\n `build.gradle.kts` file in your KMP library module and apply the plugin at\n the top of your file within the `plugins` block:\n\n ### Kotlin\n\n ```kotlin\n // Module-specific build.gradle.kts file\n\n plugins {\n alias(libs.plugins.kotlin.multiplatform)\n\n // Add the following\n alias(libs.plugins.android.kotlin.multiplatform.library)\n }\n ```\n\n ### Groovy\n\n ```groovy\n // Module-specific build.gradle file\n\n plugins {\n alias(libs.plugins.kotlin.multiplatform)\n\n // Add the following\n alias(libs.plugins.android.kotlin.multiplatform.library)\n }\n ```\n4. **Configure Android KMP target.** Configure the Kotlin Multiplatform block\n (`kotlin`) to define the Android target. Within the `kotlin` block, specify\n the Android target using `androidLibrary`:\n\n ### Kotlin\n\n ```kotlin\n kotlin {\n androidLibrary {\n namespace = \"com.example.kmpfirstlib\"\n compileSdk = 33\n minSdk = 24\n\n withJava() // enable java compilation support\n withHostTestBuilder {}.configure {}\n withDeviceTestBuilder {\n sourceSetTreeName = \"test\"\n }\n\n compilations.configureEach {\n compilerOptions.configure {\n jvmTarget.set(\n org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8\n )\n }\n }\n }\n\n sourceSets {\n androidMain {\n dependencies {\n // Add Android-specific dependencies here\n }\n }\n getByName(\"androidHostTest\") {\n dependencies {\n }\n }\n\n getByName(\"androidDeviceTest\") {\n dependencies {\n }\n }\n }\n // ... other targets (JVM, iOS, etc.) ...\n }\n ```\n\n ### Groovy\n\n ```groovy\n kotlin {\n androidLibrary {\n namespace = \"com.example.kmpfirstlib\"\n compileSdk = 33\n minSdk = 24\n\n withJava() // enable java compilation support\n withHostTestBuilder {}.configure {}\n withDeviceTestBuilder {\n it.sourceSetTreeName = \"test\"\n }\n\n compilations.configureEach {\n compilerOptions.options.jvmTarget.set(\n org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8\n )\n }\n }\n\n sourceSets {\n androidMain {\n dependencies {\n }\n }\n androidHostTest {\n dependencies {\n }\n }\n androidDeviceTest {\n dependencies {\n }\n }\n }\n // ... other targets (JVM, iOS, etc.) ...\n }\n ```\n5. **Apply changes.** After applying the plugin and configuring the `kotlin`\n block, sync your Gradle project to apply the changes.\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Set up your environment](/kotlin/multiplatform/setup)\n- [Add KMP module to a project](/kotlin/multiplatform/migrate)"]]