Android Studio中的任务:app:compileDebugJavaWithJavac执行失败


71

我正在Android Studio中开发一个Android应用程序。不太确定出了什么问题。我几天前已经成功建立了。任何帮助都会很棒。

这是错误:

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

这是我的build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "21.1.2"

defaultConfig {
    multiDexEnabled true
    applicationId "com.tubbs.citychurchob"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'),        'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.parse.bolts:bolts-android:1+'
compile 'com.android.support:recyclerview-v7:23.1.0'
}

1
转到运行->编辑配置-> Gradle-> + Gradle-> Tasks:build,脚本参数:--info --debug-> Apply->使用新配置运行->现在您将能够看到详细信息。粘贴在这里登录。
米兰

这是默认设置吗?
MrTimotheos

转到文件>项目结构。从无法识别的值中选择构建工具版本。
莱斯利

由于项目中的导入错误,我解决了此错误...在终端类型/ gradlew assemble {Your Buile Type} --scan ...中,它将在控制台中输出错误。
issamux

我不小心«在代码库中的某个地方键入了代码,这导致了此问题。
bharv14 '18

Answers:


66

尝试将您的升级buildToolsVersion到“ 23.0.1”,如下所示:

compileSdkVersion 23
buildToolsVersion "23.0.1"

如果您没有安装该版本的buildTools,请使用SDKManager作为提示进行下载。


49
刚刚尝试过,但没有成功,我的意思是构建仍然失败了。
MrTimotheos

1
是的 这可能与我的Java有关吗?
MrTimotheos

2
请尝试清理和重建,我认为某些依赖项jar已过时。
starkshang,2015年

3
我尝试了23.0.1、23.0.2,项目结构(intellij)中的所有内容都指向1.7,。/ gradlew --version和javac都指向1.7,JAVA_HOME设置为指向1.7,但仍然没有运气-我总是设法使它工作,但我总是忘记如何做。这是魔术:(
Srneczek

2
我应该在哪里进行这些更改?我拉了一个React Native应用并在构建时遇到了这个错误。
DragonKnight

128

在Android Studio 3.1中,您可以在Build窗口中查看错误的详细信息。

打开构建选项卡。它们有些隐藏,您必须扩展Java编译器节点。您将在此处看到错误。

在此处输入图片说明

但是有一种更好的方法来查看错误。您可以单击“切换视图”按钮以更好地查看错误。这样,您不必扩展每个节点。

在此处输入图片说明


我遇到了与Java 8不兼容的Google Paging库的问题,我不得不更新我的所有依赖关系,并且错误消失了。
Hitesh Sahu

3
单击上面建议的切换视图按钮,可以帮助我跟踪确切的错误并进行修复。谢谢!真是头疼得厉害.....
Gautam Mandsorwale '18 -10-11

1
我正在使用Android Studio 3.3.1,我会说这不一定能回答问题,但对于调试它非常有用。谢谢,这个解决方案节省了我寻找错误的时间。
Abel Callejo

2
哇,我节省了很多时间
dadan

2
你救了我的命,当我用房间的框架,我的数据库键的所有错误都隐藏在Java编译器,但都显示在视图的toogle
Xiidref

39

这种问题的确使我们感到焦虑,因为将不再提供更多有用的信息。

我不知道我们真的是同一个人,但是我可以提供两种方法来帮助我们尝试解决问题。

1.首先,您可以尝试清理或重新启动Android Studio和计算机。在中国,开发人员之间有一种说法。

小问题,只需重新启动。大问题,应重新安装。

上面的谚语将帮助您多次解决此类问题。

2.其次,我们需要使用一些gradle命令来帮助您找到更多有用的细节。

我遇到了以下类似情况:

org.gradle.initialization.ReportedException: org.gradle.internal.exceptions.LocationAwareException: Execution failed for task ':app:compileDebugJavaWithJavac'.
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:139)
    at org.gradle.initialization.DefaultGradleLauncher.executeTasks(DefaultGradleLauncher.java:109)
    at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:78)
    at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:75)
    at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:152)
    at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:100)
    at org.gradle.internal.invocation.GradleBuildController.run(GradleBuildController.java:75)
    at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:53)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$1.run(RunAsBuildOperationBuildActionRunner.java:43)
    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.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:40)
    at org.gradle.tooling.internal.provider.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:51)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:47)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:30)
    at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:39)
    at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:25)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:80)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:53)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:57)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:32)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:36)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:25)
    at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:43)
    at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:29)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:69)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:30)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:59)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:44)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:45)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:30)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:62)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:82)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:295)
    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.internal.exceptions.LocationAwareException: Execution failed for task ':app:compileDebugJavaWithJavac'.
    at org.gradle.initialization.DefaultExceptionAnalyser.transform(DefaultExceptionAnalyser.java:74)
    at org.gradle.initialization.MultipleBuildFailuresExceptionAnalyser.transform(MultipleBuildFailuresExceptionAnalyser.java:47)
    at org.gradle.initialization.StackTraceSanitizingExceptionAnalyser.transform(StackTraceSanitizingExceptionAnalyser.java:30)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:137)
    at org.gradle.initialization.DefaultGradleLauncher.executeTasks(DefaultGradleLauncher.java:109)
    at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:78)
    at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:75)
    at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:152)
    at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:100)
    at org.gradle.internal.invocation.GradleBuildController.run(GradleBuildController.java:75)
    at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:53)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$1.run(RunAsBuildOperationBuildActionRunner.java:43)
    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.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:40)
    at org.gradle.tooling.internal.provider.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:51)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:47)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:30)
    at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:39)
    at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:25)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:80)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:53)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:57)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:32)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:36)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:25)
    at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:43)
    at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:29)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:69)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:30)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:59)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:44)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:45)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:30)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:62)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:82)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:295)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: 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.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)
    ... 3 more
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:50)
    at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:35)
    at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:98)
    at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:51)
    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.internal.tasks.compile.incremental.IncrementalCompilationFinalizer.execute(IncrementalCompilationFinalizer.java:39)
    at org.gradle.api.internal.tasks.compile.incremental.IncrementalCompilationFinalizer.execute(IncrementalCompilationFinalizer.java:24)
    at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:207)
    at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:133)
    at com.android.build.gradle.tasks.factory.AndroidJavaCompile.compile(AndroidJavaCompile.java:125)
    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)
    ... 29 more

