No resource identifier found for attribute 'barrierDirection' in package - ConstraintLayout Barrier

2.8k views Asked by At

I am trying to run a sample program for a training hosted at GitHub (https://github.com/googlecodelabs/constraint-layout).

I updated the build.gradle to fix build errors, but I cannot get it to compile and run. I am getting

No resource identifier found for attribute 'barrierDirection' in package 'com.google.googleio'

No resource identifier found for attribute 'constraint_referenced_ids' in package 'com.google.googleio'

I am using Android Studio 2.3.3.

build.gradle (Module: app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "com.google.googleio"
        minSdkVersion 22
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
}

activity_main_done.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    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:id="@+id/activity_main_done"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_editor_absoluteX="0dp"
    app:layout_editor_absoluteY="80dp"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="80dp">

    <ImageView
        android:src="@drawable/singapore"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_editor_absoluteX="0dp"
        app:layout_editor_absoluteY="0dp"
        android:id="@+id/header"
        android:scaleType="centerCrop"
        android:contentDescription="@string/placeholder"
        app:layout_constraintLeft_creator="1"
        app:layout_constraintTop_creator="1"
        app:layout_constraintRight_creator="1"
        app:layout_constraintBottom_creator="1"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="0dp"
        app:layout_constraintLeft_toLeftOf="@+id/activity_main_done"
        tools:layout_constraintLeft_creator="1"
        app:layout_constraintTop_toTopOf="@+id/activity_main_done"
        tools:layout_constraintTop_creator="1"
        app:layout_constraintRight_toRightOf="@+id/activity_main_done"
        tools:layout_constraintRight_creator="1"
        app:layout_constraintBottom_toBottomOf="@+id/favorite"
        android:layout_marginBottom="16dp"
        tools:layout_constraintBottom_creator="1"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintVertical_bias="0.0" />

    <ImageView
        android:src="@drawable/ic_star"
        android:layout_width="36dp"
        android:layout_height="36dp"
        app:layout_editor_absoluteX="359dp"
        app:layout_editor_absoluteY="104dp"
        android:id="@+id/favorite"
        android:background="@drawable/info_background"
        android:padding="5dp"
        android:contentDescription="@string/placeholder"
        app:layout_constraintTop_creator="1"
        app:layout_constraintRight_creator="1"
        app:layout_constraintBottom_creator="0"
        tools:layout_editor_absoluteX="359dp"
        tools:layout_editor_absoluteY="104dp"
        app:layout_constraintTop_toTopOf="@+id/activity_main_done"
        tools:layout_constraintTop_creator="0"
        app:layout_constraintRight_toRightOf="@+id/activity_main_done"
        android:layout_marginEnd="16dp"
        tools:layout_constraintRight_creator="0"
        app:layout_constraintBottom_toBottomOf="@+id/activity_main_done"
        android:layout_marginBottom="16dp"
        tools:layout_constraintBottom_creator="0"
        app:layout_constraintVertical_bias="0.19" />

    <TextView
        android:text="@string/singapore"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_editor_absoluteX="16dp"
        app:layout_editor_absoluteY="140dp"
        android:id="@+id/title"
        android:textSize="24sp"
        app:layout_constraintLeft_creator="1"
        app:layout_constraintTop_creator="0"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="140dp"
        app:layout_constraintLeft_toLeftOf="@+id/activity_main_done"
        android:layout_marginStart="16dp"
        tools:layout_constraintLeft_creator="0"
        app:layout_constraintTop_toBottomOf="@+id/header"
        android:layout_marginTop="16dp"
        tools:layout_constraintTop_creator="0" />

    <EditText
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:text="@string/camera_value"
        android:ems="10"
        app:layout_editor_absoluteX="73dp"
        app:layout_editor_absoluteY="176dp"
        android:id="@+id/cameraType"
        app:layout_constraintLeft_creator="1"
        app:layout_constraintTop_creator="1"
        app:layout_constraintRight_creator="1"
        app:layout_constraintLeft_toLeftOf="@+id/settings"
        tools:layout_constraintLeft_creator="1"
        app:layout_constraintTop_toBottomOf="@+id/title"
        android:layout_marginTop="8dp"
        tools:layout_constraintTop_creator="0"
        app:layout_constraintRight_toRightOf="@+id/settings"
        tools:layout_constraintRight_creator="1"
        app:layout_constraintStart_toEndOf="@+id/labelBarrier"
        android:layout_marginStart="8dp" />

    <TextView
        android:text="@string/camera"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_editor_absoluteX="16dp"
        app:layout_editor_absoluteY="189dp"
        android:id="@+id/cameraLabel"
        android:labelFor="@+id/cameraType"
        app:layout_constraintLeft_creator="1"
        app:layout_constraintBaseline_creator="1"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="189dp"
        app:layout_constraintLeft_toLeftOf="@+id/activity_main_done"
        android:layout_marginStart="16dp"
        tools:layout_constraintLeft_creator="0"
        app:layout_constraintBaseline_toBaselineOf="@+id/cameraType"
        tools:layout_constraintBaseline_creator="0" />

    <TextView
        android:text="@string/settings"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_editor_absoluteX="16dp"
        app:layout_editor_absoluteY="238dp"
        android:id="@+id/settingsLabel"
        android:labelFor="@+id/settings"
        app:layout_constraintLeft_creator="1"
        app:layout_constraintBaseline_creator="1"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="238dp"
        app:layout_constraintLeft_toLeftOf="@+id/activity_main_done"
        android:layout_marginStart="16dp"
        tools:layout_constraintLeft_creator="0"
        app:layout_constraintBaseline_toBaselineOf="@+id/settings"
        tools:layout_constraintBaseline_creator="0" />

    <android.support.constraint.Barrier
        android:id="@+id/labelBarrier"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:barrierDirection="end"
        app:constraint_referenced_ids="cameraLabel,settingsLabel" />

    <EditText
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:text="@string/camera_settings"
        android:ems="10"
        app:layout_editor_absoluteX="73dp"
        app:layout_editor_absoluteY="225dp"
        android:id="@+id/settings"
        app:layout_constraintLeft_creator="1"
        app:layout_constraintTop_creator="1"
        app:layout_constraintRight_creator="1"
        tools:layout_constraintLeft_creator="1"
        app:layout_constraintTop_toBottomOf="@+id/cameraType"
        android:layout_marginTop="8dp"
        tools:layout_constraintTop_creator="0"
        app:layout_constraintRight_toRightOf="@+id/description"
        tools:layout_constraintRight_creator="1"
        app:layout_constraintStart_toEndOf="@+id/labelBarrier"
        android:layout_marginStart="8dp" />

    <Button
        android:text="@string/upload"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_editor_absoluteX="307dp"
        app:layout_editor_absoluteY="538dp"
        android:id="@+id/upload"
        app:layout_constraintRight_creator="1"
        app:layout_constraintBottom_creator="1"
        tools:layout_editor_absoluteX="307dp"
        tools:layout_editor_absoluteY="538dp"
        app:layout_constraintRight_toRightOf="@+id/activity_main_done"
        android:layout_marginEnd="16dp"
        tools:layout_constraintRight_creator="0"
        app:layout_constraintBottom_toBottomOf="@+id/activity_main_done"
        android:layout_marginBottom="16dp"
        tools:layout_constraintBottom_creator="0" />

    <Button
        android:text="@string/discard"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_editor_absoluteX="211dp"
        app:layout_editor_absoluteY="538dp"
        android:id="@+id/discard"
        android:elevation="0dp"
        app:layout_constraintRight_creator="0"
        app:layout_constraintBaseline_creator="1"
        tools:layout_editor_absoluteX="211dp"
        tools:layout_editor_absoluteY="538dp"
        app:layout_constraintRight_toLeftOf="@+id/upload"
        android:layout_marginEnd="8dp"
        tools:layout_constraintRight_creator="0"
        app:layout_constraintBaseline_toBaselineOf="@+id/upload"
        tools:layout_constraintBaseline_creator="0" />

    <TextView
        android:text="@string/singapore_description"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_editor_absoluteX="16dp"
        app:layout_editor_absoluteY="274dp"
        android:id="@+id/description"
        android:fadingEdge="vertical"
        android:ellipsize="end"
        android:textSize="15sp"
        app:layout_constraintLeft_creator="1"
        app:layout_constraintTop_creator="0"
        app:layout_constraintRight_creator="1"
        app:layout_constraintBottom_creator="0"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="274dp"
        app:layout_constraintLeft_toLeftOf="@+id/activity_main_done"
        android:layout_marginStart="16dp"
        tools:layout_constraintLeft_creator="1"
        app:layout_constraintTop_toBottomOf="@+id/settings"
        android:layout_marginTop="8dp"
        tools:layout_constraintTop_creator="1"
        app:layout_constraintRight_toRightOf="@+id/activity_main_done"
        android:layout_marginEnd="16dp"
        tools:layout_constraintRight_creator="1"
        app:layout_constraintBottom_toTopOf="@+id/discard"
        android:layout_marginBottom="8dp"
        tools:layout_constraintBottom_creator="1" />

</android.support.constraint.ConstraintLayout>

FYI - The code compiles and runs when I comment out the android.support.constraint.Barrier tag.

1

There are 1 answers

3
CommonsWare On BEST ANSWER

Barrier does not exist in 1.0.2 of the constraint-layout library. It is part of 1.1.0, presently in beta state. You need to switch your dependency back to:

compile 'com.android.support.constraint:constraint-layout:1.1.0-beta1'

If Android Studio complains that it cannot find this library, make sure that your project-level build.gradle file looks like the one from the project, specifically having the Google repo configured in allprojects:

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com'
        }
    }
}