230

When I am trying debug application on Android Studio gives this log output :

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

I restarted Android Studio, but I can't solve this problem . How can I solve it ? Thank you

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
yusufonderd
  • 3,237
  • 4
  • 21
  • 34
  • 9
    *How can I solve it ?* compile an apk – Tim Dec 02 '15 at 10:03
  • 1
    @TimCastelijns I actually wonder if Android Studio is not intelligent enough to include the create debug apk task into the deb application task. Gradle should be made for this. – NoDataDumpNoContribution Dec 02 '15 at 10:23
  • 1
    @Trilarion By default AS executes gradle's assembleDebug task which compiles a debug apk. Something seems wrong here, which requires manual compilation – Tim Dec 02 '15 at 10:25
  • 3
    Adding Gradle Make-Aware fixed this issue for me. http://stackoverflow.com/a/25871525/1712417 – Iammesol Dec 10 '15 at 18:53
  • 2
    Try to add "Gradle Make-Aware" http://stackoverflow.com/questions/18256177/android-studio-local-path-doesnt-exist/25871525#25871525 – Andy Cheng Apr 28 '16 at 05:19
  • For me this was fixed by clearing android studio cache w/ rm -rfv ~/Library/Caches/AndroidStudio* Another workaround was renaming the apk to the apk that android studio was looking for.. but that's a temporary solution – The Tokenizer Jun 19 '17 at 03:45

41 Answers41

465

Click this option to solve the error:

Run: View > Tool Windows > Gradle > [project] > Tasks > build > build

Askr
  • 57
  • 7
指尖上的Android
  • 4,798
  • 2
  • 9
  • 2
  • 6
    Special characters in your project directory name will also throw this error. – N.P Oct 20 '16 at 06:25
  • 50
    This didn't work for me at all. I would advise answers that explain why they are supposed to work rather than just telling the reader what to do, so that they can understand / avoid / solve those errors later. – person27 Oct 27 '17 at 18:22
  • 3
    Would you explain what does this exactly do and why this problem happened? – Hamidreza Sahraei Nov 18 '17 at 10:30
  • btw "Special characters" also include numbers. It's ridiculous, wasted tons of time on this. *facepalm* :) – alexr101 Jul 06 '18 at 04:34
  • Funny, for me it did not work for some reason in Android Studio 3.1.4, at least not until I actually restarted the IDE. – tsaulic Aug 23 '18 at 00:43
  • 5
    That button doesn't exist on the latest version of Android Studio, but I believe it's the "Sync Project With Gradle Files" option, which did work for me. – nasch Feb 08 '19 at 02:48
  • I assume this is an old version, but clicking sync with gradle didn't work for me. Adding Gradle-aware Make to Debug Configuration as stated by @Seven did the trick. – Jay Smoke Apr 03 '19 at 23:50
  • for me changing the release apk location fixed the issue. – bravo Aug 05 '20 at 08:40
  • @nasch The "Reimport Gradle "- Button moved to drop-doqn menu. Do a right click on the highest tree node in the picture (Right click on "alamap") – longi Oct 21 '20 at 11:53
  • @longi Well thank you, but I'm not still trying to figure it out after almost two years. :-) – nasch Oct 22 '20 at 14:13
211

If you are facing this issue after the update to Android Studio V 3.1 then try the below.

I was facing this same problem when I updated to Android Studio 3.1. All other solutions I found here were quite manual because you have to clean and rebuild every time, that is not good at all. But thanks to Iman Marashi's answer here I was able to solve it.

Go to Run -> Edit Configurations...

Make sure you have a "Gradle-aware Make" on the Before launch section:

Run/Debug Configurations

To add it click the + sign and select Gradle-aware Make and a popup will appear, just leave the text field empty and click OK and OK.

Prateek
  • 3,923
  • 6
  • 41
  • 79
Seven
  • 3,232
  • 1
  • 17
  • 15
  • 13
    This is the fix for the recent 3.1 update. For me, the first symptom of this issue was the APK not "responding" to changes in the code. It's now clear to me that the new APK wasn't building properly at all. – David Gay Mar 29 '18 at 14:54
  • This answer can solve for me. I updated 3.1 and get this error. – ZarNi Myo Sett Win Mar 30 '18 at 03:40
  • This helped resolve my issue where I have my build.gradle changing the name of the APK that is kicked out based on the `variant`, `versionCode`, & `versionName`. – Rockin4Life33 Mar 24 '19 at 20:50
  • I faced the problem after Android Studio froze and been killed while building a release APK and that answer solved the problem – lior_13 Mar 26 '19 at 11:36
