获取 http://schemas.android.com/apk/res/android 时出错

cha*_*teg 6 android android-manifest android-studio

好吧,我正在网上浏览教程,然后当我尝试将 build.gradle 文件更改为compileSdkVersion 21 而不是 23 时,一切都失去了情节,现在我之前的所有项目等都显示错误。

在 AndroidManifest.xml 中,2 个http行和所有android: 都是红色的,并且活动开始标记下面也有一条红色的波浪线。我对我做错了什么一无所知!就像互联网已经消失了一样?只是一个菜鸟,所以我不知道请帮忙!

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:android="http://schemas.android.com/tools"
          package="com.site.project" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>

    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

ade*_*hus 1

您的清单文件中的xmlns:android命名空间有重复的架构定义- 每个命名空间只允许有一个架构,我怀疑编译器会因重复的条目而感到困惑。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:android="http://schemas.android.com/tools"
          package="com.site.project" >
Run Code Online (Sandbox Code Playgroud)

应该:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="com.site.project" >
Run Code Online (Sandbox Code Playgroud)

命名空间模式定义很重要 - 它们用于定义属性前缀。因为您的重复条目使 android 命名空间无效,所以所有以 为前缀的属性都android:将是错误的 - 这就是为什么所有android:属性都会显示错误(红线)。

或者,如果您未tools:在清单中使用带有前缀的任何属性,则只需完全删除工具命名空间即可:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.site.project" >
Run Code Online (Sandbox Code Playgroud)