0

我正在嘗試運行GitHub(https://github.com/googlecodelabs/constraint-layout)上託管的培訓的示例程序。在包中找不到屬性'barrierDirection'的資源標識符 - ConstraintLayout Barrier

我更新了build.gradle來修復構建錯誤,但我無法讓它編譯和運行。我越來越

未發現屬性「barrierDirection」在 包「com.google.googleio」

在包中發現了 屬性「constraint_referenced_ids」沒有資源標識符資源標識符「com.google.googleio '

我正在使用Android Studio 2.3.3。

的build.gradle(模塊: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 - 代碼編譯,當我註釋掉android.support.constraint.Barrier運行標籤。

回答

9

Barrier不存在於constraint-layout庫的1.0.2中。它是1.1.0的一部分,目前處於測試狀態。你需要切換你的依賴回:

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

如果Android Studio中抱怨說,它無法找到該庫,請確保您的項目級build.gradle文件看起來像the one from the project,特別是具有谷歌的回購協議中allprojects配置:

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

我改變爲1.0.2,因爲由於沒有找到依賴關係的錯誤而無法編譯它。出於某種原因,它今天在1.1.0上發現它。謝謝! – ethan

+1

@ethan:AFAIK,'1.1.0-beta1'不在本地的'ConstraintLayout'版本庫中,但在Google Maven倉庫中,這是我答案中代碼片段添加到項目中的內容。 – CommonsWare

+2

'maven {url'https://maven.google.com'}'可以被'google()'替代(至少在Gradle插件的3.0.0版本中,仍然處於測試階段)。 –

相關問題