ツナドーナツ・技術メモ帳

色々なものを作る過程で分からなかったことなどを書いていきます

error: duplicate attribute.とは?

error: duplicate attribute.というエラーが初めて出てきたので一応メモ。
これは、AndroidXMLで宣言が重複しているというエラーです。
例えばこのコードでは、Bootstrapとandroidのlayout_constraintHorizontal_biasが重複して定義されています。

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="36dp"
        android:scaleType="center"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.659"<!-- ここと -->
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView3"
        app:srcCompat="@android:drawable/ic_menu_report_image"
        bootstrap:layout_constraintHorizontal_bias="0.5"<!-- ここ -->
        bootstrap:layout_constraintStart_toEndOf="@+id/progressBar" />

このように宣言が重複してしまうとbuildの段階で止まりますので、どちらか一方の宣言だけを残してあげれば動くようになります。
bootstrapでデザインを整えたいのであれば、android側の宣言を取り消してしまえばOKです。

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="36dp"
        android:scaleType="center"
        app:layout_constraintEnd_toEndOf="parent"
        <!-- コメントアウト -->
        <!-- app:layout_constraintHorizontal_bias="0.659" -->
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView3"
        app:srcCompat="@android:drawable/ic_menu_report_image"
        bootstrap:layout_constraintHorizontal_bias="0.5"<!-- bootstrapを使う -->
        bootstrap:layout_constraintStart_toEndOf="@+id/progressBar" />