Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 927
Nick Cardoso Avatar asked Aug 23 '17 15:08

Nick Cardoso


People also ask

Why is Android Studio not working?

If Studio doesn't start after an upgrade, the problem may be due to an invalid Android Studio configuration imported from a previous version of Android Studio or an incompatible plugin.

How can I create APK File in Android Studio?

Creating an APK file First, open up your project or application that you want to import into an APK file. Then, select Build > Build Bundle(s)/APK(s) > Build APK(s) from the toolbar menu. Android Studio will take a few moments to generate an APK file.

Where does Android Studio build APK?

Android Studio saves the APKs you build in project-name / module-name /build/outputs/apk/ .

Can I run an APK in Android Studio?

While the emulator is running, you can run Android Studio projects and choose the emulator as the target device. You can also drag one or more APKs onto the emulator to install them, and then run them.


1 Answers

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

like image 142
Nick Cardoso Avatar answered Oct 13 '22 00:10

Nick Cardoso