Android Studio 3.1 "Run" not compiling code
Asked Answered
D

6

89

When I try to install an app, there are two possibilities:

  1. Install existing APK from build folder when I run the app
  2. Install APK after performing clean build

For existing APK in the build folder, the app just works fine. But when I clean the project using Build -> Clean Project, and then try to run the app (i.e. install the app to my emulator or physical device), it shows me error:

The APK file /Users/MyApplicationName/app/build/outputs/apk/app-debug.apk does not exist on disk.

NOTE: This behaviour happens only when I clean the project and not when I have already have a pre-built app APK in my build folder

I've referred to: The APK file does not exist on disk but my point is, when we usually run the app after cleaning the project, we never need to make a build of it, if the APK is not existing in the build folder, it automatically generates and installs the latest one.

Things I've tried:

  1. Running the app when APK file exists in the build folder (works perfectly fine)
  2. Running the Clean Project -> Running the app (expected is the project would be built and the app would get installed but it shows the above mentioned error!)
  3. Same process of cleaning and running the app after doing Invalidate Caches/Restart
Demirep answered 27/3, 2018 at 6:39 Comment(3)
Build -> Clean Project->Rebuild ProjectChaise
@IntelliJAmiya exactly as you said, but the point here is, when I rebuild the project, it surely works, but shouldn't it generate the APK & work the same way if I run the app?Demirep
Check this link for answer: https://mcmap.net/q/103850/-android-studio-3-1-run-command-does-not-rebuild-the-apk-duplicateFreed
U
161

I have solution for your issue.

Also confirmed by Android Studio on Twitter : https://twitter.com/androidstudio/status/981914632892960768

  1. Edit your app configuration as below.

enter image description here

  1. Here you can see your app configuration as below.

enter image description here

  1. Here is missing Gradle-aware make attribute in before launch configuration. You can see here.

enter image description here

  1. Please add this Gradle-aware Make attribute through this way. Click on + icon and select Gradle-aware Make as seen in this screen.

enter image description here

  1. You can add this without writing any task just press OK button and task will be added and now it should look like this. Now apply changes and run your application.

enter image description here

It will solve this old apk installing issue on clean build in new Android Studio 3.1 issue.

Note : This issue is resolved in new Android Studio 3.1.1 Stable release.

Ungracious answered 27/3, 2018 at 6:49 Comment(7)
It seems that if you change your code and run the app, it's not building the app just running the old code. This solution worked for me.Drusi
NOT WORKING: Shutdown finished in 0ms Error while generating dependencies split APK com.android.ide.common.process.ProcessException: Failed to execute aapt at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:809) at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:797) at com.android.build.gradle.internal.transforms.InstantRunSplitApkBuilder.generateSplitApkResourcesAp(InstantRunSplitApkBuilder.java:373)Christi
@Christi It's working for me. Can you please check your project's other gradle's configuration. I think that would be issue.Ungracious
@Christi Yes, Exactly. Currently in my configuration instant run is turned off. So this solution works for me.Ungracious
Running Android Studio 3.4 (built April 9, 2019), it was not generating instant_run_split_apk_resources files, and therefore not running. Only breaking for one of my Build Variants. The fix for me was to REMOVE Gradle-aware Make from the configuration's "Before launch" list. Now my "Before launch" list is empty, and it still works fine.Mendiola
I had this issue in latest AS 4.2 Canary build for long time. This fixed that issue, thanks.Bubal
Good! My AS4.1.2 new project still have this issue. Really weird.Auramine
C
6

The APK file /Users/MyApplicationName/app/build/outputs/apk/app-debug.apk does not exist on disk.

May be bug. You should change Settings.

You should open the Run/Debug Configurations dialog & select Run > Edit Configurations

Make sure, Gradle-aware Make is Added in TaskList or not. If not then click + & select from the options.

enter image description here

Note

If you receive

Shutdown finished in 0ms Error while generating dependencies split APK com.android.ide.common.process.ProcessException: Failed to execute aapt at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:809) at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:797) at com.android.build.gradle.internal.transforms.InstantRunSplitApkBuilder.generateSplitApkResourcesAp(InstantRunSplitApkBuilder.java:373)

You should Un-Check INSTANT RUN.

File-- Settings-- Build, Execution, Deployment -- Instant Run and uncheck Enable Instant Run.

Chaise answered 27/3, 2018 at 6:49 Comment(10)
Yes, It will work in rebuild because configuration is already setup with instant run so. But will not work on clean build and run project combination.Ungracious
@SaguKacha Indeed.Chaise
NOT WORKING: Shutdown finished in 0ms Error while generating dependencies split APK com.android.ide.common.process.ProcessException: Failed to execute aapt at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:809) at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:797) at com.android.build.gradle.internal.transforms.InstantRunSplitApkBuilder.generateSplitApkResourcesAp(InstantRunSplitApkBuilder.java:373)Christi
@Christi Whats your buildToolsVersion ??Chaise
@IntelliJAmiya 26.0.2Christi
@Christi compileSdkVersion 27 buildToolsVersion "27.0.3" then Clean-Rebuild and runChaise
@IntelliJAmiya same result with compileSdkVersion 27 buildToolsVersion "27.0.3"Christi
@Christi Gradle version 3.0.1 ?Chaise
@Christi Disable Instant run ??Chaise
@IntelliJAmiya this is the problem: I NEED instant run :(( "run" works with instant run disabledChristi
S
2

clean your project and run again

If it's not work then

  • Step 1 Close your project.
  • Step 2 Go to your project folder and delete all build folder.
  • Step 3 run your project.
Strader answered 27/3, 2018 at 6:42 Comment(5)
Also tried closing project, closing Android Studio & performing invalidate caches/restart but no luck, after cleaning the app, it always shows the error, and strangely, if the project is built, it always runs the same APK which is in build folder without updating with any changes.Demirep
did you try step 2? go to your project folder and delete all build folder with module build folder.Strader
Yes I did delete the build folder as well, nothing works!Demirep
desable instan run and do all agiain.Strader
did you get solution?Strader
E
1

I encountered the same issue with Iguana | 2023.2.1 beta 02. While I was able to build my project without any warnings or clear errors, my app would not run. I could create a bundle or APK in the APK folder, but I couldn't run my project on an emulator or a device that didn't already have an installed APK of the same project. I attempted all the suggested solutions, but none of them worked for me. In the end, I decided to downgrade Android Studio to the earliest stable version available, which is Hedgehog | 2023.1.1. This resolved my problem.

Eton answered 8/2 at 14:38 Comment(0)
F
0

This issue has been fixed with Android studio 3.1.1 (April 2018) release. Update your android studio to 3.1.1.

Here is there explanation regrading the issue details, cause and solution:

In some cases, when a project created in Android Studio 3.0 was opened for the first time in Android Studio 3.1, the Gradle-aware Make task was removed from the Before launch area in Run/Debug Configurations. The result was that projects did not build when the Run or Debug button was clicked, which in turn caused failures such as deployment of incorrect APKs and crashes when using Instant Run.

To solve this problem, Android Studio 3.1.1 adds the Gradle-aware Make task to the run configuration for projects that are missing this entry. This modification occurs after the first Gradle sync when the project is loaded.

Official release notes: https://developer.android.com/studio/releases/index.html#3-1-0

Freed answered 10/4, 2018 at 5:58 Comment(0)
D
0

For all people seing this and having the issue on Android Studio +4.0.0:

Run -> Edit configurations... -> disable check box (Allow parallel run)

It may slow your build a little but it better than running the app more than one time.

Dimarco answered 14/1, 2021 at 16:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.