Angel Angel - 4 months ago 25
Android Question

Unexpected namespace "map" - Android Google Maps API

Here's the entirity of my XML file. The imporant part is the map fragment at the end that gives me this error: "Unexpected namespace prefix found for tag fragment" It doesn't seem to impact the code but I'm curious if anyone knows what's up. I've seen posts saying it's a Lint issue or an Eclipse problem but I'm using the latest version of Android Studio.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:background="#FFFFFF"
android:orientation="vertical">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">

<Button
android:id="@+id/button_lakeside_webview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lakeside"/>

<Button
android:id="@+id/button_spinner_webview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Spinner"/>

</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<View
android:id="@+id/colored_bar"
android:layout_width="48dp"
android:layout_height="3dp"
android:background="" />

</LinearLayout>

<!-- Unsure why it complains about the map namespace, the below code is recommended by Google -->

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraBearing="0"
map:cameraTilt="30"
map:cameraZoom="16"
map:mapType="normal"
map:uiCompass="false"
map:uiRotateGestures="false"
map:uiScrollGestures="false"
map:uiTiltGestures="false"
map:uiZoomControls="false"
map:uiZoomGestures="false"/>

</LinearLayout>

Answer

As you say there is a known bug in the Android Lint. There are a couple of issues filed:

The last one updated on Jul 14 2016 states that "Please try again on a newer version of Android Studio (2.2 or greater). If the issue still occurs file a new bug."

As a workaround you can add this property to the fragment to ignore the error (I have tested it and the map:properties work as expected):

tools:ignore="MissingPrefix"