Vipul
Vipul

Reputation: 28103

Android Studio: “Execution failed for task ':app:mergeDebugResources'” if project is created on drive C:

I added Google Play services as a dependency in my current project. If I save the project on the C: drive, I get the following error while syncing up the project:

Error: Execution failed for task ':app:mergeDebugResources'.
       > Error: Failed to run command:
       C:\Program Files (x86)\Android\android-studio\sdk\build-tools\android-4.4.2\aapt.exe s -i C:\Users\ashokp\Desktop\Studio\AndroidV2SDK_AndroidStudioFormat\Google Play
       Services\SampleApplication\AndroidV2SDKSampleApp_GooglePlayServices\app\build\exploded-aar\com.google.android.gms\play-services\4.3.23\res\drawable-hdpi\common_signin_btn_text_focus_light.9.png -o
       C:\Users\ashokp\Desktop\Studio\AndroidV2SDK_AndroidStudioFormat\Google Play
       Services\SampleApplication\AndroidV2SDKSampleApp_GooglePlayServices\app\build\res\all\debug\drawable-hdpi\common_signin_btn_text_focus_light.9.png
       Error Code:
       42

This only happens if the project is saved on the C: drive. If I save it to some other drive, it works perfectly.

Does anyone else face this issue? What causes this? How can I fix/circumvent this?

enter image description here

Upvotes: 51

Views: 206018

Answers (30)

Relie Essom
Relie Essom

Reputation: 1378

Try cleaning you project by running:

cd android && ./gradlew clean && ./gradlew && cd ..

then run:

npx react-native run-android

or

npx expo run:android

Hope this helps!

Upvotes: 0

Suraj Kamble
Suraj Kamble

Reputation: 11

I had rebased on master branch that had a new module addition. and i had "offline mode" ON for gradle. turned it on and rebuilt the project. it worked for me.

happy coding.

Upvotes: 0

Dame Gjurchinoski
Dame Gjurchinoski

Reputation: 159

You have " ' " symbol in your strings or arrays somewhere ... erase it !!!

I have LET'S DOI IT , after erasing " ' " and LET'S was LETS , problem disapered

Upvotes: 1

Lorenzo Gentili
Lorenzo Gentili

Reputation: 11

This caused the problem for me: I put an ' character on my "strings.xml" file and it crashed everything.

After deleting that ' character it works...

Upvotes: 1

In my case the problem was with the recent change in color XML i failed to insert '#' into the XML file. Please check ur recent changes that can be a cause for concern for this error.

Upvotes: 0

Mehmet Ibrahim
Mehmet Ibrahim

Reputation: 31

In my case this error was due to character in string.xml file.

from

<string name="machine_coords">MACHINE\nCOORD'S</string>

to

<string name="machine_coords">MACHINE\nCOORD"'"S</string>

Upvotes: 0

Phil
Phil

Reputation: 1070

I encountered this error and by process of elimination I discovered the problem to be a single apostrophe (') in a string resource. (Specifically, a string array item.) Replacing the apostrophe with the &#39; entity didn't work either. Escaping it with \' however, did work and my project built. I discovered the proper escape code through Android Studio's string resource editor. The build error message was completely unhelpful.

Upvotes: 1

nas mohd
nas mohd

Reputation: 11

I just found out that I had defined some color in colors.xml twice and after commenting one of them out, it solved the issue. and now i'm furious

Upvotes: 1

UzumakiL
UzumakiL

Reputation: 403

Check if all the files in the values folder are correct. In my case it was the strings.xml where I forgot to escape single quotes.

Upvotes: 0

Philz97
Philz97

Reputation: 61

I my case, I had duplicated properties in the xml file. The 'android:layout_height' was in my layout tag and also in one of his child.

Upvotes: 0

yakup Sintaf
yakup Sintaf

Reputation: 15

Add this two lines to your build.gradle(app)

aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false

Upvotes: -1

Sigilai Brian
Sigilai Brian

Reputation: 141

I encountered this issue while working on a Flutter Application. I solved it by going to Tools > Flutter > Flutter Clean.

Upvotes: 0

Roman Strakhov
Roman Strakhov

Reputation: 220

In my case, the problem was caused by having a button with an angle bracket inside android:text field:

<Button
   ...
   android:text="<-"
/>

Changing it to android:text="back" fixed everything.

While having "<-" as a hardcoded text on a button isn't the best practice, it's a shame people have to spend so much time on finding solutions to these kind of issues without getting any informative hints from gradle on what is wrong.

Upvotes: 0

Vivek Hande
Vivek Hande

Reputation: 1009

when we add some new thing in out project, in that case some times resources might get duplicate that time it will give the error while run the app, in my case also get same issue I had face, while I had added the kotlin activity in java project, in it gives me error

Execution failed for task ':app:mergeDebugResources'. ...\themes.xml: Error: Duplicate resources

so in this case please check the local history and remove the duplicate resources from res folder, so simply revert that changes

Upvotes: 1

RafaelJan
RafaelJan

Reputation: 3606

If you are working on PC of a company that uses a proxy you must turn on your VPN

Upvotes: 1

Yatheesh Kumar
Yatheesh Kumar

Reputation: 11

Adding the right repository in Project build.gradle solved the issue. In my case Google Maven Repository was needed and was added as below in the build.gradle

repositories {
google()
}

refer to this link for declaring repositories: https://docs.gradle.org/current/userguide/declaring_repositories.html

Upvotes: 1

Vahid
Vahid

Reputation: 1758

For developers who live in Iran, Just rebuild while offline. You're done! (it's related to sanctions!)

