Peter
Peter

Reputation: 589

Android XML: "conflicts with another tag that has the same ID"

I recently deleted a fragment including its layout and viewmodel from my project. (FragmentAddFlight, VmAddFlight, fragment_add_flight.xml)

Surprisingly I am getting these errors:

    [databinding] {"msg":"\u003cImageView id\u003d\u0027@+id/imageView2\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":277,"col0":20,"line1":286,"col1":85}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView4\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":308,"col0":28,"line1":312,"col1":64}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/editText8\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":314,"col0":28,"line1":318,"col1":60}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView5\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":327,"col0":28,"line1":331,"col1":63}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView14\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":333,"col0":28,"line1":338,"col1":57}]}
  [databinding] {"msg":"\u003cImageView id\u003d\u0027@+id/imageView2\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":369,"col0":20,"line1":378,"col1":72}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView4\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":400,"col0":28,"line1":404,"col1":60}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/editText8\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":406,"col0":28,"line1":410,"col1":60}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView5\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":419,"col0":28,"line1":423,"col1":71}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView14\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":425,"col0":28,"line1":430,"col1":57}]}
  [databinding] {"msg":"\u003cImageView id\u003d\u0027@+id/imageView2\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":452,"col0":20,"line1":461,"col1":77}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView4\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":483,"col0":28,"line1":487,"col1":60}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/editText8\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":489,"col0":28,"line1":493,"col1":60}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView5\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":502,"col0":28,"line1":506,"col1":71}]}
  [databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView14\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\Christoph\\Documents\\Android-Projekte\\FlightLogger\\app\\src\\main\\res\\layout\\fragment_add_flight.xml","pos":[{"line0":508,"col0":28,"line1":513,"col1":57}]}

Remember the file referenced in these error has already been deleted. Why do I get these errors?

I cleaned the project via Build -> clean project. I tried to rebuild the project via the same menu. But the result remains the same.

Does anybody have an idea how to solve this issue?

Upvotes: 25

Views: 15582

Answers (15)

Chala Java yeu dya
Chala Java yeu dya

Reputation: 1

The right solution is here.

Step 1 : Remove this line from your build.gradle file

 buildFeatures {
    dataBinding =  true
}

Step 2: Invalid cache & restart android studio Step 3: Close Android Studio Step 4: Let the android studio sync after doing step 2 Step 5: Restart your system

And woilaa..!!

Upvotes: 0

VonSchnauzer
VonSchnauzer

Reputation: 951

Any declaration of an id in an xml-layout should be unique.

This will be global in your app:

<LinearLayout
    android:id="@+id/myLayoutId"

whilst this will not be global

<LinearLayout
    android:id="@id/myLayoutId"

It won't be a problem usually, but something to keep in mind.

Upvotes: 0

Imran Khan Saifi
Imran Khan Saifi

Reputation: 569

Sometime this problem arise when you refactor(Rename) id in current file and it change that id in full project and this problem arises..

Upvotes: 0

Shahriar Zaman
Shahriar Zaman

Reputation: 938

Couldn't make it go without killing existing Gradle processes.

on Linux terminal:

pkill -f '.*GradleDaemon.*'

Upvotes: 0

Yaseen Official
Yaseen Official

Reputation: 1

If you are getting such issue then follow these instructions

if your system is Windows,

  1. Open cmd, input perfmon, and you will see there.
  2. "open resource monitor" just click on this option
  3. Click the CPU->Associated handle->Search android.
  4. Close all the associated handle,then open your AndroidStudio

Now you get there is no such error. This process is worked for me.

Upvotes: 0

android developer
android developer

Reputation: 116322

If you use view-binding, you can add this to the layout till you have better IDs for the Views:

tools:viewBindingIgnore="true"

Do it for each problematic layout.

I found this tip from here.

Upvotes: 6

Bassem M Bazzoun
Bassem M Bazzoun

Reputation: 11

In my case there was the same ID assigned to different views in my XML file. I just changed one of them to avoid conflict then it worked.

Upvotes: 1

pnkj
pnkj

Reputation: 498

if File > Invalidate Caches / Restart > Invalidate and Restart cannot solve your problem. Maybe you can try to

  1. delete
    buildFeatures {
        dataBinding =  true
    }
  1. Invalidate
  2. Close AndroidStudio
  3. if your system is Windows, open resource monitor(because my computer is Chinese, so I don't know how to translate this word in the English system. Open cmd, input perfmon, and you will see it.)
  4. Click the CPU->Associated handle->Search android.
  5. Close all the associated handle,then open your AndroidStudio and add the
    buildFeatures {
        dataBinding =  true
    }

enter image description here

enter image description here

enter image description here

Upvotes: 3

Le Trung Hieu
Le Trung Hieu

Reputation: 174

None of the above works for me: tools:viewBindingIgnore="true" , invalidate caches, gradlew assembleDebug. All is not works.

The only way I found is delete the whole project and pull the source code again from git. Then build -> it run normally

Upvotes: -1

Mars Moon
Mars Moon

Reputation: 114

Sometimes none of the tricks explained above works as expected. Invalidate Cache and Restart Android Studio did not work for me at all. I tried the following command as well

gradlew assembleDebug

But it only works one time. I have to do this every time I make changes to the layout file. Try following these tricks if none of it is working for you

  • Rename the layout file. You might want to change the Binding class as well
  • Export the Project and as zip, unzip it in a different locations and open the existing project.

Upvotes: 1

Dishant Dishu
Dishant Dishu

Reputation: 81

It might be the case you accidentally make a layout-26 folder and inside that, there are two XML files of the same name.

Solution-:

1.Move the correct XML file from the layout-26 folder to the layout folder

2.Delete the layout-26 folder.

Upvotes: 0

Khalid Aziz
Khalid Aziz

Reputation: 29

Compile Time Issues: Fixed: 1.Clean the project. 2.clear cache and restart.

Make sure View binding is enabled.

Upvotes: 0

Yogesh Rathi
Yogesh Rathi

Reputation: 6499

Invalidate Caches/Restart option sometime not working.

gradlew assembleDebug

Just try this command then see issue will no more available.

Upvotes: 4

brunorcabral
brunorcabral

Reputation: 145

To add on how to invalidate caches, in Android Studio, go to File > Invalidate Caches / Restart > Invalidate and Restart

Upvotes: 3

Anand Pandey
Anand Pandey

Reputation: 562

These files are created at compile time, so they might not have been deleted, Try invalidate caches and restart in android studio.

Upvotes: 51

Related Questions