Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is 'androidx.constraintlayout:constraintlayout' omittable?

I notice that I can comment out implementation 'androidx.constraintlayout:constraintlayout:2.0.4' without any errors though I use ConstraintLayout in my app.

dependencies {
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    // implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.navigation:navigation-fragment:2.3.3'
}

Why is it ok? Does the com.google.android.material library also contain constraintLayout?

like image 503
hata Avatar asked Jun 22 '26 19:06

hata


2 Answers

It's indeed coming from com.google.android.material:material:1.3.0 - but when you don't declare it explicitly, you'll build against version 2.0.1 - instead of the current version 2.0.4.

Just run ./gradlew app:dependencies to see that it will resolve a different version.


Disclaimer: I'm not exactly sure why these dependencies are rather dated
... but generally one could exclude them, so that one has to provide them:

implementation ("com.google.android.material:material:1.3.0") {
    exclude group: "androidx.annotation"       // 1.0.1 < 1.1.0
    exclude group: "androidx.appcompat"        // 1.1.0 < 1.2.0
    exclude group: "androidx.constraintlayout" // 2.0.1 < 2.0.4
    exclude group: "androidx.core"             // 1.2.0 < 1.3.2
    exclude group: "androidx.fragment"         // 1.0.0 < 1.3.0
    exclude group: "androidx.lifecycle"        // 2.0.0 < 2.3.0
    exclude group: "androidx.recyclerview"     // 1.0.0 < 1.1.0
    exclude group: "androidx.transition"       // 1.2.0 < 1.4.0
}

implementation "androidx.annotation:annotation:1.1.0"
implementation "androidx.appcompat:appcompat:1.2.0"
implementation "androidx.constraintlayout:constraintlayout:2.0.4"
implementation "androidx.core:core:1.3.2"
implementation "androidx.fragment:fragment:1.3.0"
implementation "androidx.lifecycle:lifecycle-runtime:2.3.0"
implementation "androidx.recyclerview:recyclerview:1.1.0"
implementation "androidx.transition:transition:1.4.0"

That's at least what Maven Central says; I'm assuming no side-effects.

like image 175
Martin Zeitler Avatar answered Jun 28 '26 07:06

Martin Zeitler


Yes, implementation 'com.google.android.material:material:1.3.0' contain constraintLayout.

like image 36
NRUSINGHA MOHARANA Avatar answered Jun 28 '26 08:06

NRUSINGHA MOHARANA



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!