Android gradle: Failed to resolve: androidx.compose.material3:material3 using BOM from lib.versions.toml
Asked Answered
S

1

7

I have an android (compose) projet with a single libs.versions.toml for versions catalog.

In this .toml, I declare a compose BOM and some librairies as follow:


[versions]
ksp = "1.9.10-1.0.13"
...
androidxComposeBom = "2023.10.01"

[libraries]
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "androidxComposeBom" }
androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" }
...
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3"}
androidx-compose-material3-windowSizeClass = { group = "androidx.compose.material3", name = "material3-window-size-class" }

When I do this, I get an error on 'Failed to resolve: androidx.compose.material3:material3' and 'Failed to resolve: androidx.compose.material3:material3-window-size-class'.

I only get an error on material3 libs, not 'ui' or others that have their versions in the BOM

if I specify a version as follow, it works:


[versions]
material3VersionHack = "1.1.2"

[libraries]
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "material3VersionHack"}

BUT that defeat the purpose of the BOM: avoid specifying each version...

according to https://developer.android.com/jetpack/compose/bom/bom-mapping the material3 is defined with a 1.1.2 version for BOM 2023.10.01 so what?

=> Why do I need to specify the version manually for material3? is there a way to rely on version defined by the current BOM?

Succor answered 29/10, 2023 at 19:53 Comment(3)
When you use BOM you done need to specify the version if you really wanted to override the version then and then only you have to define the version manually otherwise it will automatically select versionRecuperator
@ChiragThummar I agree with you, and in this case, V1.1.2 is the version specified in the BOM so I should not need to override it manually. And more than that: when I will update the BOM, I don't want to update material3 manually (or forget it)... but without specifying the version, I get the error and that is all the point of the question: why? :-)Succor
I am facing the same issue right now. I think could be with the name of 'material3-window-size-class' because "class" is a keyword in kotlin, (at least Android Studio mark this as keyword writing it in a .kts file). A tried without using the .libs.version.toml file and everything is fine: ``` implementation("androidx.compose.material3:material3:1.2.1") implementation("androidx.compose.material3:material3-window-size-class:1.2.1") ```Humility
M
0

you need to add both bom and meterial 3

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

    // Material Design 3
    implementation 'androidx.compose.material3:material3'
Meant answered 29/7 at 9:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.