58

Error Details

AGPBI: {"kind":"error","text":"error: \u003citem\u003e inner element must either be a resource reference or empty.","sources":[{"file":"...\\app\\src\\main\\res\\values\\ids.xml","position":{"startLine":2,"startColumn":4,"startOffset":57,"endColumn":61,"endOffset":114}}],"original":"","tool":"AAPT"}
:app:mergeDebugResources
Error: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details
:app:mergeDebugResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Error: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details.

Resource File

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item name="tv_deviceName" type="id">tv_deviceName</item>
</resources>

Build Environment

  • Android Studio 3.1.4
  • minSdkVersion = 21
  • targetSdkVersion = 28
  • compileSdkVersion = 28
  • buildToolsVersion = "28.0.2"
2
  • Same here in my case then i delete code from ids.xml file .enter image description here Commented Jun 29, 2019 at 18:48
  • my code looks like this - <item name="textinput_suffix_text" type="id"/> AndI'm having the same error. Commented Aug 23, 2022 at 7:01

8 Answers 8

103

When declaring id in resources, the body should be empty

<item
    type="id"
    name="id_name" />

For more info please have a look on below link

https://developer.android.com/guide/topics/resources/more-resources#Id

So as Oliver Manyasa mentioned, it should be as below

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item name="tv_deviceName" type="id"/>
</resources>
Sign up to request clarification or add additional context in comments.

2 Comments

I know this,bug if xml file in a aar file,how to fix this problem
@yuchangfu you can override the resource in your file to fix this problem.
22

I had a similar issue after upgrading to Android Studio 3.2.1

The error was pointing to this item in ids.xml file

<item name="mnuActivate" type="id">Activation</item>

As mentioned by the user Sangeet Suresh, I changed it to

<item name="mnuActivate" type="id" />

That fixed the issue.

2 Comments

How did you edit the file? It´s regenerated automatically
Very confusing, android studio created this automatically.
11

To all others who are still scratching their head to get the solution for this is create ids.xml inside src/main/res/values with contents similar to the following (but make sure to update it with the ids you're seeing errors for):

<?xml version="1.0" ?>
<items>
    <item name="animator" type="id"/>
    <item name="date_picker_day" type="id"/>
    <string name="deleted_key"/>
</items>

Now Android Studio will be giving you an error for explicit values and if those values are coming from some library you are using then you can't make a change in the intermediate file so instead change here and while merging your code Android studio takes care of it.

2 Comments

Great solution! Just override these values, items, strings etc. in your own resources!
Can you elaborate your answer a little giving an example ids.xml file? I tried what you suggested but the same items are coming up in the errors after a rebuild?
6

On your Resource File remove the closing tag plus the Body i.e Remove "tv_deviceName"

and let your resource file be like:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item name="tv_deviceName" type="id"/>
</resources>

1 Comment

Oliver Manyasa, would you share your email address or send an email to [email protected] asap
3

I had below error

error: <item> inner element must either be a resource reference or empty.

In my case I created new test project and deleted the toolbar and fab from activity_main.xml file but these were also in ids.xml file. After deleting both ids from ids.xml file I was able to run. In your ids.xml file you may have lots of ID's but as I created a new project So, It has No IDs.

enter image description here

In above screenshot you can see the exact file location.

2 Comments

And finally my project doesn't have a single line of code.
@young Exactly.
3

For me this was actually failing because the new gradle versions. I am pretty sure that some plugins I'm using have incompatibilities with newest gradle. I ended up with success build having the following versions:

gradle-wrapper.properties file:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

build.gradle file

 dependencies {
   classpath 'com.android.tools.build:gradle:3.0.1'
 }

EDIT:

As we want to use 3.2.+ versions now, that isn't a reliable solution.

What I ended up doing is creating a new ids.xml file, and overriding all the values that have been conflicting.

ids.xml file example:

<?xml version="1.0" encoding="utf-8"?>
    <resources>
        <item name="cc_card" type="id"/>
        <item name="cc_ccv" type="id"/>
        <item name="cc_entry" type="id"/>
        <item name="cc_entry_internal" type="id"/>
        <item name="cc_exp" type="id"/>
        <item name="cc_form_layout" type="id"/>
        <item name="cc_four_digits" type="id"/>
        <item name="cc_zip" type="id"/>
        <item name="text_helper" type="id"/>
    </resources>

Comments

2

I simply created this auto-generated file in res/xml/values with empty tags like

<?xml version="1.0" encoding="utf-8"?>
<resources>
    ...
    <item type="id" name="icon" />
    ...
</resources>

That did the trick!

Comments

1

In the the values folder I double clicked the ids.xml file this was causing the issue

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item name="roll_button" type="id">rollButton</item>
</resources>

enter image description here

I tried the some of the voted answers:

<item name="roll_button" type="id">

But I got an error that said:

The element type "item" must be terminated by the matching end-tag "</item>".

So to fix I just added the matching ending tag:

<item name="roll_button" type="id"></item>

UPDATE

I'm new to Kotlin so what I just noticed and what I didn't realize is the <item name="roll_button" type="id" /> needs the forward slash at the end to go before the closing >. If you don't include it then you will get the error I got but if you do include it the accepted answer works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.