Error:执行“:app:transformClassesWithInstantRunSlicerForDebug”任务失败。>java.io.IOException:

44
无论何时我尝试运行我的应用程序,都出现以下错误:
错误:执行任务失败
 :app:transformClassesWithInstantRunSlicerForDebug'.
 java.io.IOException: Failed to delete 

 C:\Users\ashis\AndroidStudioProjects\FirstApp\app\build\intermediates\instant-run-support\debug\restart-changes.txt**

这是输出结果:

信息:Gradle任务

[: app:assembleDebug] :app:preBuild已更新 :app:preDebugBuild已更新 :app:checkDebugManifest :app:preReleaseBuild已更新 :app:prepareComAndroidSupportAnimatedVectorDrawable2340Library已更新 :app:prepareComAndroidSupportAppcompatV72340Library已更新 :app:prepareComAndroidSupportSupportV42340Library已更新 :app:prepareComAndroidSupportSupportVectorDrawable2340Library已更新 :app:prepareDebugDependencies :app:compileDebugAidl已更新 :app:compileDebugRenderscript已更新 :app:generateDebugBuildConfig已更新 :app:mergeDebugShaders已更新 :app:compileDebugShaders已更新 :app:generateDebugAssets已更新 :app:mergeDebugAssets UP-TO-DATE :app:generateDebugResValues已更新 :app:generateDebugResources已更新 :app:mergeDebugResources UP-TO-DATE :app:processDebugManifest已更新 :app:processDebugResources已更新 :app:generateDebugSources已更新 :app:incrementalDebugJavaCompilationSafeguard已更新 :app:compileDebugJavaWithJavac已更新 :app:compileDebugNdk已更新 :app:compileDebugSources已更新 :app:buildInfoDebugLoader :app:transformClassesWithExtractJarsForDebug已更新 :app:transformClassesWithInstantRunVerifierForDebug已更新 :app:transformClassesWithJavaResourcesVerifierForDebug已更新 :app:mergeDebugJniLibFolders UP-TO-DATE :app:transformNative_libsWithMergeJniLibsForDebug已更新 :app:processDebugJavaRes已更新 :app:transformResourcesWithMergeJavaResForDebug已更新 :app:transformResourcesAndNative_libsWithJavaResourcesVerifierForDebug已更新 :app:transformClassesWithInstantRunForDebug已更新 :app:transformClasses_enhancedWithInstant+ reloadDexForDebug已更新 :app:incrementalDebugTasks :app:prePackageMarkerForDebug :app:fastDeployDebugExtractor已更新 :app:generateDebugInstantRunAppInfo已更新 :app:coldswapKickerDebug :app:transformClassesWithInstantRunSlicerForDebug失败 错误:任务“:app:transformClassesWithInstantRunSlicerForDebug”的执行失败。 java.io.IOException:无法删除C:\ Users \ ashis \ AndroidStudioProjects \ FirstApp \ app \ build \ intermediates \ instant-run-support \ debug \ restart-changes.txt 信息:构建失败 信息:总时间:1分06.761秒 信息:1个错误 信息:0个警告 信息:请参阅控制台中的完整输出

7个回答

77

:app:transformClassesWithInstantRunSlicerForDebug'. java.io.IOException: 删除失败

-- 尝试清理项目并重新构建项目。

来自@Kael:可以通过 Build -> Clean Project 或 Build -> Rebuild Project 进行清理操作。


5
(对于那些想知道的人,这是“构建菜单>清理项目”和“构建菜单>重建项目”) - kael
4
无法正常运行,当我点击“清理项目”时,它显示相同的错误:“Error:Execution failed for task ':app:mergeDebugResources'。
java.io.IOException: Could not delete path 'xxxxxxxxxx\app\build\intermediates\res\merged\debug\drawable-hdpi-v4'."
- Prasad
@Prasad:我也是。 - Veverke
我知道这不是适当的地方...但非常感谢。 - Mehdi Raash
4
这种情况发生得太频繁了。还有其他方法可以防止它发生吗? - appbootup
重建还会清理项目。 - Deividas Strioga

32

请按照以下步骤操作:

前往

1>File
2>Settings
3>Build,Execution,Deployment 
4>Instant Run
5>Uncheck (Enable Instant Run to hot swap code)

所以这对我有帮助。


8

在我的情况下,Build菜单 > 清除项目和Build菜单 > 重建都没有起作用。相反,我不得不手动从文件系统中删除build文件夹(在OSX上使用Finder,在Win上使用Explorer)。


1

我遇到了同样的问题...我通过删除项目根目录下的.gradle文件并重新构建项目来解决了我的问题。


1

尝试从Build菜单 > Clean Project和Build菜单 > Rebuild清理项目并重新构建项目 尝试重新启动Android Studio或在不同的用户上使用Android Studio


1
我遇到了“:app:generateDebugBuildConfig”编译任务失败的错误,清理和重建项目并未起作用。
以下是解决方法:
  1. C:\Users\...\AppData\Local\Android\sdk\tools 添加到环境变量的 PATH 中。
  2. 关闭 Android Studio 和正在用于编辑项目文件的 vscode。(这非常重要)
  3. 运行项目,问题将得到解决。

0
将grable-wrapper.prperties中的https://services.gradle.org/distributions/gradle-4.4-all.zip更改为https://services.gradle.org/distributions/gradle-4.1-all.zip。然后重新导入属性并同步项目。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接