Data binding: Attribute is missing the Androld namespace prefix

Viewed 3570

Android Studio 3.0

classpath 'com.android.tools.build:gradle:3.0.1'

set

  dataBinding {
        enabled = true
    }

I want to use data binding.

Here my xml layout:

<?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:layout_width="match_parent"
    android:layout_height="wrap_content">

    <data>
        <variable
            name="offer"  type="com.myproject.customer.Offer" />
    </data>

</android.support.constraint.ConstraintLayout>

But I get error:

Attribute is missing the Android namespace prefix
1 Answers

Your data-binding XML root should be layout tag

From Docs

Data-binding layout files are slightly different and start with a root tag of layout followed by a data element and a view root element. This view element is what your root would be in a non-binding layout file.

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
   <data>
       <variable name="user" type="com.example.User"/>
   </data>

  <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:layout_width="match_parent"
      android:layout_height="wrap_content">

  </android.support.constraint.ConstraintLayout>

</layout>
Related