android - 我的所有 android studio 项目和所有新项目都会给我带来来自调试 android list 文件的错误

标签 android android-manifest android-studio-3.0

每次我尝试构建一个项目时,都会出现 debug\manifest 文件,并表示构建文件夹下的文件已生成,不应编辑,并且会出现许多错误,表示 android:版本名称、允许备份和其他内容不应该出现在此处,尽管我没有编辑它们。每个 Android 项目都会发生这种情况,甚至是新的空项目。 我尝试使缓存无效并重新启动 重建/清洁项目 卸载/重新安装 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 出于某种原因正在将代码添加到生成的可调试 list 文件中,但我不知道为什么,对此问题的任何建议都将非常感谢,这里是生成的 list 文件的示例

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

这是实际 list 文件的示例,没有任何错误

<?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 上的开放错误了解更多信息。

关于android - 我的所有 android studio 项目和所有新项目都会给我带来来自调试 android list 文件的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46961004/

相关文章:

android - 从最近启动的应用程序和从主屏幕启动应用程序之间的区别

android - 为工具栏使用自定义字体时崩溃

android - Lint : "Newer Library Versions Available" when using variables

android - 移植 Android 以在 ARM RealView Debugger 上运行

android - RxJava 2 - 观察列表中的添加和删除

android - 在智能手机上关闭 Chrome 浏览器时 session cookie 不会过期

Android 应用程序主题 - 使用样式 xml 文件中的主题时的区别

android - 如何使用 Canvas 从圆圈内的字符串文本创建位图?

android - 如何在不丢失数据的情况下返回我的父 Activity ?

android - Android Studio 3.6 更新后 BuildConfig.FLAVOR 问题