com.android.builder.internal.aapt.v2.Aapt2Exception: Android 资源编译失败
com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
我有一个旧的 android 项目,现在我决定 运行 它,在迁移到 androidX 并在库中添加一些升级后,我在尝试时遇到了这些错误至 运行 它:
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':mergeDebugResources'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:103)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:73)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.run(DefaultTaskGraphExecuter.java:256)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:249)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:238)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access0(DefaultTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.execute(DefaultTaskPlanExecutor.java:104)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.execute(DefaultTaskPlanExecutor.java:98)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:663)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:597)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl.run(ManagedExecutorImpl.java:46)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.internal.UncheckedException: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
Output: /mnt/Media/usb/mobile-android/client14/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:5159: error: <item> inner element must either be a resource reference or empty.
/mnt/Media/usb/mobile-android/client14/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:5163: error: <item> inner element must either be a resource reference or empty.
/mnt/Media/usb/mobile-android/client14/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:5182: error: <item> inner element must either be a resource reference or empty.
/mnt/Media/usb/mobile-android/client14/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:5228: error: <item> inner element must either be a resource reference or empty.
/mnt/Media/usb/mobile-android/client14/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:5229: error: <item> inner element must either be a resource reference or empty.
Command: /home/alt/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.0-4818971-linux.jar/8ae53ed779dc0eb0d7edfbb9c8e24cf8/aapt2-3.2.0-4818971-linux/aapt2 compile --legacy \
-o \
/mnt/Media/usb/mobile-android/client14/build/intermediates/res/merged/debug \
/mnt/Media/usb/mobile-android/client14/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml
这是我的 gradle:
buildscript {
repositories {
google()
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
// classpath 'com.guardsquare.dexguard.gradle:dexguard-gradle-plugin:8.0.17'
}
}
apply plugin: 'com.android.application'
allprojects{
repositories{
google()
mavenCentral()
mavenLocal()
maven {
url "https://repo1.maven.org/maven2"
}
maven {
url "https://repo.spring.io/libs-milestone"
}
}
}
android {
compileSdkVersion 29
buildToolsVersion "27.0.3"
signingConfigs {
debug {
storeFile file('pmb-android.keystore')
storePassword 'caspianmbkeystore'
keyAlias 'caspian_mb'
keyPassword 'caspianmbkeystore'
}
release {
storeFile file('pmb-android.keystore')
storePassword 'caspianmbkeystore'
keyAlias 'caspian_mb'
keyPassword 'caspianmbkeystore'
}
}
defaultConfig {
applicationId "com.cas.android"
targetSdkVersion 29
minSdkVersion 19
versionCode 1391
versionName "1.3.9.1"
vectorDrawables.useSupportLibrary = true
signingConfig signingConfigs.debug
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility org.gradle.api.JavaVersion.VERSION_1_8
targetCompatibility org.gradle.api.JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'scala.*'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.properties'
}
lintOptions{
checkReleaseBuilds false
abortOnError false
}
}
dependencies {
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.basgeekball:awesome-validation:2.0'
implementation 'com.specyci:residemenu:1.6'
implementation 'org.greenrobot:eventbus:3.0.0'
implementation 'com.google.guava:guava:24.1-jre'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.8.6'
implementation 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
implementation 'androidx.mediarouter:mediarouter:1.2.5'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.gms:play-services:12.0.1'
implementation group: 'joda-time', name: 'joda-time', version: '2.9.9'
implementation group: 'com.ibm.icu', name: 'icu4j', version: '51.1'
}
这是gradle.properies:
android.enableJetifier=true
android.injected.build.model.only.versioned=3
android.useAndroidX=true
有什么问题?
ID 资源不应像您的那样在 XML 节点中包含文本。
我最好的猜测是,当您最初处理这个项目时,构建工具对此更加宽容。现在,他们更加严格地执行规则。
因此,如果您从那些失败的 <id>
元素中删除文本,您的状态应该会更好。
我有一个旧的 android 项目,现在我决定 运行 它,在迁移到 androidX 并在库中添加一些升级后,我在尝试时遇到了这些错误至 运行 它:
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':mergeDebugResources'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:103)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:73)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.run(DefaultTaskGraphExecuter.java:256)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:249)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:238)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access0(DefaultTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.execute(DefaultTaskPlanExecutor.java:104)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.execute(DefaultTaskPlanExecutor.java:98)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:663)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:597)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl.run(ManagedExecutorImpl.java:46)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.internal.UncheckedException: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
Output: /mnt/Media/usb/mobile-android/client14/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:5159: error: <item> inner element must either be a resource reference or empty.
/mnt/Media/usb/mobile-android/client14/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:5163: error: <item> inner element must either be a resource reference or empty.
/mnt/Media/usb/mobile-android/client14/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:5182: error: <item> inner element must either be a resource reference or empty.
/mnt/Media/usb/mobile-android/client14/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:5228: error: <item> inner element must either be a resource reference or empty.
/mnt/Media/usb/mobile-android/client14/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:5229: error: <item> inner element must either be a resource reference or empty.
Command: /home/alt/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.0-4818971-linux.jar/8ae53ed779dc0eb0d7edfbb9c8e24cf8/aapt2-3.2.0-4818971-linux/aapt2 compile --legacy \
-o \
/mnt/Media/usb/mobile-android/client14/build/intermediates/res/merged/debug \
/mnt/Media/usb/mobile-android/client14/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml
这是我的 gradle:
buildscript {
repositories {
google()
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
// classpath 'com.guardsquare.dexguard.gradle:dexguard-gradle-plugin:8.0.17'
}
}
apply plugin: 'com.android.application'
allprojects{
repositories{
google()
mavenCentral()
mavenLocal()
maven {
url "https://repo1.maven.org/maven2"
}
maven {
url "https://repo.spring.io/libs-milestone"
}
}
}
android {
compileSdkVersion 29
buildToolsVersion "27.0.3"
signingConfigs {
debug {
storeFile file('pmb-android.keystore')
storePassword 'caspianmbkeystore'
keyAlias 'caspian_mb'
keyPassword 'caspianmbkeystore'
}
release {
storeFile file('pmb-android.keystore')
storePassword 'caspianmbkeystore'
keyAlias 'caspian_mb'
keyPassword 'caspianmbkeystore'
}
}
defaultConfig {
applicationId "com.cas.android"
targetSdkVersion 29
minSdkVersion 19
versionCode 1391
versionName "1.3.9.1"
vectorDrawables.useSupportLibrary = true
signingConfig signingConfigs.debug
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility org.gradle.api.JavaVersion.VERSION_1_8
targetCompatibility org.gradle.api.JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'scala.*'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/maven/com.fasterxml.jackson.core/jackson-core/pom.properties'
}
lintOptions{
checkReleaseBuilds false
abortOnError false
}
}
dependencies {
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.basgeekball:awesome-validation:2.0'
implementation 'com.specyci:residemenu:1.6'
implementation 'org.greenrobot:eventbus:3.0.0'
implementation 'com.google.guava:guava:24.1-jre'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.8.6'
implementation 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
implementation 'androidx.mediarouter:mediarouter:1.2.5'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.gms:play-services:12.0.1'
implementation group: 'joda-time', name: 'joda-time', version: '2.9.9'
implementation group: 'com.ibm.icu', name: 'icu4j', version: '51.1'
}
这是gradle.properies:
android.enableJetifier=true
android.injected.build.model.only.versioned=3
android.useAndroidX=true
有什么问题?
ID 资源不应像您的那样在 XML 节点中包含文本。
我最好的猜测是,当您最初处理这个项目时,构建工具对此更加宽容。现在,他们更加严格地执行规则。
因此,如果您从那些失败的 <id>
元素中删除文本,您的状态应该会更好。