每当我尝试构建一个项目时,就会出现debug \ manifest文件,并说build文件夹下的文件是生成的,不应该被编辑,并且会出现很多错误,说android:版本名称,允许备份,其他人不应该在这里,即使我没有编辑它们。这适用于每个Android项目,甚至是新的空项目。 我尝试使缓存无效并重新启动 重建/清理项目 卸载/重新安装android 3.0,一旦我从2.3.3升级到3.0 btw,就会出现此错误。
以下是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正在为生成的debuggable清单文件添加代码,但由于某些原因,我不知道为什么,对此问题的任何建议都会非常感谢,这里是生成的清单文件的示例
<?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
}
答案 0 :(得分:2)
您收到错误是因为AAPT2不允许使用下划线字符&#39; _&#39;作为包名称中的第一个或最后一个字符。在您的包裹名称中,它是&#39; moiz _&#39;中的最后一个字符
请关注https://issuetracker.google.com/68468089处的开放式错误以获取更多信息。