错误:当我尝试创建签名APK时,可疑命名空间和前缀组合[NamespaceTypo]

时间:2022-05-24 15:27:08

I Googled my problem but I can't find a solution.
When I try to create a signed APK, I get this error:

我用Google搜索了我的问题,但我找不到解决方案。当我尝试创建签名的APK时,我收到此错误:

 Error:(6) Error: Suspicious namespace and prefix combination [NamespaceTypo]
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   Explanation for issues of type "NamespaceTypo":
   track these down.
   xmlns:app="http://schemas.android.com/tools"
   obscure error messages. This check looks for potential misspellings to help
   Accidental misspellings in namespace declarations can lead to some very

This is the fragment of this layout file:

这是此布局文件的片段:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/tools"
    app:layout_behavior="@null"
    android:layout_gravity="bottom|right">

4 个解决方案

#1


100  

change the code xmlns:app="http://schemas.android.com/tools" with this:

使用以下代码更改代码xmlns:app =“http://schemas.android.com/tools”:

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

的xmlns:应用= “http://schemas.android.com/apk/res-auto”

It made mine work.

它使我的工作。

#2


12  

Your first two lines of the xml code are incorrect. The whole xml file should look as follows:

您的前两行xml代码不正确。整个xml文件应如下所示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/tools"
app:layout_behavior="@null"
android:layout_gravity="bottom|right">

The first 2 lines are the declaration of the xml file. Although you are able to view the actual layout of the page in the design view, the layout itslef would still have issues when being built since it needs the xml tools tag.

前两行是xml文件的声明。虽然您可以在设计视图中查看页面的实际布局,但由于需要xml工具标记,因此在构建时它的布局仍会出现问题。

The purpose of this namespace is to be able to record information in XML files, and have that information stripped when the application is packaged such that there is no runtime or download size penalty. It is a dedicated Android XML namespace.

此命名空间的目的是能够在XML文件中记录信息,并在打包应用程序时剥离该信息,使得没有运行时或下载大小损失。它是一个专用的Android XML命名空间。

Hope this helps :)

希望这可以帮助 :)

#3


3  

The tools namespace should be used for the preview tools of the xml on android studio. For example, if you are testing a view that is hidden by default, but you want to see it on your preview you should use tools:visibility=visible.

工具命名空间应该用于android studio上xml的预览工具。例如,如果您正在测试默认情况下隐藏的视图,但您希望在预览中看到它,则应使用工具:visibility = visible。

The app namespace, as far as I know, is used to add your custom views and layouts to the namespace of the xml you want to add your views.

据我所知,app命名空间用于将自定义视图和布局添加到要添加视图的xml的命名空间中。

So all your answers are correct, but I think no one explained what the namespaces do. So for convention I recommend to use them like this:

所以你的所有答案都是正确的,但我认为没有人解释命名空间的作用。所以对于惯例,我建议像这样使用它们:

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

#4


1  

I had this same error. My problem was that Android Studio automatically put an xmlns into my layout tab instead of the root view tag when using data binding.

我有同样的错误。我的问题是,在使用数据绑定时,Android Studio会自动将xmlns放入我的布局选项卡而不是根视图标记。

In other words when I have Android Studio resolve the app prefix it did this:

换句话说,当我让Android Studio解析应用前缀时,它会这样做:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:custom="http://schemas.android.com/apk/res-auto"
        xmlns:app="http://schemas.android.com/tools"> <!-- added namespace here ... -->

    <data>

        <variable
            name="viewModel"
            type="com.example.ViewModel"/>
    </data>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:orientation="horizontal">

        <LinearLayout
            android:layout_width="..."
            android:layout_height="..."
            android:orientation="vertical"
            app:backgroundResource="@{viewModel.someResource}"> <!-- ... when trying to resolve app -->
            ...

when it should have done this:

什么时候应该这样做:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:custom="http://schemas.android.com/apk/res-auto">

    <data>

        <variable
            name="viewModel"
            type="com.example.ViewModel"/>
    </data>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  xmlns:app="http://schemas.android.com/tools" <!-- should have added here -->
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:orientation="horizontal">

        <LinearLayout
            android:layout_width="..."
            android:layout_height="..."
            android:orientation="vertical"
            app:backgroundResource="@{viewModel.someResource}">
            ...

#1


100  

change the code xmlns:app="http://schemas.android.com/tools" with this:

使用以下代码更改代码xmlns:app =“http://schemas.android.com/tools”:

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

的xmlns:应用= “http://schemas.android.com/apk/res-auto”

It made mine work.

它使我的工作。

#2


12  

Your first two lines of the xml code are incorrect. The whole xml file should look as follows:

您的前两行xml代码不正确。整个xml文件应如下所示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/tools"
app:layout_behavior="@null"
android:layout_gravity="bottom|right">

The first 2 lines are the declaration of the xml file. Although you are able to view the actual layout of the page in the design view, the layout itslef would still have issues when being built since it needs the xml tools tag.

前两行是xml文件的声明。虽然您可以在设计视图中查看页面的实际布局,但由于需要xml工具标记,因此在构建时它的布局仍会出现问题。

The purpose of this namespace is to be able to record information in XML files, and have that information stripped when the application is packaged such that there is no runtime or download size penalty. It is a dedicated Android XML namespace.

此命名空间的目的是能够在XML文件中记录信息,并在打包应用程序时剥离该信息,使得没有运行时或下载大小损失。它是一个专用的Android XML命名空间。

Hope this helps :)

希望这可以帮助 :)

#3


3  

The tools namespace should be used for the preview tools of the xml on android studio. For example, if you are testing a view that is hidden by default, but you want to see it on your preview you should use tools:visibility=visible.

工具命名空间应该用于android studio上xml的预览工具。例如,如果您正在测试默认情况下隐藏的视图,但您希望在预览中看到它,则应使用工具:visibility = visible。

The app namespace, as far as I know, is used to add your custom views and layouts to the namespace of the xml you want to add your views.

据我所知,app命名空间用于将自定义视图和布局添加到要添加视图的xml的命名空间中。

So all your answers are correct, but I think no one explained what the namespaces do. So for convention I recommend to use them like this:

所以你的所有答案都是正确的,但我认为没有人解释命名空间的作用。所以对于惯例,我建议像这样使用它们:

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

#4


1  

I had this same error. My problem was that Android Studio automatically put an xmlns into my layout tab instead of the root view tag when using data binding.

我有同样的错误。我的问题是,在使用数据绑定时,Android Studio会自动将xmlns放入我的布局选项卡而不是根视图标记。

In other words when I have Android Studio resolve the app prefix it did this:

换句话说,当我让Android Studio解析应用前缀时,它会这样做:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:custom="http://schemas.android.com/apk/res-auto"
        xmlns:app="http://schemas.android.com/tools"> <!-- added namespace here ... -->

    <data>

        <variable
            name="viewModel"
            type="com.example.ViewModel"/>
    </data>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:orientation="horizontal">

        <LinearLayout
            android:layout_width="..."
            android:layout_height="..."
            android:orientation="vertical"
            app:backgroundResource="@{viewModel.someResource}"> <!-- ... when trying to resolve app -->
            ...

when it should have done this:

什么时候应该这样做:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:custom="http://schemas.android.com/apk/res-auto">

    <data>

        <variable
            name="viewModel"
            type="com.example.ViewModel"/>
    </data>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  xmlns:app="http://schemas.android.com/tools" <!-- should have added here -->
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:orientation="horizontal">

        <LinearLayout
            android:layout_width="..."
            android:layout_height="..."
            android:orientation="vertical"
            app:backgroundResource="@{viewModel.someResource}">
            ...