以下是我的fragment_rate.xml
布局XML文件:
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
tools:context=".view.ui.RateFragment"
android:layout_height="match_parent">
<FrameLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
</FrameLayout>
</layout>
当我编译它时,我遇到了这个特殊错误:
Android resource compilation failed
Output: /home/sparker0i/CurrencyConverter/app/build/intermediates/incremental/mergeDebugResources/stripped.dir/layout/fragment_rate.xml:10: error: duplicate attribute.
Command: /home/sparker0i/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.1-4818971-linux.jar/d811e9cf0b30534b0c407565dcc71d36/aapt2-3.2.1-4818971-linux/aapt2 compile --legacy \
-o \
/home/sparker0i/CurrencyConverter/app/build/intermediates/res/merged/debug \
/home/sparker0i/CurrencyConverter/app/build/intermediates/incremental/mergeDebugResources/stripped.dir/layout/fragment_rate.xml
Daemon: AAPT2 aapt2-3.2.1-4818971-linux Daemon #0
从此错误消息开始,第10行解析为FrameLayout内部的layout_width引用。奇怪的事实是,当我交换layout_height和layout_width的引用时,在第10行仍然出现相同的错误。
如果有重复的错误,我在互换时应该在第9行收到错误消息,但是错误仍然在第10行。
请帮助我。
PS。听起来很奇怪,但是还有另一个用户面临类似的问题here
EDIT1:这是更详细的错误日志:
org.gradle.internal.UncheckedException: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Failed to compile android resource '/home/sparker0i/CurrencyConverter/app/src/main/res/layout/fragment_rate.xml'.
Output: /home/sparker0i/CurrencyConverter/app/src/main/res/layout/fragment_rate.xml:10: error: duplicate attribute.
Command: /home/sparker0i/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.1-4818971-linux.jar/d811e9cf0b30534b0c407565dcc71d36/aapt2-3.2.1-4818971-linux/aapt2 compile --legacy \
-o \
/home/sparker0i/CurrencyConverter/app/build/intermediates/res/merged/debug \
/home/sparker0i/CurrencyConverter/app/build/intermediates/incremental/mergeDebugResources/stripped.dir/layout/fragment_rate.xml
Daemon: AAPT2 aapt2-3.2.1-4818971-linux Daemon #2
at org.gradle.internal.UncheckedException.throwAsUncheckedException(UncheckedException.java:63)
at org.gradle.internal.UncheckedException.throwAsUncheckedException(UncheckedException.java:40)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:76)
at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:50)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:124)
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.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:113)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:95)
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$1.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.access$200(DefaultTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.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$1.run(ManagedExecutorImpl.java:46)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Failed to compile android resource '/home/sparker0i/CurrencyConverter/app/src/main/res/layout/fragment_rate.xml'.
Output: /home/sparker0i/CurrencyConverter/app/src/main/res/layout/fragment_rate.xml:10: error: duplicate attribute.
Command: /home/sparker0i/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.1-4818971-linux.jar/d811e9cf0b30534b0c407565dcc71d36/aapt2-3.2.1-4818971-linux/aapt2 compile --legacy \
-o \
/home/sparker0i/CurrencyConverter/app/build/intermediates/res/merged/debug \
/home/sparker0i/CurrencyConverter/app/build/intermediates/incremental/mergeDebugResources/stripped.dir/layout/fragment_rate.xml
Daemon: AAPT2 aapt2-3.2.1-4818971-linux Daemon #2
at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1006)
at com.android.ide.common.workers.ExecutorServiceAdapter.close(ExecutorServiceAdapter.kt:56)
at com.android.build.gradle.internal.aapt.WorkerExecutorResourceCompilationService.close(WorkerExecutorResourceCompilationService.kt:67)
at com.android.build.gradle.tasks.MergeResources.doFullTaskAction(MergeResources.java:324)
at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:106)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
... 43 more
Caused by: com.android.builder.internal.aapt.v2.Aapt2Exception: Failed to compile android resource '/home/sparker0i/CurrencyConverter/app/src/main/res/layout/fragment_rate.xml'.
Output: /home/sparker0i/CurrencyConverter/app/src/main/res/layout/fragment_rate.xml:10: error: duplicate attribute.
Command: /home/sparker0i/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.1-4818971-linux.jar/d811e9cf0b30534b0c407565dcc71d36/aapt2-3.2.1-4818971-linux/aapt2 compile --legacy \
-o \
/home/sparker0i/CurrencyConverter/app/build/intermediates/res/merged/debug \
/home/sparker0i/CurrencyConverter/app/build/intermediates/incremental/mergeDebugResources/stripped.dir/layout/fragment_rate.xml
Daemon: AAPT2 aapt2-3.2.1-4818971-linux Daemon #2
at com.android.build.gradle.internal.res.Aapt2ErrorUtils.rewriteCompileException(Aapt2ErrorUtils.kt:44)
at com.android.build.gradle.internal.res.Aapt2CompileWithBlameRunnable$run$1.invoke(Aapt2CompileWithBlameRunnable.kt:39)
at com.android.build.gradle.internal.res.Aapt2CompileWithBlameRunnable$run$1.invoke(Aapt2CompileWithBlameRunnable.kt:28)
at com.android.build.gradle.internal.res.namespaced.Aapt2DaemonManagerService.useAaptDaemon(Aapt2DaemonManagerService.kt:71)
at com.android.build.gradle.internal.res.namespaced.Aapt2DaemonManagerService.useAaptDaemon$default(Aapt2DaemonManagerService.kt:69)
at com.android.build.gradle.internal.res.Aapt2CompileWithBlameRunnable.run(Aapt2CompileWithBlameRunnable.kt:34)
at com.android.ide.common.workers.ExecutorServiceAdapter$submit$submission$1.run(ExecutorServiceAdapter.kt:39)
at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
Output: /home/sparker0i/CurrencyConverter/app/build/intermediates/incremental/mergeDebugResources/stripped.dir/layout/fragment_rate.xml:10: error: duplicate attribute.
Command: /home/sparker0i/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.1-4818971-linux.jar/d811e9cf0b30534b0c407565dcc71d36/aapt2-3.2.1-4818971-linux/aapt2 compile --legacy \
-o \
/home/sparker0i/CurrencyConverter/app/build/intermediates/res/merged/debug \
/home/sparker0i/CurrencyConverter/app/build/intermediates/incremental/mergeDebugResources/stripped.dir/layout/fragment_rate.xml
Daemon: AAPT2 aapt2-3.2.1-4818971-linux Daemon #2
at com.android.builder.internal.aapt.v2.Aapt2DaemonImpl.doCompile(Aapt2DaemonImpl.kt:142)
at com.android.builder.internal.aapt.v2.Aapt2Daemon.compile(Aapt2Daemon.kt:81)
at com.android.builder.internal.aapt.v2.Aapt2DaemonManager$LeasedAaptDaemon.compile(Aapt2DaemonManager.kt:170)
at com.android.build.gradle.internal.res.Aapt2CompileWithBlameRunnable$run$1.invoke(Aapt2CompileWithBlameRunnable.kt:37)
... 10 more
EDIT2:从构建文件夹中打开布局文件:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" android:tag="layout/fragment_rate_0" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" tools:context=".view.ui.RateFragment" android:layout_height="match_parent">
</FrameLayout>
答案 0 :(得分:1)
在研究了<layout>
标签之后,在我看来,该标签已被Data Binding之前用于here (about the usage of the <layout>
tag),并在Android Developers documentation (about how to use such tags)中有更详细的解释。
因此,我假设<layout>
标记中的属性可能会在内部传递给父标记(在您的情况下为<FrameLayout>
)。
因此,如果您不使用数据绑定,则可以删除<layout>
标记并将这些属性重新分配给<FrameLayout>
标记,或者只是删除XML命名空间(或xmlns
个属性)。
答案 1 :(得分:0)
在我的情况下,我误将<layout>
标签赋予了ID。删除后,问题得以解决。
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/layout">
<android.support.constraint.ConstraintLayout
android:id="@+id/cm1"
android:layout_width="match_parent"
android:layout_height="match_parent">
答案 2 :(得分:0)
我能够通过同时删除android:layout_width
和android:layout_height
属性来解决此问题。
答案 3 :(得分:0)
您的绑定布局必须存在一些问题,请更正您的布局标签