2

While using Android Studio I encountered the following error: enter image description here

The date of the APK is 2 days older than the current one (Gradle is used to append the build date to APK name). I've checked folder \build\outputs\apk, and an APK with the correct date has indeed been generated: enter image description here

The follows have been tried:

  • Build -> Clean Project
  • Build -> Rebuild Project
  • File -> Invalidate Caches / Restart...

How do I fix this so the correct APK can be uploaded to device to run?


Edit: Changed the title to better reflect the circumstances where this issue would occur. It appears that Android Studio would remember the APK names provided by Gradle when it's been synced with Android Studio, but does not update the APK names when Gradle is ran to create the actual files.

In my situation it's caused by the fact that the current date is appended to the APK name, so if I synced Gradle to Android Studio on 12/3 Android Studio would remember the APK filename to be app_2014-12-03.apk). Then using Gradle build and run the app on 12/4 would cause the disconnection between Android Studio and Gralde, where Gralde generated app_2014-12-04.apk and yet Android Studio still remembered the APK filename to be app_2014-12-03.apk.

Kai
  • 15,284
  • 6
  • 51
  • 82
  • Just trying to get more info; so you have found that the correct app is being generated? If so, that means that it is just an issue with Android Studio and its ability to send the APK to the device. Try manually sending the APK that you found in the output folder onto your device, just use email, and then see if the app works properly and has compiled properly. Then, the first thing that comes to mind, after working with Android Studio before, is to just reinstall it. But I would wait for a more creative solution, either from me or from someone else, before you do anything that drastic. – AeroVTP Dec 03 '14 at 03:30
  • @AeroVTP yes, the correct APK (xxx_2014-12-03.apk) has been generated and works as expected, the issue is that Android Studio keep trying to send some non-existing old APK (in this case xxx_2014-12-01.apk) to my device, which failed. And it's actually better that it has failed, now I suspect a number of head-scratching "how the frack can this bug still exist" moments in the past was due to sterile APK being sent to my device. I prefer to find a lasting solution to this rather than doing uninstall/reinstall, which kills productivity... – Kai Dec 03 '14 at 03:47
  • Try to find the local path that it is being stored at. I am attacking this problem as though the file is not found; so I would check out this StackOverflow post on how to fix the problem. Hopefully it will help. http://stackoverflow.com/questions/16869611/android-studio-apk-install-error-local-path-doesnt-exist – AeroVTP Dec 03 '14 at 03:51
  • @AeroVTP You can see from the 2nd image in my question that the APK was generated by Android Studio and stored in the correct place, so the main problem seem to be that Android Studio somehow decided that another version of APK is the most current one, instead of the one that it just generated a second ago :-/ – Kai Dec 03 '14 at 04:01
  • @MateuszPryczkowski That seem to have solved the problem... even though I didn't change Gradle in the intervening time. Is there a good explanation for this behavior? Regardless, please put up your comment as an answer and I'll mark it. – Kai Dec 03 '14 at 13:32

2 Answers2

2

It is a problem with sync between Gradle and Android Studio. Press Gradle Sync icon (it is icon between Project Structure and AVD Manager) and it will solve the issue.

(In comments you asked for explanation - I found this answer few weeks ago, when I had also issue with this[but now I cannot find this page]. If I remember correctly was information, that during Sync Gradle is informing AS about different information including info about apk path. In your case [and mine in past] path is changing every day, as we have date in name of apk and due to this we have to make Sync)

Mateusz Pryczkowski
  • 1,874
  • 1
  • 16
  • 20
  • what could be the reason this is helps only for one time ? every time before i run my project i have to sync Gradle... – Jesus Dimrix Apr 08 '15 at 09:20
0

If you want a workaround for this you can check out my answer on this post.

Basically, you wold only rename the APK when doing a command line build, such as from a CI Server. While doing normal development Android Studio works as usual.

Community
  • 1
  • 1
Tom Bollwitt
  • 10,849
  • 1
  • 17
  • 11