16

I upgraded to Android Support Library 23.2.0 and added

vectorDrawables.useSupportLibrary = true

to my build.gradle, so that I have vector drawable support for apis lower than 21. (See here for details).

I also replaced

android:src="@drawable/ic_create_black_24dp"

with

app:srcCompat="@drawable/ic_create_black_24dp"

in every Imageview that uses vector drawables.

The app compiles and works perfectly fine, but code analysis reports:

Error:(56, 9) Unexpected namespace prefix "app" found for tag ImageView

Why is this the case? Why is it compiling although I am getting errors?

EDIT: I have added

xmlns:app="http://schemas.android.com/apk/res-auto"

in my root layout.

Lukas Lechner
  • 7,881
  • 7
  • 40
  • 53

5 Answers5

23

Lint, Android's code analysis tool, doesn't seem to know about support vector drawables, yet. You can safely ignore the error by adding tools:ignore="MissingPrefix" to the ImageView tag.

Kirill Rakhman
  • 42,195
  • 18
  • 124
  • 148
  • 1
    Also add `tools:src="@drawable/ic_create_black_24dp"` to preview the drawable in the layout – osrl Mar 04 '16 at 13:30
  • It works for me. Please mentioned this line too in your answer xmlns:tools="http://schemas.android.com/tools" – VVB Dec 27 '16 at 06:02
2

Change ImageView to android.support.v7.widget.AppCompatImageView in your XML

Student222
  • 3,021
  • 2
  • 19
  • 24
1

You're seeing this error, because original ImageView doesn't have srcCompat attribute. This attribute is used only by AppCompatImageView, which is injected instead of ImageView you declared. This error is easy to spot when using overloaded view inflaters. Lint performs static analysis and doesn't know about hacks you can do with xml from code.

Zielony
  • 16,239
  • 6
  • 34
  • 39
0

Need to add this to top parent layout :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
Leonid Veremchuk
  • 1,952
  • 15
  • 27
0

Add xmlns:app="schemas.android.com/apk/res-auto" as attribute either to your ImageView or to the Top-Level Tag like LinearLayout, CoordinatorLayout, RelativeLayout.. etc

<ImageView android:layout_width="match_parent"
           android:layout_height="match_parent"
           app:srcCompat="@drawable/ic_create_black_24dp"
           xmlns:app="http://schemas.android.com/apk/res-auto"/>

or in parent layout

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            xmlns:app="http://schemas.android.com/apk/res-auto"/>
Dhaval Parmar
  • 18,812
  • 8
  • 82
  • 177