首页 文章

Android构建错误未显示R内容

提问于
浏览
1

所以我只是将我的应用程序转移到另一台笔记本电脑,当我尝试构建此错误时提示 . 请帮忙 . 我需要改变什么?

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
  Output:  C:\Users\Rhylle Vincent\Desktop\01-03-2018-740pm\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:651: error: <item> inner element must either be a resource reference or empty.
  C:\Users\Rhylle Vincent\Desktop\01-03-2018-740pm\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:652: error: <item> inner element must either be a resource reference or empty.

  Command: C:\Users\Rhylle Vincent\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\f919f683d074912d6e0f1b8bf0931ab0\aapt2-3.2.1-4818971-windows\aapt2.exe compile --legacy \
          -o \
          C:\Users\Rhylle Vincent\Desktop\01-03-2018-740pm\app\build\intermediates\res\merged\debug \
          C:\Users\Rhylle Vincent\Desktop\01-03-2018-740pm\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml
  Daemon:  AAPT2 aapt2-3.2.1-4818971-windows Daemon #0
  Output:  C:\Users\Rhylle Vincent\Desktop\01-03-2018-740pm\app\src\main\res\values\ids.xml:4:5-54: AAPT: error: <item> inner element must either be a resource reference or empty.

  C:\Users\Rhylle Vincent\Desktop\01-03-2018-740pm\app\src\main\res\values\ids.xml:3:5-47: AAPT: error: <item> inner element must either be a resource reference or empty.

  Command: C:\Users\Rhylle Vincent\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\f919f683d074912d6e0f1b8bf0931ab0\aapt2-3.2.1-4818971-windows\aapt2.exe compile --legacy \
          -o \
          C:\Users\Rhylle Vincent\Desktop\01-03-2018-740pm\app\build\intermediates\res\merged\debug \
          C:\Users\Rhylle Vincent\Desktop\01-03-2018-740pm\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml
  Daemon:  AAPT2 aapt2-3.2.1-4818971-windows Daemon #0

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

* Get more help at https://help.gradle.org

BUILD FAILED in 7s

ids.xml

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

2 回答

  • 1

    在您的资源文件中删除结束标记加上正文,即删除“tv_deviceName”

    <item type="id" name="button_ok">tv_deviceName</item>
    

    我应该如下所示

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

    然后,此布局代码段使用Button小部件的“button_ok”ID:

    <Button android:id="@id/button_ok"
        .... />
    

    请注意,android:id值不包含ID引用中的加号,因为ID已存在,如上面的ids.xml示例中所定义 . (当您使用加号登录为XML资源指定ID时,格式为android:id =“@ id / name” - 这意味着“名称”ID不存在且应该创建 . )

    作为另一个示例,以下代码段使用“dialog_exit”ID作为对话框的唯一标识符:

    showDialog(R.id.dialog_exit);
    

    参考:Click here.

  • 1

    应该:

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

    ref是here .

相关问题