欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android Studio编译失败问题(aapt2)

程序员文章站 2024-01-16 22:42:40
android studio 3.1编译时出错: org.gradle.api.tasks.taskexecutionexception: execution failed for task &...

android studio 3.1编译时出错:

org.gradle.api.tasks.taskexecutionexception: execution failed for task ':app:mergedebugresources'.
    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)
caused by: error: java.util.concurrent.executionexception: com.android.builder.internal.aapt.v2.aapt2exception: aapt2 error: check logs for details
    at com.android.ide.common.res2.mergedresourcewriter.end(mergedresourcewriter.java:332)
    at com.android.ide.common.res2.datamerger.mergedata(datamerger.java:301)
    at com.android.ide.common.res2.resourcemerger.mergedata(resourcemerger.java:412)

根据网上说的添加了android.enableaapt2=false,一开始都ok后来创建新项目又出了问题:

org.gradle.api.tasks.taskexecutionexception: execution failed for task ':app:transformdexwithinstantrundependenciesapkfordebug'.
    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)

根据查找说是修改一个android studiio 一个配置就可以,取消选中enable instant run :
Android Studio编译失败问题(aapt2)
修改之后真的可以运行了,但取消这个选中之后编写代码会非常麻烦,资源文件的引用非常麻烦,需要手写,还需要重新编译才能看出是否正确。

java.lang.runtimeexception: com.android.build.api.transform.transformexception: com.android.ide.common.process.processexception: failed to execute aapt
    at com.android.builder.profile.recorder$block.handleexception(recorder.java:55)
    at com.android.builder.profile.threadrecorder.record(threadrecorder.java:104)

最后查看log感觉还是aapt的问题,果然把android.enableaapt2=false 改为true就可以了。
Android Studio编译失败问题(aapt2)

附:一个提示编译时错误的方法 gradlew compiledebugjavawithjavac
Android Studio编译失败问题(aapt2)