【问题标题】:"Gradle build finished with 1 error(s)" fault“Gradle 构建完成,出现 1 个错误”错误
【发布时间】:2018-09-06 04:34:53
【问题描述】:

我的 Android 工作室有问题。有时它可以工作,但当它不起作用时,通常会出现此错误:

我应该怎么做才能解决这个问题?

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.wordpress.schoolworkhelpsite.swhsapp.MainActivity">

    <image>ic.launcher.png</image>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="23dp"
        android:text="SchoolWork HelpSite"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>
<xml>

如果我的代码有误,我需要更改什么?

【问题讨论】:

  • 显示错误,我们不会读心术
  • 您的 xml 文件有错误并且未格式化,请使其正确,这样可以解决错误。
  • 尝试复制整个错误日志并发布它,而不是图像

标签: xml android-studio android-gradle-plugin


【解决方案1】:

Android Studio 应该会立即告诉您代码出了什么问题。如果没有在设置中查找 Lint 并检查每个相关选项。

  1. &lt;image&gt;ic.launcher.png&lt;/image&gt;

AS说

此处不允许使用元素图片

如果要使用图片,请使用ImageView

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@mipmap/ic_launcher" />
  1. &lt;xml&gt;

AS 说:

多个根标签

你为什么要打开另一个根标签?以&lt;/xml&gt; 结束也是不正确的,你从哪里得到这个想法?您只需要关闭根标记,在这种情况下是 ConstraintLayout 并且您的代码很好。只需删除 &lt;xml&gt; 行。

【讨论】:

    【解决方案2】:

    错误1:希望屏幕设计没有任何错误,因此在预览面板中更改设备和API版本,您将获得预览。

    错误 2:分享您在消息选项卡中显示的错误。好让我给你整改

    【讨论】:

    • 我现在已经改变了问题......希望这会更好。
    猜你喜欢
    • 1970-01-01
    • 2017-12-22
    • 2016-10-05
    • 1970-01-01
    • 1970-01-01
    • 2015-07-09
    • 1970-01-01
    • 2014-09-01
    • 1970-01-01
    相关资源
    最近更新 更多