填坑app:compileDebugJavaWithJavac

·  阅读 17028

Android Error:Execution failed for task':app:compileDebugJavaWithJavac'和':app:transformJackWithJackForDebug'.


之前在mac上开发的一个项目,如今想换到pc上

安装jdk->配置环境变量->安装Android Studio 3.1.2, ok,一切都顺利进行,导入项目,修改了一些版本更新后的操作,ok,也没有问题,运行项目,好吧,出问题了,

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

第一反应就是去clean一下,然后rebuild,再次运行,还是不行。

接下来老规矩,问google,发现关于这个问题的博客还真不少,解决方案如下:

  1. 关闭增量编译,在bulide.gradle文件中android{ ... } 下compileOptions{}中加一行incremental = false;
  2. 将项目中用到java8的方法还原到java7;
  3. Check build.gradle(Module: Android) fixed problem 升级build.gradle中的buildToolsVersion到最新的版本;
  4. 升级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
    }
    

一个一个来,全都试完了,还是不能解决这个问题,脑袋大了

有问题总得结局,硬着头皮在google上搜了两天,终于功夫不负有心人,找到了答案:

造成 app:compileDebugJavaWithJavac的原因是jdk8 编译的方式和之前版本的编译方式变了,所以代码里面有语法错误或者类路径错误会导致编译不能通过而报出这个异常,这里简单讲下新版和旧版的jdk的编译方式的区别。

旧版 javac 工具链:
javac (.java –> .class) –> dx (.class –> .dex)新版 Jack 工具链:
Jack (.java –> .jack –> .dex)

(假装很懂的样子...)

知道问题原因了,就来解决问题

在Teriminal中输入命令:

gradlew compileDebugSources --stacktrace -info

回车

All input files are considered out-of-date for incremental task ':app:compileDebugJavaWithJavac'.
Compiling with source level 1.8 and target level 1.8.
file or directory 'E:\android-studio\AndroidStudioProjects\Ailianmeng\app\src\debug\java', not found
Compiling with JDK Java compiler API.
E:\android-studio\AndroidStudioProjects\Ailianmeng\app\src\main\java\com\aili\ailianmeng\application\AlmApplication.java:18: 错误: 程序包com.hyphenate.chat不存在
import com.hyphenate.chat.EMClient;
                         ^
E:\android-studio\AndroidStudioProjects\Ailianmeng\app\src\main\java\com\aili\ailianmeng\application\AlmApplication.java:19: 错误: 程序包com.hyphenate.chat不存在
import com.hyphenate.chat.EMOptions;
                         ^
E:\android-studio\AndroidStudioProjects\Ailianmeng\app\src\main\java\com\aili\ailianmeng\moudle\easeui\EaseuiHelper.java:32: 错误: 找不到符号
import com.hyphenate.EMConnectionListener;
                    ^
  符号:   类 EMConnectionListener
  位置: 程序包 com.hyphenate
E:\android-studio\AndroidStudioProjects\Ailianmeng\app\src\main\java\com\aili\ailianmeng\moudle\easeui\EaseuiHelper.java:33: 错误: 找不到符号
import com.hyphenate.EMError;
                    ^
  符号:   类 EMError
  位置: 程序包 com.hyphenate
E:\android-studio\AndroidStudioProjects\Ailianmeng\app\src\main\java\com\aili\ailianmeng\moudle\easeui\EaseuiHelper.java:34: 错误: 找不到符号
import com.hyphenate.EMMessageListener;
                    ^
  符号:   类 EMMessageListener
  位置: 程序包 com.hyphenate
E:\android-studio\AndroidStudioProjects\Ailianmeng\app\src\main\java\com\aili\ailianmeng\moudle\easeui\EaseuiHelper.java:35: 错误: 程序包com.hyphenate.chat不存在
import com.hyphenate.chat.EMClient;

环信的问题,找到问题所在位置,挨个儿解决吧


收藏成功!
已添加到「」, 点击更改