Android 编译报XML declaration not well-formed错误的解决方法

 项目上一秒还运行得好好的,下一秒编译却突然不成功,报如下错误

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:  D:\ws\AutosizingTest\app\src\main\res\layout\activity_main.xml:1: error: XML declaration not well-formed.
  
  Command: C:\Users\Him\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\4fc997b490c0c003506edf14eef98945\aapt2-3.2.1-4818971-windows\aapt2.exe compile --legacy \
          -o \
          D:\ws\AutosizingTest\app\build\intermediates\res\merged\debug \
          D:\ws\AutosizingTest\app\src\main\res\layout\activity_main.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 1s

 根据错误提示是布局文件错误,可是看了老半天没发现什么错误啊,而且布局文件也没动过啊

<?xml dversion="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <!--此处省略好多代码-->
</RelativeLayout>

而且错误提示也是说的不清不楚的,无法定位问题的原因,这种情况你越急越找不到原因。

遇到问题不要总是想当然的认为自己代码没问题,自己什么也没有动,就开始骂mmp。这时候需要静下心来。

根据错误提示这句话activity_main.xml:1: error: XML declaration not well-formed可以知道问题肯定出在activity_main.xml,而且是在第一行,仔细一看发现<?xml dversion="1.0" encoding="utf-8"?>这句话中version前多了一个d,导致了编译不通过。有可能是不小心按到键盘导致的。

所以遇到问题一定不要慌,事出必定有因,根据错误提示静下心来排查,肯定能找出问题的原因。

 

 

posted @ 2019-03-30 15:16  野猿新一  阅读(77)  评论(0编辑  收藏  举报