빠른 시작 | Jetpack Compose | Android Developers

컴포즈를 사용하기 전에 다음과 같은 주의사항이 있다.

새 프로젝트에 Compose 추가하기

새 프로젝트를 시작한다면, 프로젝트 메뉴에서 Compose 를 선택한다면 자동으로 Compose 가 추가된다.

기존 앱에 Compose 추가하기


Compose 사용설정하기

Compose를 사용하지 않았던 기존 App 에서 Compose 를 추가하려면 Build.gradle 에 다음과 같이 추가해야 된다.

android {
    buildFeatures {
        compose true //compose 기능 사용 설정
    }

    composeOptions {
        kotlinCompilerExtensionVersion = "1.3.2" 
				//Kotlin 컴파일러버전과 일치하는 Compose를 사용한다
    }
}

Compose 의존성 추가하기

Compose Bom과 필요한 Compose 라이브러리를 다음과 같이 추가한다.

dependencies {

    def composeBom = platform('androidx.compose:compose-bom:2022.12.00')
    implementation composeBom
    androidTestImplementation composeBom

    // Choose one of the following:
    // Material Design 3
    implementation 'androidx.compose.material3:material3'
    // or Material Design 2
    implementation 'androidx.compose.material:material'
    // or skip Material Design and build directly on top of foundational components
    implementation 'androidx.compose.foundation:foundation'
    // or only import the main APIs for the underlying toolkit systems,
    // such as input and measurement/layout
    implementation 'androidx.compose.ui:ui'

    // Android Studio Preview support
    implementation 'androidx.compose.ui:ui-tooling-preview'
    debugImplementation 'androidx.compose.ui:ui-tooling'

    // UI Tests
    androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
    debugImplementation 'androidx.compose.ui:ui-test-manifest'

    // Optional - Included automatically by material, only add when you need
    // the icons but not the material library (e.g. when using Material3 or a
    // custom design system based on Foundation)
    implementation 'androidx.compose.material:material-icons-core'
    // Optional - Add full set of material icons
    implementation 'androidx.compose.material:material-icons-extended'
    // Optional - Add window size utils
    implementation 'androidx.compose.material3:material3-window-size-class'

    // Optional - Integration with activities
    implementation 'androidx.activity:activity-compose:1.5.1'
    // Optional - Integration with ViewModels
    implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.5.1'
    // Optional - Integration with LiveData
    implementation 'androidx.compose.runtime:runtime-livedata'
    // Optional - Integration with RxJava
    implementation 'androidx.compose.runtime:runtime-rxjava2'

}