Resource already defined gradle Android studio - android

I have different image sizes in my drawable resource folders for different screen sizes. they are all splash_login.png splash_screen.png. In my layout-large resource directory however I have splash_login.jpg and splash_screen.jpg because the images are very big. Now when I try to run gradle build i get the following error in my stack trace
build/intermediates/symbols/release
Error Code:1
Output:
res/drawable-large-v4/splash_login.png:0: error: Resource entry splash_login is already defined.
res/drawable-large-v4/splash_login.jpg:0: Originally defined here.
res/drawable-large-v4/splash_screen.png:0: error: Resource entry splash_screen is already defined.
res/drawable-large-v4/splash_screen.jpg:0: Originally defined here.
I know this is occuring because the file extention has changed but does anyone know how to get around it without reverting my large images to .png files??
Thanks!

Found the answer. Running the following command fixed it for me :
gradle clean build assemble

Generally happen when you rename a resource (I had the problem with a .xml.xml I had to change to .xml)
From Android Studio :
Build > Rebuild Project

another option is to find the file in the build cache folders and rename/delete it there.
on my windows machine the problem file was in the '[project directory]\build\res\all\debug\raw' folder

Related

Android resource linking failed - How to solve it?

I recently changed the icon of my app. When I run the app using USB debugging on my phone, everything is fine, the app compiles and the icon is as it should be. But as soon as I try to generate a signed APK, the compilation ends with this error:
A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
Android resource linking failed
C:\Users\Adam\AndroidStudioProjects\Generator\app\build\intermediates\packaged_manifests\release\AndroidManifest.xml:11: error: resource mipmap/ic_launcher not found.
Which is strange because otherwise everything works and the xml file is where it's supposed to be. I created the icons using Image Asset and they generated correctly. The only thing that comes to me as a possible cause is that for ic_launcher there is only an xml file, but ic_launcher_round has a whole folder with png images as well. Also, in the manifest there is a preview of the icon only for the round version, it is not loaded for the regular version:
How can I solve this?
Solved, it was enough to select the icon as res directory: main when confirming the path.

Error:Some file crunching failed, see logs for details afer update gradle

Afer update gradle version to classpath 'com.android.tools.build:gradle:2.3.0' I got this error.
Error:Some file crunching failed, see logs for details
Error:Execution failed for task ':app:mergeDebugResources'.
> Error: Some file crunching failed, see logs for details
AAPT err(Facade for 596378712): \\?\C:\Users\Я\.android\build-cache\2fe51ff37440fab8f5f875609a799aebf31c9e02\output\res\drawable-xxxhdpi-v4\abc_ic_menu_share_mtrl_alpha.png ERROR: Unable to open PNG file
AAPT err(Facade for 596378712): \\?\C:\Users\Я\.android\build-cache\2fe51ff37440fab8f5f875609a799aebf31c9e02\output\res\drawable-xxxhdpi-v4\abc_tab_indicator_mtrl_alpha.9.png ERROR: Unable to open PNG file
AAPT err(Facade for 596378712): \\?\C:\Users\Я\.android\build-cache\2fe51ff37440fab8f5f875609a799aebf31c9e02\output\res\drawable-hdpi-v4\abc_btn_radio_to_on_mtrl_015.png ERROR: Unable to open PNG file
I'm not using 9.png files. How can I fix it?
I have exactly same problem in Android Studio 2.3.
I wasted 2 days to solve this problem.
Your problem is
AAPT err(Facade for 596378712): \\?\C:\Users\Я\.android\build- .....
Folder name of your account(reverse R?) is not ascii folder name, so build-cache cannot recognize your folder.
To Solve:
Change folder name : it's impossible in windows 10.
not use build cache: Leos Literak's answer. not good solution.
Best solution: change build-cache path.
refer to https://developer.android.com/studio/build/build-cache.html
For Ex:
in gradle.properties
android.buildCacheDir=D:/android-studio/build-cache
You can build your app cleanly.
Thanks.
I have upgraded to Studio 2.3 as well and this error suddenly occured.
AAPT: \\?\C:\Users\Leoš\.android\build-cache\ce4c6faf7b6acf7c9a9f7875a69dc5776c2cfd5b\output\res\drawable-xhdpi-v4\msbp_math_compass.png ERROR: Unable to open PNG file
I realized one similarity in your and my logs: non-ASCII characters in user name. Then I found that it is a build cache directory. And there was info how to turn it on. So I tried to turn it off with:
gradle.properties
android.enableBuildCache=false
And it works! I can compile my project again. I submitted issue 236304 to Google.
Another option is to change build cache location:
android.enableBuildCache=true
android.buildCacheDir c:\\Dev\\Android\\cache\\
I started getting this error too with Android Studio 2.3 on Mac. Neither disabling the buildCache nor changing the location of the buildCache resolved the problem.
Renaming all of my 9-patch drawables from 'xyz.9.png' to 'xyz.png' - removing the '.9' in the filename - fixed the problem.
Check your png files, in my case that was the problem (One picture was a JPEG file with .png at is end)
Remove it/them and remplace it/them by "real" png files and it may works
The path of the file might be too long for the compiler to build with it. Try moving your project to another location to reduce the length of the destination.
I ran into the same situation as #wooldridgetm.
Later I found that if my 9-patch file has marked stretch area for both left and top side, not only one side, then the problem is solved.
I don't know if it is allowed to have only one side before. Hope this help.
The problem is related to 1 corrupted image file in drawable.
I changed it and the problem was solved very quickly.
The answer is very simple, but the error message is rather ambiguous.
I changed the gradle and android studio, but the solution was very simple than what I thought.
In my case, it was some corrupted PNG file in resources too.
Try going through all of your images and see if you are able to view them in some external preview program.

