When I build my Android app, I get this error:
Error:Error: Duplicate resources: E:\Android\LED\app\src\main\res\drawable-hdpi\login_bg.png:drawable-hdpi-v4/login_bg, E:\Android\LED\app\src\main\res\drawable-hdpi\login_bg.9.png:drawable-hdpi-v4/login_bg
Error:Execution failed for task ':app:mergeDebugResources'.
> E:\Android\LED\app\src\main\res\drawable-hdpi\login_bg.png: Error: Duplicate resources: E:\Android\LED\app\src\main\res\drawable-hdpi\login_bg.png:drawable-hdpi-v4/login_bg, E:\Android\LED\app\src\main\res\drawable-hdpi\login_bg.9.png:drawable-hdpi-v4/login_bg
I am not able to properly understand the error. What file is duplicated here? What am I supposed to do to rectify it?
The reason you are seeing this error is because Android considers the following images to be the same, based on how they are referenced in your layouts:
E:\Android\LED\app\src\main\res\drawable-hdpi\login_bg.png
E:\Android\LED\app\src\main\res\drawable-hdpi\login_bg.9.png
The first image, login_bg.png, is a normal image. The second image, login_bg.9.png, is named in such a way to tell Android that it is a 9-patch image. However, in terms of referencing the images, they are declared the same, as in the following examples.
Normal image:
<ImageView
android:id="#+id/normalImage"
android:background="#drawable/login_bg"/>
Nine-patch image:
<ImageView
android:id="#+id/ninePatchImage"
android:background="#drawable/login_bg"/>
Note: There is no difference in terms of referencing the images from the /res/drawables directory of your Android project.
See here for more info about nine-patch image, or the correct term for it is nine-patch drawable. For reference, nine-patch drawables must be declared as <name>.9.png, as in login_bg.9.png.
Therefore, simply renaming them will not solve the issue. You need to check with whoever developed the UI to see which one should be used: either the normal image (login_bg.png) or the 9-patch image (login_bg.9.png)—not both.
This error message will occur whenever the build tools detect multiple files with same name, regardless of their extension type.
For example, a file named mypicture.jpg cannot be in the same folder as mypicture.png.
In your case, login_bg.9.png and login_bg.png cannot be in the same directory.
Therefore, what you need to do is change the name of (or delete) one of the files.
Delete the image from drawable directory, because you are using same name within one folder, which is not allowed.
After I changed the initial/default ic_launcher via Resource Manager>>Image Asset>>Icon Type>> Launcher Icons
I got this error.
It happens because the initial icon still exists and with the same name inside the mipmap folder.
the solution for me was to delete the initial launcher icon.
Solution: Change your view to Project, find the initial icon, and delete it, then the error should be gone.
Solved this by going to
Build ➞ Clean Project
Using Ant instead of Gradle seemed to fix the issue for me. Many of my files have the same filename to start with a different extension (indexed resource files of various types). Ancient project, and the ancient solution worked for me.
I find a same string name in my two diff .xml file,
//a.xml
<string name="dialog_subscribe">关注</string>
//b.xml
<string name="dialog_subscribe">subscribe</string>
then i solved it by rename one of then
Related
I want to use a custom font, I downloaded the "Poppins" font and pasted the TTF files into the freshly made "font" folder and they have a red line under them, presumably trying to indicate that there is a problem with them. The "font" folder I made is located in java/res/font.
I tried to google the issue but I could not find anything about this. May you help me? I will attach a photo of the hierarchy and how they look. Android Studio doesn't give any info on what that may be. Thanks for looking into this.
enter image description here
Capital letters and - chars are not allowed in resource file names. Rename the files to all lowercase, and you can replace the - with underscore _.
I added a vector asset to a wear os project using and cannot access it using:
ContextCompat.getDrawable(mContext,R.drawable.ic_settings);
It does not seem to be finding the asset. I have the Drawable directory and see the assets in it. I opened up the xml file and there is an error:
"The drawable 'ic_settings' in drawable has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier"
I have no idea what this means. I just added it using the New -> Vector Asset menu. Does anybody know how to solve this issue?
Here is the line in the code:
Here is where it is in android studio:
When I look at the file:
Furthermore I have a roundbutton.xml in the drawable directory which is referred by R.drawable in another pice of code, and which there are no errors.
UPDATE
After doing all the checks (is the asset in the drawable directory), I closed and restarted Android Studio and it recognized them. Ye ol' reboot. Thanks to all for the responses. I am going to select the one which helped the most as the answer.
The problem is that your asset is specific to a certain configuration, so if the configuration doesn't match with device settings then the drawable can't be found by resource and will lead to a crash.
Some variants are:
- drawable (base, if not found in any folder)
- drawable-ldpi (low-resolution devices will look into it)
- drawable-mdpi (medium-resolution devices will look into it)
- drawable-v24 (devices with API level v24 or v24+ will look into it)
For more info, you can see: https://developer.android.com/training/multiscreen/screendensities
To Fix it:
Goto Android window and expand app > res > drawable, find the drawable, and right-click on it. From the menu goto Refactor > Move File...
From the text edit box remove the substring after the word "drawable" (in the image you can see "-xxxhdpi" after the drawable word which we should remove) and press Refactor.
Now, you're good to go.
Which helped me in a similar case with another file.
I redid a bunch of work to fix this error. Deleted the entire contents of the file in the IDE editor. Retyped and rechecked the contents of the entire project probably 10 times. Nothing helped. It seemed mystical.
The problem was solved like this:
I removed the ic_launcher_background.xml file. Not safe.
And created a new one. Then I typed the whole text again.
And everything became good.
Perhaps some hidden control character in the file interfered. I can't repeat the situation again.
For me creating a new file in drawable directory (instead of copying it there) helped. I just copied and pasted the content of that file to the new which I created.
Saw the same message recently, but the cause was a hyphen in the file name. I had copied the file keyboard_alt-48px.xml directly into the drawable directory:
Renaming to remove the hyphen resolved the problem.
For reference, trying to rename with the hyphen in the file name again was then highlighted as an invalid resource name:
This is my project folder, when i adding first image then it not show any error but after adding the 2nd and 3rd image it show the red lines.
I don't know where i do mistake, if anyone knows then please help me.
In Android Studio, click on View > Tool Windows > Resource Manager in the menus or click on the Resource Manager tab to the left of the Project window.
Click the + below Resource Manager, and select Import Drawables. This opens a file browser.
Make sure the name of the image you are trying to add does not resemble some keyword. I was trying to add an image in drawable with name "try". When i made it "tried" error went away. So, name your image != any keyword.
FOR YOUR CASE IN PARTICULAR:
Try invalidating cache and restarting it. Moreover, also check if the problem persists only with these two images or others too.
Names should be in lowercase.
Therefore never use names with uppercase letters in it
try removing numerals and keep a meaningful name. Also ensure that the names are in lower case
drawable folder is wrong place for png files.
In drawable are stored xml files
All png files should be stored in mipmap folders
If you want have only one png for all resolutions, store it in mipmap-anydpi
I found the problem.
Add the same image to the default drawable folder. Android Studio automatically doesn't add it to the default drawable folder.
It usually happen because of the name assigned to image file. try to put the name of file in snake_case.[error][solution]
solutionC.pngerror
I put an image in my res/drawable folder, but when I clean and build my project, I receive the error message R cannot be resolved. I don't understand why this happens, what should I do?
Check out the following link:
http://source.android.com/source/using-eclipse.html
Note: Eclipse sometimes likes to add an "import android.R" statement at the top of your files that use resources, especially when you ask eclipse to sort or otherwise manage imports. This will cause your make to break. Look out for these erroneous import statements and delete them.
After removing the erroneous imports, delete your R.java file and try to clean and build the project again. If the problem still persists, post here.
possible causes:
duplicate file names (across all drawables folders) . for example , is there a file named "h1.png" and also "h1.jpg" ?
bad files names . only letters allowed are lowercase english ones , and digits.
hidden files , like those of the OS . on windows , it's probably "Thumb.db" . either delete them , or delete & disable them. linux and mac also have such files , but with different names and usually start with "." .
Make sure your image name is in small latters and in res/drawable folder.for how we add drawables in our project and supported images formats see docs Drawable Resources
Might be you are using android.R.drawable.your_image
Remove android.R from imports. use R.drawable.your_image
For Android Studio:
Right click on res, new Image Asset
On Asset type choose Action Bar and Tab Icons
Choose the image path
Give your image a name in Resource name
Next->Finish
The image will be saved in the /res/drawable folder!
Does anybody know, where I can find the original image-files (button backgrounds, menu icons, etc.) used by Android? I'd need something like the text input background for my own view, but would like it to match the existing style as exactly as possible. Also I need the correct padding etc. But besides checking out the whole Android source from Github I have no idea where to find those images.
Go to the folder where you installed the Android SDK. You find the resources in
platforms > android-* > data > res > drawable-*
the ids of the default android resources are saved in the android R class:
getResources().getDrawable(android.R.drawable.*);
Note that R is android.R here and not your.packe.name.R!
The original files are saved in the sdk:
under platforms/android-8/data/res/drawable e.g. you can find them
I found it:
/home/quyen/Android/Sdk/platforms/android-15/data/res/drawable-mdpi