Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Inner element must either be a resource reference or empty

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"
like image 258
Mable John Avatar asked Aug 29 '18 11:08

Mable John


4 Answers

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>
like image 149
Sangeet Suresh Avatar answered Nov 08 '22 18:11

Sangeet Suresh


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.

like image 32
dna Avatar answered Nov 08 '22 17:11

dna


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.

like image 11
Sangam Pandey Avatar answered Nov 08 '22 18:11

Sangam Pandey


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>
like image 6
Oliver Manyasa Avatar answered Nov 08 '22 19:11

Oliver Manyasa