Illegal underscore in R.java

After updating to Android Studio 1.3.2, I've got strange mistake
Error:(2056, 77) error: illegal underscore in R.java (more details on the screenshot below)
But name 11880432_466668553495145_5076754104009227271_n was not found in project at all anywhere, except R.java. Also, this color was found in android support, design support libraries and android support cardview, but it has normal names there
UPD
There was a problem with encoding in file name in drawable resource directory. Problem solved
It's a bug, I solved this problem doing
Build > Clean Project or Build > Rebuild Project
If it didn't solve your problem make sure that in your Drawable folder are not a Drawable with a name without uppercase and symbols like (#,#,$) etc.

Error Building Project in Android Studio "Error: No resource found that matches the given name (at ____ with value '#drawable/<name>')

I've searched all over Google, stackoverflow and other android programming websites, many have suggestions for people who have misplaced files from one folder to another and so forth.. But none that illustrate the problem I'm facing.
It's not a corrupt file as in the case here as I tried this with no success.
The error I'm facing is similar though:
[debug] C:\Users\Name\AppData\Local\Temp\android_manifest_copy6264790980678653632tmp\AndroidManifest.xml:11: error: Error: No resource found that matches the given name (at 'icon' with value '#drawable/ic_launcher').
Similarly, this is happening with an #string element, #style element and another #string, examples below:
'#string/app_name'
'#style/AppTheme'
'#string/app_name'
One thing that I have noticed, and coming from the world of Eclipse, I cannot explain this behavior in Android Studio.. In my 'main' project folder, everything exists and builds correctly for debugging. It seems that Android Studio is trying to build off of a 'debug' folder, which will not build when running 'Build' > 'Rebuild Project'.
Does anyone know where I can place these missing files to get the project to build? Or is this some other problem?
Alright, so after fussing with the rebuild for hours trying different methods (renaming particular files [i.e. those with the problems], rebuilding the app after renaming folders inside the build folder, etc) I finally decided that I would go to the source of the problem and see if it worked like other IDE's. Indeed it did, this is how I performed the fix:
Find the location of the problem - For me, all four of the errors I had were inside the 'build' folder of the project.
Close any open instances of the project
While the project is closed, rename this folder from windows explorer (or other if youre using a different OS) (i.e. If the folders name is "build", rename it to "build.old")
Open the project once more
Go to Build > Rebuild Project
You should not have any issues doing this, like I did.
Specifications:
IDE Platform: Android Studio
IDE Version: Android Studio (I/O Preview) 0.2.2
JRE: 1.7.0_25
My problem is about #drawable/img_1, the pic is JPEG format, while it's extension name is png, I force to rename it jpg extension. Then it builds successfully.
If anyone is using Gradle and sees this it's good to remind about the convention directory structure.
For Gradle you have to put your resources in src/main/res. I migrated a project to Gradle and got the said error when I hadn't moved the res/ directory from the old structure.

Android R Cannot be resolved issue

I have just been working on my android project in eclipse and all of a sudden this error appeared, my manifest file matches the name of my application etc.............!
What I have noticed is that that the auto generated Java files are missing from the gen folder its completely empty now.
orginally I had to create a default.properties file as there wasn't one present and it was working fine uptil the point i tried to add a button into one of my xml files. Tried to clean project too and that hasn't resolved the issue either.
Any ideas?
This error is usually caused because you have an error in one of your resources. Check to make sure that there are no errors in the xml resource files or the drawable directories. In the list of errors you are seeing you should look at the top most error and see if you can resolve this. What tends to happen is that an error in one of your resource files is causing the generation of the R file to fail. Once the R file fails to generate you will see a huge list of errors but they are all caused by the one error.
Remove the gen folder from Project Name ->Properties -> Java Build Path ->Source. You will get an error message after removing it. Now Add the gen folder again in the same way. You can now see the R class. If the problem remain, then try to remove both src and gen; add them again.
use "Project" -> "Clean" in Eclipse to re-generate your R file and fix other android issues.
...sometimes this helps a lot! ;D

Categories

Resources