我的所有 android 工作室项目和所有新项目都给我来自调试 android 清单文件的错误

All of my android studio projects and all new ones give me errors coming from the debug android manifest file

每次我尝试构建一个项目时,都会出现 debug\manifest 文件,并说构建文件夹下的文件已生成,不应编辑,并且会出现许多错误,说 android:version name, allow backup其他人不应该在这里,即使我没有编辑它们。每个 android 项目都会发生这种情况,甚至是新的空项目。 我尝试使缓存无效并重新启动 重建/清洁项目 Uninstalling/Reinstalling android 3.0,顺便说一句,我从 2.3.3 升级到 3.0 后就出现了这个错误。

这是 gradle 构建错误

Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:compileDebugAndroidTestSources, :app:compileDebugUnitTestSources, :app:compileDebugSources]
C:\Users\moiz_\Desktop\AndroidStudioProjects\MyApplication2\app\build\intermediates\manifests\full\debug\AndroidManifest.xml
Error:(2) error: attribute 'package' in <manifest> tag is not a valid Java package name: 'com.example.moiz_.myapplication2'.
Error:(2) attribute 'package' in <manifest> tag is not a valid Java package name: 'com.example.moiz_.myapplication2'.
Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt

我猜 android 出于某种原因正在向生成的可调试清单文件中添加代码,但我不知道为什么,任何关于这个问题的建议都将非常感谢,这里是生成的示例清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.moiz_.myapplication2"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="24"
        android:targetSdkVersion="26" />

    <application
        android:allowBackup="true"
        android:debuggable="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity android:name="com.example.moiz_.myapplication2.MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <meta-data
            android:name="android.support.VERSION"
            android:value="26.1.0" />
        <meta-data
            android:name="android.arch.lifecycle.VERSION"
            android:value="27.0.0-SNAPSHOT" />
    </application>

</manifest>

这里是没有任何错误的实际清单文件的示例

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.moiz_.myapplication2">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

这里是build.gradle(Module:app)文件供参考

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.moiz_.myapplication2"
        minSdkVersion 24
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

和build.gradle项目文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}


您收到错误是因为 AAPT2 不允许将下划线字符“_”作为包名称中的第一个或最后一个字符。在您的包名称中,它是 'moiz_'.
中的最后一个字符 请按照 https://issuetracker.google.com/68468089 上的开放错误了解更多信息。