Why AndroidStudio shows warning "Namespace declaration is never used"?
Asked Answered
P

2

10

This is my layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
</LinearLayout>

Taked from the android official training

In the second line, AndroidStudio shows this warning:

Namespace declaration is never used

Why this happens?

Thank you.

Priedieu answered 17/11, 2013 at 22:23 Comment(4)
The statement that the tools namespace is not used is perfectly correct, but I've no idea why the parser chooses to report this as a warning, since unused namespaces normally do no harm.Experimentalism
Yes, But I think having an unused namespace is like having an unused variable or method. So by default the ide warns the unnecessary code.Priedieu
Well, warnings are a matter of opinion, but so many XML-generation processes produce XML with redundant namespaces that in my view, a tool that warns about them is going to get very irritating. Also, you can't automatically detect that a namespace declaration is redundant; it might be used only (as in XSLT) to declare prefixes used by QNames-in-content.Experimentalism
How you said, "warnings are a matter of opinion". In my opinion is good thing the ide warns unused things, even in xml.Priedieu
P
12

This is because you don't have anything with tools namespace actually declared in your xml.

Look at the android namespace, you have 3 elements with that namespace, but none for tools.

The namespace tools (http://schemas.android.com/tools) is used for the GUI designer and is not used for running apps on Android devices so you can safely remove it.

Photoplay answered 17/11, 2013 at 22:25 Comment(0)
D
1

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

Devisor answered 12/6, 2022 at 13:21 Comment(1)
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From ReviewCima

© 2022 - 2024 — McMap. All rights reserved.