您知道上面的日志对我们解决此类问题没有用,我们需要执行gradle命令以查找更多有用的信息。

注意:我使用macOS(10.13)和Android Studio(3.1)

转到您的Android项目目录以执行以下gradle命令:

./gradlew assembleDebug --info

注意:如果在执行上述命令时遇到权限问题,可以使用此命令来处理:

chmod +x gradlew

然后我得到了(省略了一些不重要的部分):

> Task :app:compileDebugJavaWithJavac FAILED
Putting task artifact state for task ':app:compileDebugJavaWithJavac' into context took 0.0 secs.
file or directory '/Users/ifeegoo/workspace/android/android-bluetooth-color-lamp-karma-lighting/app/src/debug/java', not found
Up-to-date check for task ':app:compileDebugJavaWithJavac' took 0.009 secs. It is not up-to-date because:
  Task has failed previously.
All input files are considered out-of-date for incremental task ':app:compileDebugJavaWithJavac'.
Compiling with source level 1.7 and target level 1.7.
Creating new cache for classAnalysis, path /Users/ifeegoo/workspace/android/android-bluetooth-color-lamp-karma-lighting/.gradle/4.4.1/javaCompile/classAnalysis.bin, access org.gradle.cache.internal.DefaultCacheAccess@156d7504
Creating new cache for jarAnalysis, path /Users/ifeegoo/workspace/android/android-bluetooth-color-lamp-karma-lighting/.gradle/4.4.1/javaCompile/jarAnalysis.bin, access org.gradle.cache.internal.DefaultCacheAccess@156d7504
Creating new cache for taskJars, path /Users/ifeegoo/workspace/android/android-bluetooth-color-lamp-karma-lighting/.gradle/4.4.1/javaCompile/taskJars.bin, access org.gradle.cache.internal.DefaultCacheAccess@156d7504
Creating new cache for taskHistory, path /Users/ifeegoo/workspace/android/android-bluetooth-color-lamp-karma-lighting/.gradle/4.4.1/javaCompile/taskHistory.bin, access org.gradle.cache.internal.DefaultCacheAccess@156d7504
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
file or directory '/Users/ifeegoo/workspace/android/android-bluetooth-color-lamp-karma-lighting/app/src/debug/java', not found
Compiling with JDK Java compiler API.
/Users/ifeegoo/workspace/android/android-bluetooth-color-lamp-karma-lighting/app/src/main/java/com/chipsguide/app/colorbluetoothlamp/v2/karmalighting/frags/banner/VideoActivity.java:10: error: package com.android.tedcoder.wkvideoplayer.model does not exist
import com.android.tedcoder.wkvideoplayer.model.Video;
                                               ^
