0

Following is the awkward and incomplete colors.xml I get while trying to create an Android project using Android Studio 3.2.1.

enter image description here

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.

Why is it happening?

Update

After manually changing colors.xml file to following I start getting the following error:

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:

<?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>
skip
  • 12,193
  • 32
  • 113
  • 153
  • Do you have your `New Project` template incorrectly modified? Note that what you say is `create a project`... – Geno Chen Dec 14 '18 at 14:44
  • This is during the creation of the project. I haven't done anything to the project yet. It just builds with that error and the colors.xml file. – skip Dec 14 '18 at 15:07
  • Which kind of project are you creating? Consider looking for /plugins/android/lib/templates to find what happened. `AndroidTVActivity`? – Geno Chen Dec 14 '18 at 15:23
  • Update for your update: what is the content of `/plugins/android/lib/templates/gradle-projects/NewAndroidModule/root/res/mipmap-anydpi-v26ic_launcher_round.xml`? – Geno Chen Dec 14 '18 at 16:42
  • Hello @GenoChen It is ` ` – skip Dec 14 '18 at 16:46
  • @GenoChen When I navigate to the file `ic_launcher_background` inside my android project I find it is full of errors. – skip Dec 14 '18 at 16:49

4 Answers4

2

This file is copied from <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.

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.

Geno Chen
  • 4,916
  • 6
  • 21
  • 39
  • Hello @Geno Chen I just did that and then I have started getting another issue that I have mentioned in my updated question. Please take a look. – skip Dec 14 '18 at 16:42
  • 1
    @skip I updated my answer for your updated question. – Geno Chen Dec 14 '18 at 16:50
  • You're spot on about the `ic_launcher.xml` and `ic_launcher_round.xml` in the project full of junk. I've copied the content from `/plugins/android/lib/templates/gradle-projects/NewAndroidModule/root/res/mipmap-anydpi-v26/ic_launcher_round.xml` to `D:\AndroidStudioWorkspace\GameCardz\app\src\main\res\mipmap-anydpi-v26\ic_launcher_round.xml`. I've updated the `ic_launcher` in the project too. But still I've got errors being shown in the `D:\AndroidStudioWorkspace\GameCardz\app\src\main\res\drawable\ic_launcher_background.xml` file. – skip Dec 14 '18 at 16:58
  • 1
    I mean the "source", or we say the "template", which locates in `/plugins/android/lib/templates/`, where the file of your new project generated / copied from, are destroyed with an unknown reason. So what you should do is, to fix the "template", by reinstall Android Studio, or reinstall that Android plugin, or manually fix all the errors in the template, **not** by copying the content from "template" to "generated project". – Geno Chen Dec 14 '18 at 17:03
0

In my case I had to delete .gradle .android and .androidstudio3.x folders in c\useres\username and it went normal again. I think you have updated androidstudio recently.

Tanveer Ahmed
  • 426
  • 1
  • 4
  • 15
0

In my case, I had to delete .gradle .android and .androidstudio3.x folders in C:\Users\username and it went normal again. I think you have updated Android Studio recently.

This worked for me also. My colors.xml and ic_launcher were corrupted somehow. I built many apps with no issue. Then this weekend I was getting build errors.

gogaz
  • 2,323
  • 2
  • 23
  • 31
jimmy
  • 1
0

If your files from <Android Studio install dir>/plugins/android/lib/templates/gradle-projects/NewAndroidModule has been crashed.

  1. Download 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

  3. Extract files from <Name Of Downloaded File>.tar.gz and Replace All !!!
  4. Restart Android Studio