Nick Cardoso
Nick Cardoso

Reputation: 21733

Why is Android Studio not building and deploying correct apk

My issue is similar to this question however the app is deployed.

Currently on Windows when I click run in the Android Studio Gradle starts building as expected and says completed (sometimes completed with 1 warning and sometimes, depending on the situation I may get a dialog about uninstalling the previous APK)

Then the activity launches on the device or emulator as expected, but when I start testing it becomes obvious that the newest changes are not deployed. Either the installation has silently failed or an old APK from the build cache has been deployed.

I have instant run switched off but usually do not uninstall the app between running my changes, except where I have changed branches (Git) and Android Studio has told me the versions are incompatible.

Usually if the system gets into this state the only thing that helps is Invalidate Caches/ Restart

This is a hard issue to track, has anybody else encountered it and had success in preventing it?

Upvotes: 7

Views: 1625

Answers (1)

Nick Cardoso
Nick Cardoso

Reputation: 21733

I have not found a way to prevent this, but the following seems to work to ensure the correct APK is always installed:

  1. Uninstall from device/emulator
  2. Run Gradle/cleanBuildCache
  3. Run Gradle/clean
  4. Deploy

If you skip cleanBuildCache it fails. Clean alone doesn't appear to do enough.

I'm still looking for a better answer - post if you have one

Upvotes: 1

Related Questions