KSUERS
KSUERS

Reputation: 589

Failed to compile values file

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?

Upvotes: 47

Views: 94878

Answers (26)

dzboot02
dzboot02

Reputation: 2970

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.

Upvotes: 0

Miguel Tom&#225;s
Miguel Tom&#225;s

Reputation: 1911

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>

Upvotes: 71

Hesam Marshal
Hesam Marshal

Reputation: 319

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>

Upvotes: 5

Cembora
Cembora

Reputation: 346

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.

Upvotes: 0

Huseynbaba
Huseynbaba

Reputation: 70

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:)

Upvotes: 1

Symtox
Symtox

Reputation: 415

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)

Upvotes: 3

Bilal Aslam
Bilal Aslam

Reputation: 9

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

Upvotes: -1

strayfox0325
strayfox0325

Reputation: 51

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.

Upvotes: 5

Sanjay Kumar
Sanjay Kumar

Reputation: 21

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> >

Upvotes: 0

wasi
wasi

Reputation: 1

enter image description here

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

Upvotes: -1

Parth Sharma
Parth Sharma

Reputation: 1

Try adding this in gradle.properties file:

android.useAndroidX=true

android.enableJetifier=true

Upvotes: -1

Mahmoud Ayman
Mahmoud Ayman

Reputation: 1324

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.

Upvotes: 0

Mc_Topaz
Mc_Topaz

Reputation: 637

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

Upvotes: 0

Awais Nayyar
Awais Nayyar

Reputation: 11

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

Upvotes: 1

Pawan Vats
Pawan Vats

Reputation: 1

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.

Upvotes: 0

Samuel Agbede
Samuel Agbede

Reputation: 380

Based on the answer here - https://stackoverflow.com/a/68512884/2229913, have you tried adding the following to gradle.properties?

android.useAndroidX=true
android.enableJetifier=true

Upvotes: -1

gtxtreme
gtxtreme

Reputation: 3566

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

Upvotes: 12

Maree Webster
Maree Webster

Reputation: 1

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.

Upvotes: 0

Siddharth Saxena
Siddharth Saxena

Reputation: 29

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.

Upvotes: 0

RakeSH KumAR
RakeSH KumAR

Reputation: 21

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>

Upvotes: 2

Abhinav Verma
Abhinav Verma

Reputation: 61

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

Upvotes: 5

Jignesh Patel
Jignesh Patel

Reputation: 449

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.

Upvotes: 7

七岁小猫
七岁小猫

Reputation: 1

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

Upvotes: 0

Zain
Zain

Reputation: 40810

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>

Upvotes: 2

wildcat12
wildcat12

Reputation: 1010

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.

Upvotes: 0

Nima Ganji
Nima Ganji

Reputation: 601

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!

Upvotes: 0

Related Questions