Search code examples
androidxmlgradleandroid-motionlayout

MotionLayout class not found or attribute layoutDescription not found


I'm trying to follow a google tutorial for MotionLayout and can't seem to be able to build the project or even find the class.

Here is the xml

<androidx.constraintlayout.motion.widget.MotionLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    app:layoutDescription="@xml/step1_completed">

<ImageView
        android:id="@+id/red_star"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/ic_star_outline"
        android:tint="?colorSecondary"
        android:contentDescription="@string/star"
        android:layout_marginTop="30dp"
        android:layout_marginStart="30dp"
        android:layout_marginBottom="30dp"
        android:layout_marginEnd="30dp"/>

</androidx.constraintlayout.motion.widget.MotionLayout>

here are the dependecies

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta3'
    api 'com.google.android.material:material:1.2.0-alpha03'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

an here is what I get when trying to run

AAPT: error: attribute layoutDescription (aka com.google.samples.motionlayoutcodelab:layoutDescription) not found.

Thanks


Solution

  • Use the AndroidX version of the dependency:

    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'