/Users/ifeegoo/workspace/android/android-bluetooth-color-lamp-karma-lighting/app/src/main/java/com/chipsguide/app/colorbluetoothlamp/v2/karmalighting/frags/banner/VideoActivity.java:11: error: package com.android.tedcoder.wkvideoplayer.model does not exist
import com.android.tedcoder.wkvideoplayer.model.VideoUrl;
                                               ^
/Users/ifeegoo/workspace/android/android-bluetooth-color-lamp-karma-lighting/app/src/main/java/com/chipsguide/app/colorbluetoothlamp/v2/karmalighting/frags/banner/VideoActivity.java:12: error: package com.android.tedcoder.wkvideoplayer.view does not exist
import com.android.tedcoder.wkvideoplayer.view.MediaController;
                                              ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
35 errors

:app:compileDebugJavaWithJavac (Thread[Task worker for ':',5,main]) completed. Took 0.84 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
15 actionable tasks: 1 executed, 14 up-to-date 

我得到了最重要的详细信息,因为一个模块的导入不正确,导致找不到该类。因此,我得到了解决方案。

其他一些gradle命令:

*clean project
./gradlew clean  

*build project
./gradlew build

*build for debug package
./gradlew assembleDebug or ./gradlew aD

*build for release package
./gradlew assembleRelease or ./gradlew aR

*build for release package and install
./gradlew installRelease or ./gradlew iR Release

*build for debug package and install
./gradlew installDebug or ./gradlew iD Debug

*uninstall release package
./gradlew uninstallRelease or ./gradlew uR

*uninstall debug package
./gradlew uninstallDebug or ./gradlew uD 

*all the above command + "--info" or "--debug" or "--scan" or "--stacktrace" can get more detail information.

如果--info无法获得足够的信息,请改用--debug /-scan /-stacktrace。

请记住,更多的细节将帮助您更多地解决问题。

注意:Gradle命令确实非常强大,如果您想执行更复杂的操作,尤其是有关如何处理调试/发布或多通道或模块的信息,请转到Android Studio中检查Gradle窗口,然后您将知道该怎么做它!

在此处输入图片说明

在此处输入图片说明


1
谢谢,这使我对正在发生的事情有了更好的了解
Kuti Gbolahan

@KutiGbolahan这些gradle命令可帮助我们获取有关构建过程的更多详细信息。
ifeegoo

33

这是因为未设置$ JAVA_HOME。如果您使用的是Mac:

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home" 在.bash_profile中


2
这实际上就是解决方案。
Przemo

为我工作。将其设置为我的Jenkins设置配置。
Nicolas Lauquin '16

7
注意并为您的系统设置正确的jdk版本
Anton Derevyanko

1
它的明智答案是您的代码中可能存在Java或xml中的语法错误。修复他们的错误将消失。每次都为我工作100%
Sheharyar Ejaz '18

1
键入export JAVA_HOME =“ / Library / Java / JavaVirtualMachines / jdk-,然后单击选项卡以找到正确的版本,然后继续键入/ Contents / Home
serdarsenay


16

第一步:

第一

第二步:

第二步

我都尝试了,但是什么都没有用。我的事情是解决方案。

从您的项目中

转到Gradle脚本>> build.gradle(Module:app),然后删除以下代码(如果存在)

...................................................

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_6
}

...................................................

删除它,然后清理项目,然后运行。无需设置Java主目录,无需更改版本


解决方案:文件->用gradle同步项目。它为我工作。
siddhartha shankar '20

11

如果上述所有方法均无效,请尝试从.gradle全局文件夹中删除缓存

尝试以下

rm -rf ~/.gradle/caches

react-native run-android

如果没用,下面的内容对我来说很合适

rm -rf ~/.gradle

react-native run-android


但是此示例与react android有关
Omer

4
是的,问题也与反应本机android错误有关
Amr Labib

在我的情况下,删除整个.gradle文件夹是可行的。谢谢!
卡尔文

10

更新(06/05/2017)

我想将Realm用于Android,而这需要Retrolambda。问题是Retrolambda与Jack发生冲突。

所以我从下面的原始答案所示的gradle中删除了我的Jack选项配置,并进行了以下更改:

// ---------------------------------------------
// Project build.gradle file
// ---------------------------------------------
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.1'
        classpath 'me.tatarka:gradle-retrolambda:3.6.1'
        classpath "io.realm:realm-gradle-plugin:3.1.4"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

