Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

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

Error Details

AGPBI: {"kind":"error","text":"error: u003citemu003e 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"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...