鏈接: https://blog.csdn.net/wjj1996825/article/details/79838430
關(guān)于TaskExecutionException:Execution failed for task
':app:compileDebugJavaWithJavac'和
':app:transformJackWithJackForDebug'.
通過親身受害跪呈,爬坑實(shí)踐證明非常權(quán)威有效的解決方案
項(xiàng)目運(yùn)行本身都是好好的,但就是那么突然,項(xiàng)目需要改一個(gè)地方,在發(fā)布的頁面要修改之前的ui和功能侨核,由之前只能打開相冊(cè)選擇一張照片變?yōu)橛镁艑m格選擇器形式選擇多張圖片并在頁面中以九宮格形式顯示出來圖片并且每個(gè)圖片右上角要帶有刪除的圖標(biāo)笔宿,可以進(jìn)行刪除操作,我第一反應(yīng)是不難振峻,因?yàn)橹白鲞^一個(gè)類似的功能在自己的demo里面公般,可以直接導(dǎo)入作為一個(gè)mudule使用万搔,于是點(diǎn)擊AS的file-->new-->import mudule 選中依賴庫導(dǎo)進(jìn)來了項(xiàng)目中,本以為一切都非常順利俐载,結(jié)果問題出現(xiàn)了蟹略,編譯之后報(bào)錯(cuò)了登失,紅紅的一大片遏佣,哈哈,由于太刺眼揽浙,下面就不貼成紅色了状婶,讓程序員的大腦神經(jīng)放松下吧,哈哈
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDebugJavaWithJavac'. 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.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63) at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54) at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58) at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88) 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:197) at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107) 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:124) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99) at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625) at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99) 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.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details. at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:51) at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:36) at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:99) at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:52) at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:37) at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:35) at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25) at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:198) at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:183) at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:120) at com.android.build.gradle.tasks.factory.AndroidJavaCompile.compile(AndroidJavaCompile.java:49) 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.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:173) at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134) at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122) 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:197) at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92) ... 30 more
問題出現(xiàn)了馅巷,以前沒有見過,二話不說膛虫,google搜索解決方案,有很多這樣的博客钓猬,主要的解決方案有以下幾種:
1.關(guān)閉增量編譯稍刀,在bulide.gradle文件中android{ ... } 下compileOptions{}
中加一行incremental = false
2.把項(xiàng)目中用到j(luò)ava8的方法等用java7的替換,還是回歸java7敞曹;
3.Check build.gradle(Module: Android) fixed problem 升級(jí)build.gradle中的buildToolsVersion到最新的版本账月;
4.升級(jí)Android Studio的版本(Help->Check for Updates...) 以及 配置JAVA_HOME的路徑;
5.移除jackOptions { enabled true }
和compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
incremental false
}
但是我挨個(gè)兒嘗試后都不見效澳迫,依然無法解決局齿,最后實(shí)在解決不了,只好回退老版本橄登,重新來過抓歼,但依然卡在這個(gè)地方讥此,頭痛的要命,死命google谣妻,百度萄喳,死磕兩天終于找到了解決方案,幸福來的就是這么突然拌禾,哈哈 原來 app:compileDebugJavaWithJavac 造成的原因是java jdk 8 編譯的方式和之前版本的編譯方式變了取胎,所以代碼里面有語法錯(cuò)誤或者類路徑錯(cuò)誤會(huì)導(dǎo)致編譯不能通過而報(bào)出這個(gè)異常,這里簡(jiǎn)單講下新版和舊版的jdk的編譯方式的區(qū)別湃窍。
- 舊版 javac 工具鏈:
javac (.java –> .class) –> dx (.class –> .dex) - 新版 Jack 工具鏈:
Jack (.java –> .jack –> .dex)
回到正題上闻蛀,真正的解決方案在這里,非常神奇:
在命令行中進(jìn)入項(xiàng)目的根目錄您市,或者可以在Android studio的Terminal中直接操作也可以觉痛,然后敲入一個(gè)命令:
gradlew compileDebug --stacktrace -info
或者:
gradlew compileDebug --stacktrace -debug
我直接用了這個(gè)命令,這個(gè)顯示的錯(cuò)誤信息最詳細(xì)茵休,建議你直接用這個(gè)薪棒,
gradlew compileDebugSources --stacktrace -info
-debug的命令我也試了,顯示的非常多榕莺,但不像-info一樣顯示錯(cuò)誤提示的信息非常詳細(xì)俐芯,你可以兩個(gè)都嘗試一下。
最后在出現(xiàn)的信息中找到了這個(gè)提示