69

In my case, executing "Sync Project with Gradle Files" helped. Neither restarting Andoid Studio nor clearing the cache did anything.

Bartek
  • 1,327
  • 1
  • 11
  • 22
34

If you just want to know the conclusion, please go to the last section. Thanks.

Usually when building project fails, some common tricks you could try:

  • Build -> Clean Project
  • Check Build Variants
  • Restart Android Studio (as you mentioned)

But to be more specific to your problem - when Android Studio could not find the APK file on disk. It means that Android Studio has actually successfully built the project, and also generated the APK, however, for some reason, Android Studio is not able to find the file.

In this case, please check the printed directory according to the log. It's helpful.

For example:

With Android Studio 2.0 Preview (build 143.2443734).

  1. Checkout to a specific commit (so that it's detached from head): git checkout [commit_hash]
  2. Run project
  3. Android Studio tells: The APK file /Users/MyApplicationName/app/build/outputs/apk/app-debug-HEAD.apk does not exist on disk
  4. Go to the directory, there is a file actually named: app-debug-(HEAD.apk (with an extra parenthesis)
  5. Run git branch

    *(HEAD detached at 1a2bfff)

So here you could see, due to my gradle build script's mistake, file naming is somehow wrong.

Above example is just one scenario which could lead to the same issue, but not necessary to be the same root cause as yours.

As a result, I strongly recommend you to check the directory (to find the difference), and check your build.gradle script (you may change the apk name there, something like below):

applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def newFileName = "whatever you want to name it";
            def apk = output.outputFile;
            output.outputFile = new File(apk.parentFile, newFileName);
        }
    }
Jing Li
  • 14,547
  • 7
  • 57
  • 69
  • 2
    My issue was that I was adding the app version in the APK name but the app version has x.y.z format and the "." (dot) in the naming was causing the errors. So remember no other dots but the one before apk :) – DraganescuValentin Sep 02 '16 at 09:15
20

Make sure that you don't have apostrophe or & in your path

Rim Gazzah
  • 571
  • 1
  • 6
  • 13
19

Make sure that there is Grading-aware Make in Run/Debugging configurations >> before launch section :

Like this image

Iman Marashi
  • 5,593
  • 38
  • 51
17

I witnessed a similar issue usually when I'm switching git branches. For me shutting down Android Studio rm -rfv ~/Library/Caches/AndroidStudio* and restart Android Studio is the ticket.

user213493
  • 892
  • 8
  • 10
  • My similar issue was solved by this method. I rename apk files in the gradle build to append the version number to the file, trying to debug my main activity was trying to run the wrong apk file name (previous version number). Not sure when this started but it was working fine until it didn't. – David Dec 14 '15 at 00:18
  • Android studio cache it is very big problem! – GeekHades Dec 22 '15 at 09:20
  • It is. I have just (again) incremented my build number, this changes the apk file name, again I have this problem. – David Dec 23 '15 at 04:49
13

In Android Studio 3.1.1 select File | Sync Project with Gradle Files.

In Android Studio 3, select File | Synchronize.

Then run your project again.

live-love
  • 48,840
  • 22
  • 240
  • 204
  • In Studio v3.1.1 , File -> Sync Project with Gradle Files. and you are good to go – Napolean Apr 17 '18 at 11:12
  • Then in a field on top toolbar(with icones), in next from hammer icon you have to return 'app ' back, in configuration dropdown – CodeToLife Feb 15 '19 at 20:35
11

The year is 2018. Android Studio version is 3.2.0 alpha3 and we still get this problem. As none of the above worked for me, here is my 2 cents:

Every time this happens I just generate the apk from command line:

gradlew assembleDebug

UPDATE

Deleting the folder .AndroidStudio[version] and losing all your preferences and caches... seems to solve the problem

Androiderson
  • 16,865
  • 6
  • 62
  • 72
  • 1
    but this only works for one build? if you make further changes and press the 'play' button, it just pushes the old apk and doesn't rebuild for the changes. So annoying, wtf were they thinking – behelit Mar 23 '18 at 02:55
7

In my case, I was using a special character in my app file path. I closed the Android Studio and removed the ' character from my app file path. Everything worked fine when I reopned the project.

Immortal Code
  • 101
  • 1
  • 5
  • Yeah ideally Android Studio should be smart enough to prevent users from using special character in their file path. Or better I should have followed the good programming practices myself :) – Immortal Code Nov 02 '16 at 16:12
6

I've solved building an apk using the Build option from the top window and Build APK. No need to do something weird.

Mun0n
  • 4,438
  • 4
  • 28
  • 46
