Failed to compile values file
Asked Answered
S

26

46

I try to run my program but I have a Build: failed

Failed to compile values file.

but I don't know why? the values file is generated by default ...

and I have this error

Resource compilation failed. Check logs for details.

and the explanation is

Execution failed for task ':app:mergeDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.ResourceCompilerRunnable
   > Resource compilation failed. Check logs for details.

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:mergeDebugResources'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:208)
    at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:263)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:206)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:187)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:114)
    at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:409)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:399)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:157)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:242)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:150)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:94)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
    at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:41)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:372)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:359)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:352)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:338)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.lambda$run$0(DefaultPlanExecutor.java:127)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:191)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:182)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:124)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.android.build.gradle.internal.res.ResourceCompilerRunnable
    at org.gradle.workers.internal.DefaultWorkerExecutor$WorkItemExecution.waitForCompletion(DefaultWorkerExecutor.java:336)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:142)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:94)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForAll(DefaultAsyncWorkTracker.java:80)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForCompletion(DefaultAsyncWorkTracker.java:68)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.run(ExecuteActionsTaskExecuter.java:578)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:395)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:387)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:157)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:242)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:150)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:84)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:555)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:538)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.access$300(ExecuteActionsTaskExecuter.java:109)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.executeWithPreviousOutputFiles(ExecuteActionsTaskExecuter.java:279)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.execute(ExecuteActionsTaskExecuter.java:268)
    at org.gradle.internal.execution.steps.ExecuteStep.lambda$execute$0(ExecuteStep.java:32)
    at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:32)
    at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:26)
    at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:67)
    at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:36)
    at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:49)
    at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:34)
    at org.gradle.internal.execution.steps.CancelExecutionStep.execute(CancelExecutionStep.java:43)
    at org.gradle.internal.execution.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:73)
    at org.gradle.internal.execution.steps.TimeoutStep.execute(TimeoutStep.java:54)
    at org.gradle.internal.execution.steps.CatchExceptionStep.execute(CatchExceptionStep.java:34)
    at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:44)
    at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:54)
    at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:38)
    at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:49)
    at org.gradle.internal.execution.steps.CacheStep.executeWithoutCache(CacheStep.java:159)
    at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:72)
    at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:43)
    at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:44)
    at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:33)
    at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:38)
    at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:24)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:92)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.lambda$execute$0(SkipUpToDateStep.java:85)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:55)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:39)
    at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:76)
    at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:37)
    at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:36)
    at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:26)
    at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:94)
    at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:49)
    at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:79)
    at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:53)
    at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:74)
    at org.gradle.internal.execution.steps.SkipEmptyWorkStep.lambda$execute$2(SkipEmptyWorkStep.java:78)
    at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:78)
    at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:34)
    at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsStartedStep.execute(MarkSnapshottingInputsStartedStep.java:39)
    at org.gradle.internal.execution.steps.LoadExecutionStateStep.execute(LoadExecutionStateStep.java:40)
    at org.gradle.internal.execution.steps.LoadExecutionStateStep.execute(LoadExecutionStateStep.java:28)
    at org.gradle.internal.execution.impl.DefaultWorkExecutor.execute(DefaultWorkExecutor.java:33)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:195)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:187)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:114)
    at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:409)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:399)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:157)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:242)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:150)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:94)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
    at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:41)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:372)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:359)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:352)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:338)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.lambda$run$0(DefaultPlanExecutor.java:127)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:191)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:182)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:124)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
Caused by: com.android.aaptcompiler.ResourceCompilationException: Resource compilation failed. Check logs for details.
    at com.android.aaptcompiler.ResourceCompiler.compileResource(ResourceCompiler.kt:121)
    at com.android.build.gradle.internal.res.ResourceCompilerRunnable$Companion.compileSingleResource(ResourceCompilerRunnable.kt:31)
    at com.android.build.gradle.internal.res.ResourceCompilerRunnable.run(ResourceCompilerRunnable.kt:15)
    at com.android.build.gradle.internal.profile.ProfileAwareWorkAction.execute(ProfileAwareWorkAction.kt:74)
    at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:67)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:63)
    at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:97)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1.lambda$execute$0(NoIsolationWorkerFactory.java:63)
    at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44)
    at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:409)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:399)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:157)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:242)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:150)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:94)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:60)
    at org.gradle.workers.internal.DefaultWorkerExecutor.lambda$submitWork$2(DefaultWorkerExecutor.java:200)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:215)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:164)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:131)
    ... 3 more
