AAPT2错误:一旦我将我的android工作室更新到最新版本

时间:2018-01-23 10:07:24

标签: android gradle android-gradle-3.0 aapt2

我试过" multiDexEnabled true "以及" android.enableAapt2=false" 但错误仍在继续...... 似乎有一些构建问题....我无法弄清楚它是什么

  

org.gradle.api.tasks.TaskExecutionException:任务':app:processDebugResources'执行失败。       at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)       在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)       在org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)       在org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)       在org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)       在org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)       在org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)       在org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)       在org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)       在org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)       在org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)       在org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)       在org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)       在org.gradle.execution.taskgraph.DefaultTaskGraphExecuter $ EventFiringTaskWorker $ 1.run(DefaultTaskGraphExecuter.java:248)       在org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)       在org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)       在org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)       在org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)       在org.gradle.execution.taskgraph.DefaultTaskGraphExecuter $ EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)       在org.gradle.execution.taskgraph.DefaultTaskGraphExecuter $ EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)       at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)       at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker.access $ 200(DefaultTaskPlanExecutor.java:79)       在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker $ 1.execute(DefaultTaskPlanExecutor.java:104)       在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker $ 1.execute(DefaultTaskPlanExecutor.java:98)       在org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:626)       at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581)       在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)       在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)       在java.lang.Thread.run(Thread.java:745)   引起:org.gradle.tooling.BuildException:无法执行aapt       在com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask.invokeAaptForSplit(LinkApplicationAndroidResourcesTask.java:513)       在com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask.doFullTask​​Action(LinkApplicationAndroidResourcesTask.java:248)       在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)       在org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)       在org.gradle.api.internal.project.taskfactory.IncrementalTask​​Action.doExecute(IncrementalTask​​Action.java:46)       在org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)       在org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)       在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter $ 1.run(ExecuteActionsTaskExecuter.java:121)       在org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)       在org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)       在org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)       在org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)       at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)       在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)       ......还有32个       抑制:java.lang.RuntimeException:某些文件处理失败,请参阅日志以获取详细信息           在com.android.builder.internal.aapt.QueuedResourceProcessor.waitForAll(QueuedResourceProcessor.java:121)           在com.android.builder.internal.aapt.QueuedResourceProcessor.end(QueuedResourceProcessor.java:141)           在com.android.builder.internal.aapt.v2.QueueableAapt2.close(QueueableAapt2.java:115)           在com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask.doFullTask​​Action(LinkApplicationAndroidResourcesTask.java:293)           ......还有48个   引起:com.android.ide.common.process.ProcessException:无法执行aapt       在com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:794)       在com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask.invokeAaptForSplit(LinkApplicationAndroidResourcesTask.java:491)       ......还有49个   引起:java.util.concurrent.ExecutionException:java.util.concurrent.ExecutionException:com.android.builder.internal.aapt.v2.Aapt2Exception:AAPT2错误:检查日志以获取详细信息       在com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:503)       在com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:482)       在com.google.common.util.concurrent.AbstractFuture $ TrustedFuture.get(AbstractFuture.java:79)       在com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:792)       ......还有50个   引起:java.util.concurrent.ExecutionException:com.android.builder.internal.aapt.v2.Aapt2Exception:AAPT2错误:检查日志以获取详细信息       在com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:503)       在com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:462)       在com.google.common.util.concurrent.AbstractFuture $ TrustedFuture.get(AbstractFuture.java:79)       在com.android.builder.internal.aapt.v2.QueueableAapt2.lambda $ makeValidatedPackage $ 1(QueueableAapt2.java:177)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)       ......还有1个   引起:com.android.builder.internal.aapt.v2.Aapt2Exception:AAPT2错误:检查日志以获取详细信息       在com.android.builder.png.AaptProcess $ NotifierProcessOutput.handleOutput(AaptProcess.java:463)       在com.android.builder.png.AaptProcess $ NotifierProcessOutput.err(AaptProcess.java:415)       在com.android.builder.png.AaptProcess $ ProcessOutputFacade.err(AaptProcess.java:332)       在com.android.utils.GrabProcessOutput $ 1.run(GrabProcessOutput.java:104)

5 个答案:

答案 0 :(得分:4)

尝试执行:

./gradlew clean
./gradlew assemble

如果不起作用,请尝试w CleanRebuild项目。最后,转到

  

档案>无效缓存

答案 1 :(得分:4)

问题在于PNG文件可能已损坏。有时,图像被列为PNG,但不是真正的PNG。

您可以通过在android终端中键入以下代码来获取此类图像的列表

find . -type f -name "*.png" | xargs -L 1 -I{} file  -I {} | grep -v 'image/png; charset=binary$' 

之后,您可以将其转换为PNG,然后重试。

请勿添加此android.enableAapt2=false,因为它已被弃用并且不受支持。

答案 2 :(得分:3)

尝试将compileSdkVersion更改为:compileSdkVersion 28targetSdkVersion 26 这对我有用。

答案 3 :(得分:1)

我在尝试使用数据绑定和声明布局标记时遇到了这个问题。经过这么多次尝试后我为解决这个问题所做的是当你不使用数据绑定时根据你的根布局说例如这个

  <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">     </android.support.constraint.ConstraintLayout>

删除

xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"

并将其放在您的布局标记上(即使您使用数据绑定

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

</layout>

希望它能奏效。 android.enableAapt2=false对我不起作用所以我必须删除所有内容并尝试弄清楚当我放置布局标记并使用数据绑定时我得到错误的原因因此我提出了解决方案。希望它有所帮助

答案 4 :(得分:0)

当我将Android Studio更新到3.4.0时,这发生了。 我确实更改了项目级别的 build.gradle 文件...

dependencies {
        //classpath 'com.android.tools.build:gradle:3.4.0'    //Previus default set up

       classpath 'com.android.tools.build:gradle:3.3.1' // Now working fine

    }