2015-12-08 8 views
26

我谷歌搜索我的问题,但我找不到解决方案。
当我尝试创建签名APK,我得到这个错误:错误:可疑名称空间和前缀组合[NamespaceTypo]当我尝试创建签名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 

这是这个布局文件的片段:

<?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"> 

回答

89

更改代码的xmlns:程序=“HTTP:/ /schemas.android.com/tools”与此:

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

这使我的工作。

+0

感谢您的反馈,我会记住它从我的下一个答案 –

+2

没有需要规范的答案我..我的问题固定that's足够.. –

10

您的前两行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"> 

前两行是xml文件的声明。尽管您可以在设计视图中查看页面的实际布局,但由于它需要xml工具标签,所以布局itslef在构建时仍然会遇到问题。

这个命名空间的目的是为了能够在XML文件中记录信息,并且在应用程序打包时剥离这些信息,从而不会影响运行时或下载大小。它是一个专用的Android XML命名空间。

希望这有助于:)

1

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

换句话说,当我有过Android Studio解决app前缀,它这样做:

<?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 --> 
      ... 

当它应该这样做:

<?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}"> 
      ... 
2

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

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

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

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