Caused by: java.lang.IllegalStateException: Failed to compile values file.
    at com.android.aaptcompiler.ResourceCompiler.compileTable(ResourceCompiler.kt:185)
    at com.android.aaptcompiler.ResourceCompiler.access$compileTable(ResourceCompiler.kt:1)
    at com.android.aaptcompiler.ResourceCompiler$getCompileMethod$1.invoke(ResourceCompiler.kt:132)
    at com.android.aaptcompiler.ResourceCompiler$getCompileMethod$1.invoke(ResourceCompiler.kt)
    at com.android.aaptcompiler.ResourceCompiler.compileResource(ResourceCompiler.kt:118)
    ... 26 more
 

any solution for me, please?

Stupa answered 10/10, 2020 at 17:42 Comment(6)
did you try clean project and rebuild project ?Arnettearney
This is clearly an android studio bugDisconsolate
did you find any solution?Sinh
I think it is a bug because it does not says in which file and line there an error, @samuelowino.Imperator
In my case, not sure if it was a dimen that (by missclick) end up in the styles file (don't think so, should work), or a 16pd instead of 16dp (funny thing: the preview worked and IDE never show warning)Imperator
Android studio has a problem with showing minor resource file errors. So if you have a typo or syntax error in your attrs.xml or layout.xml, the android studio is too dumb to tell you exactly what went wrong. sadDisconsolate
M
71

The error "Failed to compile a values file" is due, as the error suggests something related to any values file entry you have.

For instance, when adding a string entry value many times the char ' is present without the proper escape char \

the example below is for an entry on the strings values file:

<string name="slide_1_title">Joe's Pizza</string>

needs to be corrected to:

<string name="slide_1_title">Joe\'s Pizza</string>
Mccary answered 24/6, 2021 at 13:2 Comment(2)
Adding comment for posterity: for colors.xml, if you have a colors resource and do not include the "#" first, i.e. #FF000000, it will cause this compilation errorDishwasher
I got this same build error today, and yes it was exactly as described above- I had "can't" in my strings.xml and replaced it with "can\'t" - and the world was good...Dexamyl
D
12

This looks like a bug to me in Android Studio 4.2.2 I created a fresh project in Android Studio using Kotlin, and guess what it created the project well and I added little stuff here and there without touching the values at all and when I built the project, same error as the OP occured

Now I was curious as to why this happened

So I went with the programmatic way of building using gradlew build and too my surprise I saw the project didn't enable androidX by default and there were many dependenices based on that so I went to the gradle.properties file and set the following two values after a File> Invalidate Caches

android.useAndroidX=true
android.enableJetifier=true

Davison answered 24/7, 2021 at 18:43 Comment(0)
P
7

I have also faced the same issue, My mistake was in strings.xml file i have forgot to escape the apostrophy 's e.g Today's

I have added escape character backslash before apostrophy 's i.e Today's had solved my issue.

Powered answered 8/6, 2021 at 17:29 Comment(1)
Thank you so much! That was my problem too. I had a string resource which contained something like this: hasn\'t . When I saw it I thought I'd change it to: hasn&apos;t . I then made several other changes to may project. So when the error occurred it didn't occur to me that the change would break my build. When I saw your answer, I knew I did that same thing.Tibiotarsus
I
5

I got the same error and solved it by removing apostrophe from a string in values.xml file. That's it.

Iow answered 16/6, 2021 at 9:1 Comment(0)
F
4

I faced to this error too. It was my fault that I used 7 digits (char) for color in color.xml like this.

<color name="primary_light_color">#F6ABF69</color>

I have corrected the color name like this:

<color name="primary_light_color">#F6ABF6</color>
Favors answered 2/8, 2021 at 14:32 Comment(0)
S
4

Okay, I found out what it was in my case. So the error was in my colors.xml file, I accidentally put 2 hashtags in front of the color code (##FFFFFF), and that was all. So for anyone facing this error, check every file for stupid typos like this, apostrophes without the escape char, underscores, dashes, upper case letters, hashtags etc.

Sapp answered 4/1, 2022 at 16:33 Comment(0)
M
3

I ran in the same error, and neither the logs or stacktrace would help me. But the "Analyse Code" option got to show me I had an unescaped quote which, I can't figure out why, I can't escape with ' / ' (whereas ' works well)

Magnusson answered 17/5, 2022 at 7:58 Comment(1)
I had to switch don't to don\'t to fix this error.Leacock
P
2

For me this was due to adding nested styles in themes.xml mistakenly like below

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.MyTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
        <!-- Primary brand color. -->
       
        <!-- ///// -->

        <style name="NewStyle">
            ...
        </style>

    </style>

</resources>
Pulley answered 28/4, 2021 at 23:36 Comment(0)
C
2

I also faced this problem, In my case, I was making a string array in string.xml but I put items indirect form of text on behalf of making a string value for every item. Example:- OldCode:-

<string-array name="countries">
    <item>india</item>
    <item>pakistan</item>
    <item>uk</item>
    <item>usa</item>
    <item>bangladesh</item>
    <item>egypt</item>
    <item>germany</item>
    <item>indonesia</item>
</string-array>

NewCode:-

<string-array name="countries">
    <item>@string/india</item>
    <item>@string/pakistan</item>
    <item>@string/uk</item>
    <item>@string/usa</item>
    <item>@string/bangladesh</item>
    <item>@string/egypt</item>
    <item>@string/germany</item>
    <item>@string/indonesia</item>
</string-array>
Claque answered 6/7, 2021 at 18:9 Comment(0)
Q
1

I also got the same Error and this is because of the reason that in theme file in Values file all colors strings tags are converted in to cartItem tag by default these are item these tags are looking like this..

    <cartItem name="colorPrimary">#FBC02D</item>
    <cartItem name="colorPrimaryVariant">#F8B13E</item>
    <cartItem name="colorOnPrimary">@color/white</item>

and i simply removes the cart from the tag and the new code is like

    <item name="colorPrimary">#FBC02D</item>
    <item name="colorPrimaryVariant">#F8B13E</item>
    <item name="colorOnPrimary">@color/white</item>

in this way i solved this error... Thanks in later

Quintanilla answered 21/8, 2021 at 8:9 Comment(0)
C
1

I also had such a problem when executing my project, after some research on the project I found out that the problem is with colors.xml (I had forgotten to write the color code fully)

    <color name="grey">#</color>

After removing this line, everything worked perfectly. I hope it helped you, good luck:)

Cao answered 20/4, 2022 at 9:4 Comment(0)
A
0

I have this issue and this is how I solved it:

  1. Move the root project folder to the previous parent folder.

  2. Go to Android Studio (Use the latest Android Studio (I use 4.2) -> Refactor -> Migrate to AndroidX. Zip/backup your project and run migration.

  3. Add/Change this line at the end of gradle.properties (Global Properties):

    ...
    org.gradle.jvmargs=-XX\:MaxHeapSize\=1024m -Xmx1024m 
    

    If it doesn't work you can retry with larger than 1024 heap size.

  4. Clean and rebuild the project and it works!

Adjunct answered 24/10, 2020 at 15:5 Comment(0)
T
0

I had the same error, but it was caused by something in the values > ids.xml file.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- some other stuff -->
    <item name="a_string_i_was_trying_to_define" type="id">some string</item>
</resources>

How It Happened

For me, it happened when I got to typing too fast + auto-complete in Android Studio. In a Fragement, I added:

getString(R.id.a_string_i_was_trying_to_define)

Instead of:

getString(R.string.a_string_i_was_trying_to_define)

I realized it, and fixed it, but behind the scenes, that caused Android Studio to add to ids.xml. When I compiled, I got the cryptic error you saw. Clean/Rebuild didn't help, but deleting that value from ids.xml did.

Trevethick answered 26/4, 2021 at 20:35 Comment(0)
E
0

I had a similar problem. I updated the latest version yesterday.(android studio 4.2) error info

Execution failed for task ':app:mergeDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.ResourceCompilerRunnable
> Resource compilation failed. Check logs for details.

Check the code later found the problem. TextView use tools:text="xxx"
but parent layout not use

xmlns:tools="http://schemas.android.com/tools"

add this statement or delete tools:text="xxx" Can solve the problem

BUT Why didn't the compiler report an error

Equities answered 8/5, 2021 at 6:23 Comment(1)
Is it a bug in AS 4.2?Arciform
B
0

I have faced the same issue but in my case i added a color code and forgot to add # in front of color code. Which caused this error.

Bollen answered 18/7, 2021 at 13:0 Comment(0)
A
0

I found my problem in the colors.xml file - when I was adding a custom color for a button through the "Add a resource" dialog, I accidentally left off the # from the hex code. I noticed the error at the time, but it wouldn't let me delete the resource - I figured I'd fix it later (lesson learned). ESL's suggestion above about checking the styles.xml file led me to checking colors.xml, and sure enough, the color I meant to delete was still listed, and it was still missing the #. Since I had already re-added the corrected color through the "Add a resource" dialog, I removed the incorrectly entered one from the xml code and then the app compiled.

Astrodynamics answered 19/7, 2021 at 16:1 Comment(0)
G
0

I also faced this problem and seriously I tried each and evey solution related to this problem on Google but nothing works for me except my own solution. I am sharng this solution so this is beneficial to anyone.

My solution:- Android Studio emulator API level is 30 so I downgrade this APi level to 27 and my Android App started working fine now. This solution works for me.

Gerrit answered 14/8, 2021 at 0:24 Comment(1)
A downgrade is not the best solution.Compressibility
B
0

The attribute name in my color.xml caused this problem.

Problem

<color name="blue">#0000FF</color>

"Solution"

<color name="blu">#0000FF</color>

That worked...
Don't know why...
Not the best solution...

Backus answered 7/9, 2021 at 9:34 Comment(0)
B
0

I had the same issue in the naming of a dimen in dimens.xml

it was:

<dimen name="messageBoxTextSize">12dp</dimen>

and it should be:

<dimen name="message_box_text_size">12dp</dimen>

so I advise anyone who sees this to see all your resources files have a valid name.

Bunns answered 19/10, 2021 at 14:45 Comment(0)
S
0

The problem is you would have declared an already existing attr value in your custom view.

For example:

<declare-styleable name="myCustomView"> 
    <attr name="color" format="integer"/> //color is already existed attr
</declare-styleable> >
Siobhan answered 8/12, 2021 at 7:13 Comment(0)
N
0

In my situation, it's because I deleted hello_blank_fragment string from strings, it fixed after I re-add this to strings. I have no idea why this happened. It was added automatically after I create fragment. However I removed this string from layout xml after create. Even strange thing is it only gave this error on certain build variant.

Nazario answered 12/8, 2022 at 13:38 Comment(0)
S
0

For me, I am suspecting that it was a conflict in some attribute names with other libraries. This is really very hard to debug, I had to import the library locally, and removing things one after the other until I found the culprit decrlaration inside a resource xml file:

<resources>
    <declare-styleable name="FadingTextView">
        <attr name="texts" format="reference" />
        <attr name="timeout" format="integer" />
        <attr name="shuffle" format="boolean" />   <!-- here is the error -->
    </declare-styleable>
</resources>

I replaced shuffle with random, and the error disappeared.

For all its worth, this is an xml bug and Android Studio is handling it badly.

Simonnesimonpure answered 19/8, 2023 at 10:54 Comment(0)
W
-1

Based on the answer here - https://mcmap.net/q/363720/-failed-to-compile-values-file, have you tried adding the following to gradle.properties?

android.useAndroidX=true
android.enableJetifier=true
Woolgathering answered 5/8, 2021 at 21:58 Comment(0)
P
-1

Try adding this in gradle.properties file:

android.useAndroidX=true

android.enableJetifier=true

Primordial answered 19/10, 2021 at 22:25 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewHandout
A
-1

enter image description here

I have missed to put dp with values as you can see in line 14 in given screen shoot.

Antre answered 5/11, 2021 at 7:50 Comment(3)
im giving dimens value like this <dimen name="_22dp">22p</dimen> but the correct way to give dimens value is this <dimen name="_22dp">22dp</dimen>Antre
Please don’t include code as an image. Instead paste code as text, and format using Markdown.Ensile
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From ReviewMetachromatism
C
-1

android.enableJetifier=true add this line in gradle.properties file, this solution work for me.

Chemo answered 6/1, 2022 at 18:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.