6

For Unix like users (Linux/MacOs X), instead of removing ~/.gradle/caches/, in command line do :

$ cd path_to_you_project
$ touch build.gradle

Then ask Android Studio to build APK, it will reset gradle cache itself.

Jean-Marc Delafont
  • 534
  • 1
  • 5
  • 6
5

My problem is that I was appending the version number to the APK. Changing the version number and re-syncing Gradle fixed the problem for me.

def appendVersionNameVersionCode(variant, defaultConfig) {
    variant.outputs.each { output ->
        if (output.zipAlign) {
            def file = output.outputFile
            def removeApp = file.name.replace("app-", "")
            def removeType = removeApp.replace("-release", "")
            def fileName = removeType.replace(".apk", "." + defaultConfig.versionName + ".apk")
            output.outputFile = new File(file.parent, fileName)
        }

        def file = output.packageApplication.outputFile
        def removeApp = file.name.replace("app-", "")
        def removeType = removeApp.replace("-release", "")
        def fileName = removeType.replace(".apk", "." + defaultConfig.versionName + ".apk")
        output.packageApplication.outputFile = new File(file.parent, fileName)
    }
}
Lou Morda
  • 5,078
  • 2
  • 44
  • 49
3

Build ---> Build APK(s) and be sure it works

Kadir altınok
  • 230
  • 2
  • 5
2

File -> Invalidate Caches / Restart

dvrm
  • 3,749
  • 4
  • 34
  • 43
2

If you tried all the above answers and it didn't work try to disable "Instant Run" feature. This one helped me after all attempts.

File -> Settings -> Build, Execution, Deployment -> Instant Run -> Uncheck checkbox there

AnZ
  • 1,040
  • 24
  • 54
2

I also got that issue, after cleaning the build. For me solution was I just sync the gradle and it worked for me.

u_pendra
  • 908
  • 1
  • 10
  • 25
2

In my case the problem was that debugging configuration become invalid somehow, even that the test method name, class or package has not changed.

I deleted the configurations from Run->Edit Configurations, at here:

enter image description here

Android studio will create a new one automatically.

MiguelSlv
  • 14,067
  • 15
  • 102
  • 169
2

Sync, Clean, Rebuild and Invalidate Cache and Restart

None of them worked for me.

I have deleted the APK and output.json files in the release folder and debug folder and then tried sync, clean, and build, then it worked fine.

OR simply Delete folder which has the apk and output.json file (in case of debug/ release)

GiridharaSPK
  • 496
  • 7
  • 17
1

Faced the same issue with gradle 1.5

I had to clean the build files:

Build -> Clean project

And build an APK to force the full compilation and sync of the gradle files:

Build -> Build APK

I still don't know why or how it happened tho.

Simon PA
  • 748
  • 13
  • 26
1

if you are using Linux, try setting write permission to the app/build folder.

1

i had the same problem. it was due to false name in the path. there was a special Character in the path like this: C:\User\My App\Projekte-Tablet&Handy i deleted the "&" character and it worked well.

Orientos
  • 151
  • 3
  • 15
1

My problem was including minutes in the file name - it looked for appname_debug_0.9.0.1_170214_2216.apk when the generated file was appname_debug_0.9.0.1_170214_2217.apk so the output filename code (nabbed from elsewhere) was clearly being called from two different points in the build.

applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def project = "appname"
            def SEP = "_"
    //        def flavor = variant.productFlavors[0].name
            def buildType = variant.variantData.variantConfiguration.buildType.name
            def version = variant.versionName
            def date = new Date();
            def formattedDate = date.format('yyMMdd_HHmm')

            def newApkName = project + SEP + /*flavor + */ SEP + buildType + SEP + version + SEP + formattedDate + ".apk"

            output.outputFile = new File(output.outputFile.parent, newApkName)
        }
    }
Ian Spencer
  • 546
  • 3
  • 8
  • where is this block from? – Nerius Jok May 06 '18 at 09:49
  • It was from some other stack exchange thread from when I was first setting up the project (and had very little idea what I was doing - nothing changed there). As this part of Gradle has been changed a few times it is likely obsolete code now. – Ian Spencer May 07 '18 at 15:08
1

The problem for me was that somehow it could really not find the apk, while the apk exists.

The APK file /Users/Paul/AndroidStudioProjects/android-tv-launcher/ui/build/outputs/apk/nameofapk.apk does not exist on disk.
Error while Installing APK

All I had to do, was right click on the apk-copy relative path, and just

adb install -r <paste of relative path>

And the apk was installed and good to go. This issue happened on OSX for me.

