Android应用构建失败:Manifest文件处理错误排查求助
构建Android应用时遇到资源链接错误
错误信息
Execution failed for task ':app:processDebugResources'. > A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction > Android resource linking failed C:\...\AndroidStudioProjects\manager10\app\build\intermediates\packaged_manifests\debug\AndroidManifest.xml:2: error: attribute android:pacakage not found. error: failed processing manifest.
AndroidManifest.xml内容
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.manager10" android:pacakage="com.example.manager10" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="32" android:targetSdkVersion="32" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <!-- xmlns:tools="http://schemas.android.com/tools"> --> <application android:allowBackup="true" android:appComponentFactory="androidx.core.app.CoreComponentFactory" android:dataExtractionRules="@xml/data_extraction_rules" android:debuggable="true" android:extractNativeLibs="false" android:fullBackupContent="@xml/backup_rules" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.Manager10" > <!-- removed activity from here --> <service android:name="androidx.room.MultiInstanceInvalidationService" android:directBootAware="true" android:exported="false" /> <provider android:name="androidx.startup.InitializationProvider" android:authorities="com.example.manager10.androidx-startup" android:exported="false" > <meta-data android:name="androidx.emoji2.text.EmojiCompatInitializer" android:value="androidx.startup" /> <meta-data android:name="androidx.lifecycle.ProcessLifecycleInitializer" android:value="androidx.startup" /> </provider> <uses-library android:name="androidx.window.extensions" android:required="false" /> <uses-library android:name="androidx.window.sidecar" android:required="false" /> </application> </manifest>
Gradle构建配置(app/build.gradle)
plugins { id 'com.android.application' } android { namespace 'com.example.manager10' compileSdk 32 defaultConfig { applicationId "com.example.manager10" minSdk 32 targetSdk 32 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } buildFeatures { viewBinding true } } dependencies { implementation 'androidx.room:room-runtime:2.4.0' annotationProcessor 'androidx.room:room-compiler:2.4.0' implementation "androidx.cardview:cardview:1.0.0" implementation "androidx.core:core:1.8.0@aar" //noinspection GradleCompatible implementation "com.android.support:percent:23.0.0" implementation 'androidx.appcompat:appcompat:1.5.1' implementation 'com.google.android.material:material:1.2.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1' implementation 'androidx.navigation:navigation-fragment:2.5.3' implementation 'androidx.navigation:navigation-ui:2.5.3' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.4' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0' } //gradleEnterprise { // buildScan { // termsOfServiceUrl = "https://gradle.com/terms-of-service" // termsOfServiceAgree = "yes" // } //}
已尝试的解决方法
- 启用Gradle Enterprise
- 清理并重建项目
- 将minSDK与targetSDK统一设置为32
解决方案
错误根源是AndroidManifest.xml里的属性拼写错误且重复定义:
android:pacakage="com.example.manager10"这一行存在拼写错误(pacakage应为package),且已经有正确的package="com.example.manager10"属性,属于冗余错误配置。
解决步骤:
- 打开项目中的
AndroidManifest.xml文件 - 删除
android:pacakage="com.example.manager10"这一行代码 - 同步Gradle(点击工具栏的"Sync Project with Gradle Files"按钮)
- 重新构建项目
另外,Manifest中注释的<!-- xmlns:tools="http://schemas.android.com/tools"> -->格式有误,建议修正为<!-- xmlns:tools="http://schemas.android.com/tools" -->,避免后续可能的解析问题。
内容的提问来源于stack exchange,提问作者Dhanya Padasalgi
相关产品推荐
相关产品推荐

