Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Data Binding XML Error

I'm using Data Binding Library on a Android Studio Project when whenever I build, run, clean, rebuild, etc I get the following error:

 :app:processDebugResources AGPBI:

{"kind":"error","text":"Error parsing XML: duplicate attribute","sources": [{"file":"C:\\Users\\lucia.beltran\\Desktop\\Picho\\Projects\\Personal\\ improved-tribble\\ImprovedTribble\\app\\build\\intermediates\\data-binding-layout-out\\debug\\ layout\\task_list_item.xml","position":{"startLine":16}}],"original":"","tool":"AAPT"}

C:\Users\lucia.beltran\Desktop\Picho\Projects\Personal\improved-tribble\ImprovedTribble\app\build\intermediates\data-binding-layout-out\debug\layout\task_list_item.xml:17: error: Error parsing XML: duplicate 

 FAILED

FAILURE: Build failed with an exception.

* What went wrong: Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt

* Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 3.826 secs

My layout is as follows

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <data>
        <variable
            name="task"
            type="com.pichardo.improvedtribble.models.Task" />
    </data>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

    </LinearLayout>

</layout>

And the layout of the binding file that gradle console says is like:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" android:tag="layout/task_list_item_0" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent">

</LinearLayout>

I get which the duplicate attributes are, but I don't know why is crashing.

I read this question, but I don't have any like that on my build.gradle file.

Any suggestions?

like image 674
J. Pichardo Avatar asked Oct 05 '16 03:10

J. Pichardo


People also ask

Is Android databinding deprecated?

Recently Android has announced that with Kotlin 1.4. 20, their Android Kotlin Extensions Gradle plugin will be deprecated and will no longer be shipped in the future Kotlin releases. Android Kotlin Extensions plugin brought with it two very cool features : Synthetics let you replace calls to findViewById with kotlinx.

What is ActivityMainBinding in Android?

xml so the corresponding generated class is ActivityMainBinding . This class holds all the bindings from the layout properties (for example, the user variable) to the layout's views and knows how to assign values for the binding expressions.


2 Answers

Try to remove android:layout_width and android:layout_height="match_parent" in layout tag

<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <data>
        <variable
            name="task"
            type="com.pichardo.improvedtribble.models.Task" />
    </data>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

    </LinearLayout>

</layout>
like image 106
Mohit Suthar Avatar answered Oct 18 '22 18:10

Mohit Suthar


Here's my redacted real code:

<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
>

    <data>
        <variable
            name="MyDTO"
            type="com.example.MyDTO"
        />
    </data>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:mContext="com.example.MyActivity"
    >

All namespaces must be in outer layout tag. Any deletions did not help.

like image 6
user1046885 Avatar answered Oct 18 '22 19:10

user1046885