Boldijar Paul
  • 5,405
  • 9
  • 46
  • 94
1

Solved in may of 2018 with the new Android Studio 3.1. Delete the .gradle, .idea and build directories inside your app folder. Then try to run it again and you won't see the error.

Gerardo Suarez
  • 352
  • 2
  • 13
0

I change build.gradle file a litle info,and click "Sync Now",just ok.

0

Remove the directory ~/.gradle/caches/. It's OK to do this while Android Studio is opened. (Refer pm installing wrong package name) Press "Sync project with Gradle files" icon on Android Studio Run the project and the remote path will be correct.

Refer answer @ Android Studio gets package name wrong when running .apk

Community
  • 1
  • 1
mask
  • 6,172
  • 3
  • 24
  • 23
0

Make sure that in the path generated in your logs -in your case:

/Users/MyApplicationName/app/build/outputs/apk/app-debug.apk

folder "outputs" indeed has an "apk" folder.

That was my problem, if it's not there, you will need to run the "assembleRelease" task in gradle by following the below screenshot;

Steps to run the gradle assembleRelease task Then the folder will be generated.

Amgad
  • 169
  • 2
  • 7
0

Nothing above helped me, but I figured this out by switching to another flavor in the Build Tools panel and then switching back to the needed one.

Dmytro Karataiev
  • 1,214
  • 1
  • 14
  • 19
0

modify the file:build.gradle(app directory). in fact:you should not change this file , only by this to get sync tips,then sync project.

兰坡阳
  • 151
  • 1
  • 3
0

The button is called "Sync Project with Gradle Files" and it looks alike: Gradle Sync... always need to click it, when updating the version number, which is resulting in another APK filename (unless the filename has not changed, installing the package always works, which hints for, that the filename is being cached). The equivalent Gradle CLI option appears to be --recompile-scripts.

@see Appendix D. Gradle Command Line.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
0

First remove cleaner by going to edit configuration, It may be cleaning the build after building the apk.

Click on edit from set run/debug then click on gradle list select the clean project item and then click on -(top 2nd from left).
Sonu Kumar
  • 91
  • 1
  • 8
0

Using Android Studio 2.2.1, I clicked the Sync Project with Gradle Files option, from the dropdown at the top, Tools>Android

Similar, to an answer posted above, see below for a screenshot of how to get to this option.

enter image description here

Lee Brindley
  • 6,242
  • 5
  • 41
  • 62
0
    1) This problem occure due to apk file .if your apk file
        (output/apk/debug.apk) not generated in this format . 

    2) you should use always in gradle file .

    buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
priti
  • 892
  • 9
  • 9
0

I got it to work by:

  1. Closing the project
  2. From the Android Studio Welcome Window (or File > New), click on Import Project.

I guess that forced it to reinstall the APK, and now everything is running fine.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Viren Mody
  • 11
  • 1
  • 2
0

i solved this app by doing

  1. First Build - > Build Apk(s)
  2. Run the app now

if it not worked do Clean and build the project and then do again 1 & 2.

saigopi.me
  • 14,011
  • 2
  • 83
  • 54
  • That works but is very inconvenient as you have to do that process every time you want to run your app. If you are having that problem after a Android Studio update take a look at my answer on this thread... – Seven Mar 28 '18 at 15:47
0

I tried all of these things and none of them worked. I ended up having to do a couple of these things are the same time. Very frustrating that it took this much time.

The problem I had was related to running my unit tests following the upgrade to AS 3.1.

Here is what I did... 1.) Run / Edit Configurations / Select Tests.... 2.) Add options to "Gradle-aware Make" 3.) Select check box "Skip installation if ADK has not changed" on Misc tab

Good luck.

Rob Breidecker
  • 604
  • 1
  • 7
  • 12
0

Go to Build option on the top bar of android studio>create 'Build APK(s)', once build has created, open the folder where it has available(app\build\outputs\apk) then close the folder, that's all....then try to install the app.

BISHWAJEET
  • 61
  • 6
0

Solved this issue by updating the Android SDK-Build Tools.

Christian Schulzendorff
  • 1,431
  • 1
  • 18
  • 15
0

in my case, just

View > Tool Windows > Gradle > right click [project] > Refresh Gradle Project

Jenkyn
  • 199
  • 2
  • 10
0

assemble[Variant] would generate the APK for you on disk although it should not be necessary to use it to debug the app.

Run the following command in the root directory of the project:

$ ./gradlew clean build assemble[Variant]

GL

Braian Coronel
  • 22,105
  • 4
  • 57
  • 62