简体   繁体   English

Android Studio 3.2.1中的colors.xml问题

[英]Issue with colors.xml in Android Studio 3.2.1

Following is the awkward and incomplete colors.xml I get while trying to create an Android project using Android Studio 3.2.1. 以下是我尝试使用Android Studio 3.2.1创建Android项目时colors.xml的尴尬和不完整的colors.xml

在此处输入图片说明

The error I get is D:\\AndroidStudioWorkspace\\PlayCardz\\app\\src\\main\\res\\values\\colors.xml:7:19: Error: XML document structures must start and end within the same entity. 我得到的错误是D:\\AndroidStudioWorkspace\\PlayCardz\\app\\src\\main\\res\\values\\colors.xml:7:19: Error: XML document structures must start and end within the same entity.

Why is it happening? 为什么会这样呢?

Update 更新

After manually changing colors.xml file to following I start getting the following error: 手动将colors.xml文件更改为以下内容后,我开始出现以下错误:

Android resource compilation failed
Output:  D:\AndroidStudioWorkspace\GameCardz\app\src\main\res\mipmap-anydpi-v26\ic_launcher_round.xml:1: error: not well-formed (invalid token).

Command: C:\Users\docrk\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\a0fab621f980e2e9b95746cdfd1fc60d\aapt2-3.2.1-4818971-windows\aapt2.exe compile --legacy \
        -o \
        D:\AndroidStudioWorkspace\GameCardz\app\build\intermediates\res\merged\debug \
        D:\AndroidStudioWorkspace\GameCardz\app\src\main\res\mipmap-anydpi-v26\ic_launcher_round.xml
Daemon:  AAPT2 aapt2-3.2.1-4818971-windows Daemon #0

Manually updated colors.xml file: 手动更新的colors.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!--   color for the app bar and other primary UI elements -->
    <color name="colorPrimary">#3F51B5</color>

    <!--   a darker variant of the primary color, used for
           the status bar (on Android 5.0+) and contextual app bars -->
    <color name="colorPrimaryDark">#303F9F</color>

    <!--   a secondary color for controls like checkboxes and text fields -->
    <color name="colorAccent">#FF4081</color>
</resources>

This file is copied from <Android Studio install dir>/plugins/android/lib/templates/gradle-projects/NewAndroidModule/root/res/values/colors.xml . 该文件是从<Android Studio install dir>/plugins/android/lib/templates/gradle-projects/NewAndroidModule/root/res/values/colors.xml复制的。 Check for it to find any error in this file. 检查它以查找此文件中的任何错误。

For me, the content of this file is 对我来说,这个文件的内容是

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#008577</color>
    <color name="colorPrimaryDark">#00574B</color>
    <color name="colorAccent">#D81B60</color>
</resources>

Overwrite it if your template is modified. 如果修改了模板,则将其覆盖。

Update for the updated question: I think your project template is totally overwritten with a mess. 更新更新的问题:我认为你的项目模板是一个烂摊子完全覆盖。 You may recursively find what the error of your templates are, by finding the source of error output of the file path (for example, the error in the update says file (D:\\AndroidStudioWorkspace\\GameCardz\\app\\src\\main\\res\\mipmap-anydpi-v26\\ic_launcher_round.xml , which can be mapped into the template file <Android Studio install dir>/plugins/android/lib/templates/gradle-projects/NewAndroidModule/root/res/mipmap-anydpi-v26/ic_launcher_round.xml .), correct each of them. 您可以通过查找文件路径的错误输出源来递归地查找模板的错误(例如,更新中的错误显示文件(D:\\AndroidStudioWorkspace\\GameCardz\\app\\src\\main\\res\\mipmap-anydpi-v26\\ic_launcher_round.xml ,可以将其映射到模板文件<Android Studio install dir>/plugins/android/lib/templates/gradle-projects/NewAndroidModule/root/res/mipmap-anydpi-v26/ic_launcher_round.xml 。),请更正每一个。

Or, since this template locates in <Android Studio install dir> (actually it is a bundled plugin), you may reinstall your Android Studio, or reinstall (but, how to?) that plugin to fix this issue. 或者,由于此模板位于<Android Studio install dir> (实际上是捆绑的插件)中,因此您可以重新安装Android Studio,或重新安装(但是如何?)该插件来解决此问题。

In my case I had to delete .gradle .android and .androidstudio3.x folders in c\\useres\\username and it went normal again. 就我而言,我必须删除c \\ useres \\ username中的.gradle .android和.androidstudio3.x文件夹,它又恢复了正常。 I think you have updated androidstudio recently. 我认为您最近更新了androidstudio。

In my case, I had to delete .gradle .android and .androidstudio3.x folders in C:\\Users\\username and it went normal again. 就我而言,我必须删除C:\\Users\\username .gradle .android.androidstudio3.x文件夹,它又恢复了正常。 I think you have updated Android Studio recently. 我认为您最近更新了Android Studio。

This worked for me also. 这也对我有用。 My colors.xml and ic_launcher were corrupted somehow. 我的colors.xmlic_launcher以某种方式损坏了。 I built many apps with no issue. 我构建了许多应用程序,都没有问题。 Then this weekend I was getting build errors. 然后这个周末我遇到了构建错误。

If your files from <Android Studio install dir>/plugins/android/lib/templates/gradle-projects/NewAndroidModule has been crashed. 如果您的<Android Studio install dir>/plugins/android/lib/templates/gradle-projects/NewAndroidModule中的文件已崩溃。

  1. Download https://android.googlesource.com/platform/tools/base/+archive/studio-master-dev/templates/gradle-projects/NewAndroidModule.tar.gz 下载https://android.googlesource.com/platform/tools/base/+archive/studio-master-dev/templates/gradle-projects/NewAndroidModule.tar.gz

  2. Go to <Android Studio install dir>/plugins/android/lib/templates/gradle-projects/NewAndroidModule 转到<Android Studio install dir>/plugins/android/lib/templates/gradle-projects/NewAndroidModule

  3. Extract files from <Name Of Downloaded File>.tar.gz and Replace All !!! <Name Of Downloaded File>.tar.gz提取文件并全部替换!!!
  4. Restart Android Studio 重新启动Android Studio

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM