Android Studio downloads a sterile APK to the device when Gradle has custom logic that changes APK names

When using Android Studio, I found the following error: enter image description here

The APK date is 2 days older than the current one (Gradle is used to add the build date to the APK name). I checked the \ build \ output \ apk folder, and an APK with the correct date was actually generated: enter image description here

The following have been tested:

  • Assembly → Clean Project
  • Assembly → Restructuring Project
  • File -> Invalid Cache / Restart ...

How can I fix this so that the correct APK can be downloaded to the device?


Edit: The name has been changed to better reflect the circumstances in which this problem arose. It appears that Android Studio will remember the APK names provided by Gradle when it was synchronized with Android Studio, but will not update the APK names when Gradle starts to create the actual files.

In my situation, this is due to the fact that the current date is added to the APK name, so if I synchronize Gradle with Android Studio on 12/3, Android Studio will remember the name of the APK file as app_2014-12-03.apk). Then using Gradle to build and run the application on 12/4 will disconnect between Android Studio and Gralde, where Gralde generated app_2014-12-04 .apk, and yet Android Studio still remembered the APK file name for app_2014-12-03 .apk .

+2
android android-studio gradle
source share
2 answers

This is a sync issue between Gradle and Android Studio. Click the Gradle sync icon (this is the icon between the project structure and AVD Manager) and this will solve the problem.

(In the comments that you asked for explanation, I found this answer a few weeks ago when I also had a problem with this [but now I can not find this page]. If I remember the information correctly, then during Sync Gradle inform AS about various information, including the apk path. In your case [and mine in the past] the path changes every day, since we have a date in the apk name, and because of this we have to make Sync)

+2
source share

If you need a workaround, you can check out my answer to this post .

Basically, you only rename the APK when creating the command line, for example, from the CI server. With normal development, Android Studio works as usual.

0
source share

All Articles