0
votes

I am new to Android dev and am working on my first app. I have been running into trouble trying to get an image view set up with my own image (stock photos on studio are working fine), and am getting the following error:

AAPT: error: '/home/joshua/AndroidStudioProjects/WSC/app/src/main/res/mipmap-xxxhdpi/wsc_foreground.png' is incompatible with attribute src (attr) reference|color.

I have researched around to even try to understand what this error is saying, and I think it is having trouble linking some file/resource?

I uploaded a .jpg using the add image asset option in android studio. I added a color background to the image, which was a hex number I selected.

I am not getting any errors or warnings until I build, at which point the build fails.

**Can someone please explain:

  1. What this error means.
  2. How to troubleshoot this.
  3. Where my mistake lies.**

I have attached the (hopefully sufficiently) relevant XML code.

Here is the image view inside of my fragment_first.xml, which is inside layout:

<ImageView
        android:id="@+id/wsc_image"
        android:layout_width="930dp"
        android:layout_height="585dp"
        android:layout_marginTop="44dp"
        android:contentDescription="@string/wsc_image_description"
        android:src="/home/joshua/AndroidStudioProjects/WSC/app/src/main/res/mipmap-xxxhdpi/wsc_foreground.png"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@+id/textview_first"
        app:layout_constraintStart_toStartOf="@+id/textview_first"
        app:layout_constraintTop_toBottomOf="@+id/textview_first"
        app:layout_constraintVertical_bias="0.0" />

I don't have an XML for the wsc_foreground.png, but do have a wsc.xml. I tried adding the full path in the wsc.xml for wsc_foreground.png, but this did not change anything.

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@color/wsc_background"/>
    <foreground android:drawable="/home/joshua/AndroidStudioProjects/WSC/app/src/main/res/mipmap-xxxhdpi/wsc_foreground.png"/>
</adaptive-icon>

My apologies if this is a dumb question and/or not clear. Please let me know in the comments if I need to clarify any of this.

Thanks!

3

3 Answers

1
votes

Joshua, Since it's been a while you likely have already figured this out, but the issue might be that you're using the absolute path.

instead of

/home/joshua/AndroidStudioProjects/WSC/app/src/main/res/mipmap-xxxhdpi/wsc_foreground.png

try (notice no file extension)

@mipmap/wsc_foreground
1
votes

Just now i faced same kind of error and after 45 mins of debugging found out this is a very silly mistake.

android:background="E7E7E7" Error thrown: AAPT: error: E7E7E7 is incompatible with attribute src (attr) reference|color.

Answer: android:background="#E7E7E7"(i missed # symbol).

Joshua this might not be useful for you now as i was replying very late. This can be helpful for someone else in some other part of the world😜.

1
votes

I tried to add an image and got the same error... after an hour I realised that I had missed @ sign before drawable😥 and then I used "" instead of "/" in the naming!