// ---------------------------------------------
// Module build.gradle file
// ---------------------------------------------
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'realm-android'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    ...

Tools.jar

如果您在上面进行了这些更改,但仍然出现以下错误:

Execution failed for task ':app:compileDebugJavaWithJavac'.
com.sun.tools.javac.util.Context.put(Ljava/lang/Class;Ljava/lang/Object;)V

尝试删除以下文件:

/Library/Java/Extensions/tools.jar 

然后:

  1. 退出模拟器
  2. 退出Android Studio
  3. 重新打开Android Studio
  4. 构建>清洁项目
  5. 再次运行/调试您的应用到您的设备/模拟器

所有的更改对我来说都是固定的。

注意:

我不确定tools.jar做什么或者它是否重要。像此Stackoverflow问题中的其他用法一样:

无法在OSX优胜美地上构建Java项目

不幸的是,我们不得不使用AUSKey(澳大利亚政府在登录澳大利亚商业门户网站之前使用的一些古老的恐龙Java认证密钥系统来认证我们的计算机)。

我猜测tools.jar可能是AUSKey提供的JAR文件。

如果您担心,可以删除整个文件的备份,而不是删除此文件,并将其保存在某个位置,以防万一您无法再次登录澳大利亚商业门户。

希望有帮助:D

原始答案

我今天(2016/06/27)遇到了这个问题。

我下载了Android Studio 2.2,并将JDK更新为1.8。

除了上述指向正确的JDK路径的答案外,我还必须在build.gradle(Module: app)文件中另外指定JDK版本:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

