Issue
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?
Solution
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.
Answered By - ChuongPham
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.