Upvotes: 12

Kishan Thakkar
Kishan Thakkar

Reputation: 459

I was facing this issue after i updated to Android-Studio 3.6 the only way that worked for me was downgrading project build.gradle setting by changing

from

dependencies {
    classpath 'com.android.tools.build:gradle:3.6.0'
}

to

dependencies {
    classpath 'com.android.tools.build:gradle:3.3.0'
}

Upvotes: 2

Ananta Prasad
Ananta Prasad

Reputation: 3859

If you are using ionic in config.xml update widget tag with "xmlns:android="http://schemas.android.com/apk/res/android"

<widget id="io.ionic.starter" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">


<widget/>

Upvotes: 1

JaneSnail
JaneSnail

Reputation: 51

I have a similar problem with Error:Execution failed for task ':app:mergeDebugResources. And at last I found the reason is the pictures resource error which use the incorrect ".9.png".

Upvotes: 5

Makarand
Makarand

Reputation: 1123

In my case

  1. I Followed This answer

  2. Changed the location of project.

  3. Tried another android device [Build and success install]

  4. Tried on my android device [Build and success install * Uninstall any previous version of same app on device]

Edit- Again it happend

I had this error message and lot of others like

x-version is deprecated and use y-version instead and it'll be removed in 2019

and all of my project started giving same error messages suddenly.

Android studio was giving warnings about my antivirus program. I tried configuring it but didn't work.

Finally I uninstalled QuickHeal antivirus from my system and all is well now

Upvotes: 2

Dinesh Kc
Dinesh Kc

Reputation: 51

Dont make name with capital letters . Always use lowercase for naming . This will work fine . like companyLogo.png will raise error but company_logo.png will work fine.

Upvotes: 1

Muhammad Etisam Zafar
Muhammad Etisam Zafar

Reputation: 452

Relocate the project in an outer directory.

For example from C:/Users/x/desktop/AndroidProject to C:/projects/AndroidProject.

Upvotes: -1

Milind Chaudhary
Milind Chaudhary

Reputation: 1740

Update your gradle build tools in project level gradle , and it will show you the exact resource that is causing the error.

Upvotes: 1

Raj
Raj

Reputation: 698

Remove any capital letters or other not allowed symbols in resource file name.

Example: activity_parkingList --> activity_parking_list

Upvotes: 1

Ranjithkumar
Ranjithkumar

Reputation: 707

In drawable assets there was an image format which was an unsupported image. When i removed the image every thing started working fine.

Upvotes: 2

Choletski
Choletski

Reputation: 7535

In Android Studio 1.4 with buildToolsVersion '22.0.1' the approach of fvasquezc23 worked for me with a restart and cache invalidation.

So, after you change the location of your project folder – copy/paste the folder onto disk D: (or somewhere else with no big ‘folder in folder’ structure), just

  • go to “File” -> “Invalidate Caches/Restart” (below “Synchronize”)
  • select first option “Invalidate and Restart”

Upvotes: 3

fvasquezc23
fvasquezc23

Reputation: 912

This is caused by the path length restriction. I think it's 256 characters maximum.

Relocate your project and the build will succeed.

Upvotes: 61

DoubleCui
DoubleCui

Reputation: 59

add this in module's build.gradle.

android{
    aaptOptions.cruncherEnabled = false
    aaptOptions.useNewCruncher = false
} 

Upvotes: 4

L-N
L-N

Reputation: 11

I encountered the same error.

In the end, the problem was that I used an image in res/drawable that I copied in there and saved it as .png although the original file was .jpg .

I deleted the file (there's a warning message if there are still usages for the item in your code, but you can ignore it) and pasted it in with the original .jpg ending.

After a cleanup and gradle syncronization the error disappeared.

Upvotes: 1

Related Questions