Android Studio错误 - 错误:java.util.concurrent.ExecutionException:com.android.tools.aapt2.Aapt2Exception:AAPT错误

时间:2017-11-22 09:11:20

标签: java android gradle

enter image description here

这是我的build.gradle(Module:app)文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    aaptOptions.cruncherEnabled = false
    aaptOptions.useNewCruncher = false

    defaultConfig {
        applicationId "com.doctor.ciao"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support:design:26.1.0'
    compile 'com.felipecsl:gifimageview:2.1.0'
    compile 'com.github.devlight.pulseview:library:1.0.2'
    compile 'commons-io:commons-io:2.4'
    compile 'com.github.lguipeng:BubbleView:1.0.1'

}

我遇到两个错误:

  1. 错误:java.util.concurrent.ExecutionException:com.android.tools.aapt2.Aapt2Exception:AAPT错误

  2. 错误:任务':app:mergeDebugResources'的执行失败。

      

    错误:java.util.concurrent.ExecutionException:com.android.tools.aapt2.Aapt2Exception:AAPT错误

  3. 我已将"android.enableAapt2=false"添加到gradle.properties文件中,但错误仍然存​​在。请帮我解决这个问题。谢谢

3 个答案:

答案 0 :(得分:1)

我的问题是我有一个无效的png文件-我的一个.jpg文件被意外重命名为.png

要查找有问题的图像文件,请在我的应用目录中运行以下命令:

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

将图像文件重命名为.jpg扩展名解决了该问题,我可以再次构建。

答案 1 :(得分:0)

非常感谢。我正在关注@Anubhav Sarangi的评论:

  

我的drawable文件夹中的一些图像被自动重命名为   " imagename.9.png&#34 ;.所以它显示错误为 - 9补丁图像   错误。通过将图像重命名为" imagename.png",问题是   解决。

我检查了我的drawable文件夹中的图像,我发现有一个图像不是9-patch图像但名为imagename.9.png,我将其重命名为imagename.png,问题解决了。

有一个前提,需要添加" android.enableAapt2 = false" to gradle.properties

再次感谢@Anubhav Sarangi和@Eugen Pechanec

this is my error tips in this image, the title_bar.9.png is not 9-patch image, so i rename it to title_bar.png, and add android.enableAapt2=false to gradle.properties and click "Sync Now" and the problem solved

答案 2 :(得分:0)

使用Android 3和SDK 25后,我遇到了同样的错误。

将SDK版本从25更改为27有助于。

以下是我的build.gradle。我可以通过将SDK版本从27更改为25来重新创建它。

希望这有帮助。

compileSdkVersion 27

targetSdkVersion 27

STACK TRACE

 org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:processDebugResources'.   at
 org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
    at
 org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
    at
 org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
    at
 org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
    at
 org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at
 org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)
    at
 org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
    at
 org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)
    at
 org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
    at
 org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    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:248)
    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:241)
    at
 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)
    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:626)
    at
 org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581)
    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:
 org.gradle.tooling.BuildException: Failed to execute aapt  at
 com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask.invokeAaptForSplit(LinkApplicationAndroidResourcesTask.java:513)
    at
 com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask.doFullTaskAction(LinkApplicationAndroidResourcesTask.java:248)
    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)  at
 org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:46)
    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:121)
    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:110)
    at
 org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
    ... 32 more     Suppressed: java.lang.RuntimeException: Some file
 processing failed, see logs for details        at
 com.android.builder.internal.aapt.QueuedResourceProcessor.waitForAll(QueuedResourceProcessor.java:121)
        at
 com.android.builder.internal.aapt.QueuedResourceProcessor.end(QueuedResourceProcessor.java:141)
        at
 com.android.builder.internal.aapt.v2.QueueableAapt2.close(QueueableAapt2.java:115)
        at
 com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask.doFullTaskAction(LinkApplicationAndroidResourcesTask.java:293)
        ... 48 more Caused by:
 com.android.ide.common.process.ProcessException: Failed to execute
 aapt   at
 com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:794)
    at
 com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask.invokeAaptForSplit(LinkApplicationAndroidResourcesTask.java:491)
    ... 49 more Caused by: java.util.concurrent.ExecutionException:
 java.util.concurrent.ExecutionException:
 com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error:
 check logs for details     at
 com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:503)
    at
 com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:482)
    at
 com.google.common.util.concurrent.AbstractFuture$TrustedFuture.get(AbstractFuture.java:79)
    at
 com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:792)
    ... 50 more Caused by: java.util.concurrent.ExecutionException:
 com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error:
 check logs for details     at
 com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:503)
    at
 com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:462)
    at
 com.google.common.util.concurrent.AbstractFuture$TrustedFuture.get(AbstractFuture.java:79)
    at
 com.android.builder.internal.aapt.v2.QueueableAapt2.lambda$makeValidatedPackage$1(QueueableAapt2.java:177)
    at
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    ... 1 more Caused by:
 com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error:
 check logs for details     at
 com.android.builder.png.AaptProcess$NotifierProcessOutput.handleOutput(AaptProcess.java:463)
    at
 com.android.builder.png.AaptProcess$NotifierProcessOutput.err(AaptProcess.java:415)
    at
 com.android.builder.png.AaptProcess$ProcessOutputFacade.err(AaptProcess.java:332)
    at
 com.android.utils.GrabProcessOutput$1.run(GrabProcessOutput.java:104)