Ji Sungbin
Ji Sungbin

Reputation: 1301

How each Compose dependency affects the Compose project

Jetpack Compose official documentation says there are 7 dependencies:

compose.animation
compose.compiler
compose.foundation
compose.material
compose.material3
compose.runtime
compose.ui

But I can use all Composable and animation functions of Compose without adding dependencies of compose.animation and compose.foundation among them. I added the dependencies like this:

val compose = listOf(
    "androidx.compose.ui:ui:${Versions.Compose.Master}",
    "androidx.compose.ui:ui-tooling:${Versions.Compose.Master}",
    "androidx.compose.compiler:compiler:${Versions.Compose.Master}",
    "androidx.compose.material:material:${Versions.Compose.Master}",
    "androidx.activity:activity-compose:${Versions.Compose.Activity}",
    "androidx.compose.runtime:runtime-livedata:${Versions.Compose.Master}",
    "androidx.lifecycle:lifecycle-viewmodel-compose:${Versions.Compose.Lifecycle}"
)

Is there any benefit to the project by adding all Compose dependencies?

Upvotes: 0

Views: 441

Answers (1)

Yshh
Yshh

Reputation: 832

jetpack compose level:

material(Button,Text,...) -> foundation(Column,Image,...) -> animation(Animatable,animateXXAsState,...) -> ui(Alignment,Modifier,...) -> runtime(remember,State,...)

Therefore, the content of the advanced package you refer to will contain subordinate content. For example, the material you refer to will contain foundation, animation, UI and runtime, so you only need to refer to the material, if your project does not intend to use the material style, you only need to import the foundation

compose compiler layer is actually kotlin compiler plugin,You don't need to introduce dependencies

  composeOptions {
        kotlinCompilerExtensionVersion compose_version
        kotlinCompilerVersion kotlin_version
    }

please try

val compose = listOf(
    "androidx.compose.ui:ui-tooling:${Versions.Compose.Master}",
    "androidx.compose.material:material:${Versions.Compose.Master}",
    "androidx.activity:activity-compose:${Versions.Compose.Activity}",
    "androidx.compose.runtime:runtime-livedata:${Versions.Compose.Master}",
    "androidx.lifecycle:lifecycle-viewmodel-compose:${Versions.Compose.Lifecycle}"
)
composeOptions {
            kotlinCompilerExtensionVersion compose_version
            kotlinCompilerVersion kotlin_version
        }

Upvotes: 2

Related Questions