79

I upgraded Android Studio 3.4 today. I am no longer able to run the the app. I have cleaned the project, restarted Android studio many times. I have also invalidated cache to no avail. I am getting the following error when installing the app:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexWithInstantRunSlicesApkForDebug'.
> java.lang.RuntimeException: java.io.FileNotFoundException: E:\...\app\build\intermediates\instant_run_split_apk_resources\debug\instantRunSplitApkResourcesDebug\out\slice_1\resources_ap

Could anyone offer a tip on how to remedy this?

Edit: I have two projects with different behaviors related to this issue:

  1. Project A initially had this issue. I disabled Instant Run per the answer, the problem was solved. I enabled Instant Run later, and Project A is still working fine.
  2. Project B also had this problem that has been remedied by turning of Instant Run. However, its problem will occur as soon as Instant Run is turned on. I do not what difference between these two projects results in this. One suspect is library C project. Library C is a part of Project A (i.e. its source code, resources are in Project A). However, Project B uses the aar of Library C as a module.
Hong
  • 17,643
  • 21
  • 81
  • 142
  • 6
    Switching off Instant Run in Settings elminated the problem for me (as described in the answer to [Error:Execution failed for task ':app:transformDexWithInstantRunSlicesApkForDebug'. Failed to read zip file](https://stackoverflow.com/questions/51783951/errorexecution-failed-for-task-apptransformdexwithinstantrunslicesapkfordebu) ) – Marco Borchert Apr 23 '19 at 11:04
  • @MarcoBorchert Thank you. It started working after I turned off Instant Run. I turned Instant Run back on later, and it is still working now. It seems that turning off Instant Run does not some cleaning work that cannot be done by other regular cleaning methods. Could you turn your comment to an answer so that I can accept it? – Hong Apr 23 '19 at 14:54
  • @MarcoBorchert For another project, I cannot turn Instant Run back on. I has to be off all the time. – Hong Apr 23 '19 at 15:17

10 Answers10

94

Issue should be fixed in Android Studio 3.4.2.


EDIT: Here is my old answer on how to fix it in Android Studio 3.4.0 and 3.4.1:

Using Gradle 5.4 instead of 5.1.1 helped me with this error.

Update gradle-wrapper.properties file with: distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-all.zip

Please note I haven't tested older Gradle versions, so it's possible even (for example) 5.2 version will work. You can see all Gradle releases here - https://gradle.org/releases/

Robyer
  • 4,632
  • 2
  • 23
  • 21
  • Thank you. I have just tried and confirmed this remedy works. Unfortunately, I can accept only one answer. I guess that Google will address this issue with an update one way or another. One way is forcing the update of Gradle. – Hong Apr 25 '19 at 12:18
  • 5
    @Hong You can _change_ the accepted answer though. This solution is clearly preferable and more helpful to other readers since it isn't merely a workaround. – Marco Borchert Apr 25 '19 at 12:59
  • Please forgive my being conservative on these things. I usually stay away from the latest versions unless they have been extensively tested. I assume each Android Studio update has been tested by a lot of kind beta testers before its release. – Hong Apr 25 '19 at 13:15
  • @Hong Well, I think we can trust the Gradle testing more (as that version was publicly released for some time already) than freshly released Android Studio with this obvious problem. Also I haven't tested other Gradle versions, but perhaps you can use older version than 5.4 if you wish not to use latest one (also note latest is now 5.4.1) - see https://gradle.org/releases/ I updated my answer with this info. – Robyer May 03 '19 at 06:20
  • First, I need to confess that I am no expert in either Android Studio or Gradle. I am just a user of Android Studio. Unless there is strong evidence showing Google does a poor job in choosing Gradle versions, I would stick with the version they choose for Android Studio and assume they have good reasons for doing so. As for the answer, the large number of up votes for this one including mine makes a sufficient point to visitors. – Hong May 06 '19 at 13:37
  • 1
    This seems to have worked on AndroidStudio 3.4 on a mac. Thanks @Robyer – Hugo May 30 '19 at 17:25
  • Thanks a lot! It has solved the issue and Instant run works again. – Jusid Jun 12 '19 at 15:28
  • It happened to me on Android Studio 5.4.2, using Gradle 5.1.1. Updating to Gradle 5.5.1 made it work. Thank you! – Hendy Irawan Jul 20 '19 at 09:21
67

Switching off Instant Run as a workaround (File/Settings/Instant Run) seems to eliminate the problem.

According to OP it is possible to turn Instant Run back on without the problem recurring for some projects.

Marco Borchert
  • 1,038
  • 1
  • 11
  • 17
39

There is no need to turn off Instant Run.
Just delete the '.gradle' directory in the project and build directory inside the 'app' module.
Perform Clean Project and Rebuild Project.
This will solve the issue.

Bibin Johny
  • 3,157
  • 1
  • 13
  • 16
6

This is caused by "instant run" feature in android studio 3.4 , you can disable it by:

Open the Settings or Preferences dialog. Navigate to Build, Execution, Deployment > Instant Run. Uncheck the box next to Enable Instant Run

Enjoy...!

Mahi Saini
  • 219
  • 2
  • 2
2

Go to your project folder and move everything from ...\app\build\ to some other folder outside project. (to clear build folder with back up) In my case clearing the build folder solved the probem, till then i was disableing the instant Run option for every new install.

Harsh
  • 363
  • 4
  • 14
  • 3
    In mi case it wasn't enough to move the `build` directory, I had to move `.gradle` as well and that fixed the problem. – carrizo Jul 20 '19 at 14:54
0

I tried both "Gradle 5.4" and "Switching off Instant Run" solutions but they didnt work until I turned on "Wait for Debugger" option until "Developer Options" in my phone (Huawei Mate 10). I have confirmed that this is only working with "Instant Run" off as well.

0

This problem happened to me on Windows. I solved it by disabling instant run. I also have the same Android Studio version on Linux and it works fine with instant run enabled.

0

This is fixed in 3.4.2. Just update to the latest version of Studio. https://androidstudio.googleblog.com/2019/07/android-studio-342-available.html

mystic cola
  • 1,465
  • 1
  • 21
  • 39
0

This same error happened when I updated to Android Studio 3.4.2, I updated the tools-build-gradle to 3.4.2 and the problem disappear.

snti
  • 131
  • 3
-1

Switching off Instant Run as a workaround (File/Settings/Instant Run) seems to eliminate the problem.