Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android error Duplicate Resources

I am very new to android development and am developing my first app when I got 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 duplicate here? What am I supposed to do to rectify it?

P.S. The UI was developed by my frnd who is an UI developer and then he mailed me the project on which I am now supposed to add code and functionality so it becomes hard for me to try and figure out what might be the possible error.

like image 363
Rick Roy Avatar asked Dec 18 '14 13:12

Rick Roy


2 Answers

That's because Android considers the following to be the same when you referenced the images 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 

login_bg.9.png image tells Android that this image is a 9-patch image. Whereas, the other image, login_bg.png, is a normal image. But 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 your /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.

like image 192
ChuongPham Avatar answered Sep 24 '22 20:09

ChuongPham


basically it will occur whenever the xml detects multiple files with same name, regardless of their extension type. e.g : mypicture.jpg can not be in same directory folder with mypicture.png

so does with your case, login_bg.9.png and login_bg.png in the same directory folder is not allowed.

hopefully this may be useful. have a good day

like image 30
Odhik Susanto Avatar answered Sep 24 '22 20:09

Odhik Susanto