当前位置: 首页 > 知识库问答 >
问题:

Android构建错误,不显示R内容

祁坚壁
2023-03-14

所以,我只是把我的应用程序转移到另一台笔记本电脑上,当我试图构建这个错误时,出现了提示。请帮忙。我需要改变什么?

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个答案

姬烨磊
2023-03-14

在资源文件上,删除结束标记和正文,即删除“tv_deviceName”

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

Id应该如下所示

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

然后,此布局片段使用按钮小部件的“button_ok”ID:

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

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

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

showDialog(R.id.dialog_exit);

折射:点击这里。

蒋永宁
2023-03-14

应该是:

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

裁判来了。

 类似资料:
  • 格拉德尔计划 应用程序Gradle 错误:配置根项目'webapp'时出现问题。 无法解决配置: classpath的所有依赖项。找不到com.android.tools.build: gradle: 3.0.0-alpha3。在以下位置搜索:file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/

  • 我对Android Studio有个奇怪的问题。下面是我的类文件在Android Studio上的样子 下面是它在文本编辑器上的样子。 知道为什么会这样吗?我试过关闭然后重新移植项目,使缓存无效并重新启动,清理项目,构建项目,删除.idea文件夹和.iml文件。我的所有文件都是坏的,当打开时,但在文本编辑器上看起来很好。

  • 我正在开发一个屏幕锁定的Android应用程序。我已经使用广播接收器的屏幕。在我的应用程序中,我想使用拖放。所以,当我使用时,它显示一个错误 JAVAlang.RuntimeException:在com中接收广播意图{act=init view flg=0x10}时出错。应用程序。锁屏图书馆。LockBroadcastReceiver@f22ed7d. 并且库文件引用是https://github

  • 我使用最新的Android Studio 1.3.2(OS Windows 7),在资产目录我把2 apks,当我试图编译我收到这个错误。 如何解决此错误?任何建议都有很大帮助。

  • 在我尝试在Android Studio中创建的每个项目中,R的所有用法都用红色标记,并带有错误消息“无法解析符号R”,但编译成功,应用程序运行。这真的很烦人,因为它阻碍了自动完成,并且在我的代码上显示了巨大的红色波浪线。 这是我的: 这就是项目结构的样子: 知道怎么解决吗?