生成的文件如下所示:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"
    defaultConfig {
        applicationId "com.mycompany.appname"
        minSdkVersion 17
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        jackOptions {
            enabled true
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    testCompile 'junit:junit:4.12'
}

另请注意,如果遇到关于的错误Java 8 language features requires Jack enabled,则需要将以下内容添加到gradle文件中(如上所示):

jackOptions {
    enabled true
}

之后,我终于在手机上运行了新的项目应用程序。


8

在将Android Studio升级到2.2.2版本后,我遇到了这个问题,我按照建议使用嵌入式JDK解决了这个问题: 在此处输入图片说明


7

在Android Studio中打开: File > Project Structure并检查JDK位置是否指向您的JDK 1.8目录。

注意:您可以使用compileSdkVersion 24。它相信我。为此,请先从Oracle下载最新的JDK。


3

解决了这个问题。

我正在尝试编译“ Waveform Android”项目-https: //github.com/Semantive/waveform-android

并得到了我这个错误。

我在Ubuntu 14.04LTS上使用Android Studio。

我已经安装了JAVA 8。

在我的gradle构建脚本文件中,有一些语句如下。

retrolambda {
    jdk System.getenv("JAVA8_HOME")
    oldJdk System.getenv("JAVA7_HOME")
    javaVersion JavaVersion.VERSION_1_7
}

我将“ JAVA8_HOME”更改为“ JAVA_HOME”,因为在我的环境变量中,将Java主目录设置为JAVA_HOME而不是JAVA8_HOME,然后成功构建了它。

更改构建脚本后。

retrolambda {
    jdk System.getenv("JAVA_HOME")
    oldJdk System.getenv("JAVA7_HOME")
    javaVersion JavaVersion.VERSION_1_7
}

或以其他方式可以创建一个新的名为JAVA8_HOME的环境变量,该变量指向正确的JDK位置,但是我没有尝试过,因为我不希望每个JDK版本都使用环境变量。


Retrolambda是我的问题。我对旧的Java Home版本进行了硬编码,但随后又升级并忘了更新。切换到这种自动方式。谢谢!
superuserdo

2

请检查您应用的build.gradle。我遇到了同样的问题,最后我发现问题出在我的build.gradle文件依赖项{}中,它添加了额外的.jar文件,该文件在我的项目中实际上不存在为依赖项。所以我删除了这个依赖关系,问题就消失了。


这就是答案。我已替换了libs文件夹中的库。但是当我查看build.gradle文件时,旧库仍作为依赖项保留在那里。我必须手动从build.gradle中删除条目。
Krishnabhadra '16

2

问题仅在于命名文件夹,如果要保存项目的文件夹中包含特殊字符,则将其删除。如果错误仍然存​​在,请尝试保存没有空间的文件夹。


2

我遇到了同样的问题,已经尝试了所有解决方案,但无济于事。

原来,使用Java 9是问题所在。安装较低版本的Java(jdk 1.8.0_162)对我有用


1

我是在Mac OS Sierra上首次运行React Native Android App时遇到此问题的:

Execution failed for task ':app:compileDebugJavaWithJavac'.

> Could not find tools.jar

我从以下位置更改了Java开发工具包(JDK)的JAVA HOME环境变量:

export JAVA_HOME='/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home'

至 :

export JAVA_HOME='/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home'

在Android Studio中创建项目并在项目设置中查找JDK位置后,我找出了正确的版本。


1

只需补充上面的@yuchaozh答案即可帮助我解决问题。(我没有评论代表)

运行此命令以知道您拥有哪个Java版本

ls /Library/Java/JavaVirtualMachines/

您将得到类似以下的输出:

jdk1.8.0_111.jdk

替换为Java版本,然后运行此命令以导出正确的路径。

export JAVA_HOME="/Library/Java/JavaVirtualMachines/<YOUR_JAVA_VERSION>/Contents/Home"

1

您的gradle文件可能已损坏。尝试跑步

./gradlew --refresh-dependencies

在android studio内的终端中。


1

当我尝试在单元测试中使用Retrolambda时出现此错误。我没有找到如何使Retrolambda与单元测试一起使用的解决方案。因此,我在单元测试中使用老式的匿名类而不是lambda,它对我有用。


0

在构建文件中更改编译文件(“ AF-Android-SDK.jar”)编译文件(“ libs / AF-Android-SDK.jar”),它将起作用


0

我有同样的问题。我与一个使用Mac的开发人员团队一起工作,团队中的其他所有人都在运行Windows。但是,我们将Anroid Studio 2.2-beta与jdk 1.8一起使用。如果您使用的是Mac,遇到此问题,请按以下方法解决。不要使用Android Studio 2.2-beta。我花了几个小时尝试在2.2-beta中调试此错误。我通过简单地更改为Android Studio 2.1.3来解决了它。更改Android Studio版本后,我们的应用立即运行。同样在Android Studio网站上,您也可以在下载之前警告Mac用户有关在2.2 beta上运行jdk 1.8的信息。猜猜我应该读完精美的文字哈哈


0

我遇到了同样的错误。JAVA_HOME指向正确的JDK版本。所有支持库和构建工具已更新。仍然面临着同样的问题。

我在我的项目中使用Android批注。我添加了一个新的View ..,并且Java文件中已经存在一个具有相同名称的视图。当我运行该项目时,不是指示该视图已经存在,而是我收到了以上错误。

如果其他解决方案无效,请检查您的Java文件错误。


1
那么,这如何回答问题?请澄清您的解决方案。
gofr1

0

如果您使用的是Android + Lambdas,则可能会发生这种情况。有时我可以使用Lambda,而不会出现任何问题,但在其他情况下,该项目将无法编译并在编译器中给出异常(当我尝试将Lambda或方法引用传递给ScheduledExecutorService.scheduleAtFixedRate时)。

在此链接中有一个讨论(https://bugs.openjdk.java.net/browse/JDK-8169759),其中他们解释了为什么会发生这种情况。同时,当编译器允许我时,我只是在Android项目中使用lambda。


0

这对我有用

compileSdkVersion 25
buildToolsVersion '25.0.0'

请具体说明。我需要把这两行放在哪里。谢谢
Mustkeem K

0

我遇到了类似的问题,但是我必须手动在程序文件上设置jdk文件夹,因此我特别向所有人推荐那些要升级到Java 8的文件夹,以使用嵌入式工具直接指向android studio的项目设置选项或选择文件夹


0

更改build.gradle文件中的任何内容将再次重新同步所有内容,错误将消失。对我来说,我更改了minSdkVersion并成功了。如果系统崩溃或未正确关闭Android Studio,请不要担心。


0

使用这些设置,它将正常工作。

android {
     compileSdkVersion 26
     buildToolsVersion '26.0.2'

  defaultConfig {
    applicationId "com.pm.motivator"
    minSdkVersion 15
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
 }
}

-_-编译版本与构建版本不同是不好的习惯。
Md Imran Choudhury

0

就我而言,更新黄油刀无法解决问题

从:“ com.jakewharton:butterknife:8.4.0”到:“ com.jakewharton:butterknife:8.8.1”

我试图在Adapter类中使用@BindView,但没有成功。一旦使用.findViewById(R.id.message_time),编译就成功完成了。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.