tinonetic
tinonetic

Reputation: 8036

Android Studio is installing old apk on device

I am developing an Android app using Android Studio (0.89 Build #AI-135.1404660, Built on Sept 3,2014) using both emulator and Nexus 4 device.

I had the same issue with a version prior to that.

The problem is that after I changed my code and resource files, I still get the old apk installed on the device or emulator.

What do I need to do to get it to run current code? Is it a building config?

Is it a known issue with Android Studio?

Or with a Nexus 4 device?

This is the second time it has happened, and I resolved it(then) after trying one of the steps below. They have not worked for me again.

Here is what I've tried

  1. Build > Clean Project > Restart Android Studio > Run
  2. Build > Rebuild Project > Run
  3. Step 1 plus Uninstalling of apk on device
  4. Step 2 plus Unistalling of apk on device
  5. Adding erroneous resource entry then running.

I have read the following:

  1. Android apk install: How to clear files from old version?
  2. adb - How to reinstall an app, without retaining the data?
  3. Device still has the old apk
  4. Android build doesn't update code base or resources for target .apk on device

None has worked so far.

Upvotes: 24

Views: 20581

Answers (16)

Ruslan
Ruslan

Reputation: 31

I clicked here I clicked here

Then I removed this configuration(the name can be different) Then removed this configuration

And then I added it again by clicking on this button and then I added it again by clicking on this button

Upvotes: 0

Xhy
Xhy

Reputation: 41

The problem occurred on my Android 11 devices. I guess ART ran old code dex2oated.

Solution:

On Android Studio Topbar click on Run/Debug Configurations dropdown menu -> Edit Configurations.. -> General tab. Under Installation Options you will find Always install with package manager (disable deploy optimization on Android 11 and later) option.

Check the option and press OK to apply.

enter image description here

Upvotes: 4

nizam.sp
nizam.sp

Reputation: 4062

I did "Clear Cache" in App settings and then it launched properly

Upvotes: 0

Cactusroot
Cactusroot

Reputation: 1058

My devices also ran old states - dont know from where in my git it has taken these.

I created a new configuration (default is "app") and it worked.

Upvotes: 0

Shriharsh Pathak
Shriharsh Pathak

Reputation: 156

The solution to this issue is actually very simple. Android studio is actually not detecting some small changes that you have made to the application. That is why it is installing the previous builds. The solution is easy -> Remove the previous builds.

In the right side, go to gradle tab.

  1. Expand Tasks. Find "clean" or "cleanCache" task or any task that starts with "clean". Double click to run that task.
  2. Expand "app". and do the same.

Then File> Invalidate cache and restart.

Enjoy!! Your problem is solved...

enter image description here

Upvotes: 0

anemomylos
anemomylos

Reputation: 641

Same problem, none of the solutions mentioned here had any effect. I had to disable the "Allow parallel run" in "Menu > Run > Edit configurations...".

You can read more about this option here: How to run the same project multiple times in IntelliJ IDEA?

Upvotes: 0

ribhu69
ribhu69

Reputation: 140

Check Your Layout Files.

I ran into the same problem and I realized, it gives some problem if you have same layout in multiple orientations(portrait and landscape). If one is changed other remains unchanged and then it creates a conflict. So android studio installs the one with the previous layout

PS: This was happening in my case.

Upvotes: 1

Saurabh Sanyal
Saurabh Sanyal

Reputation: 11

I am using android studio for building flutter app, I was facing the same issue untill I did the following:

  1. From Android Studio, go to Tools-Flutter-FlutterClean

It resolved my problem as of now.

Upvotes: 1

Peter
Peter

Reputation: 111

I've spent way too many hours to keep this to myself. The way I fixed it was that I noticed some hours later that I was using different layout version in res/ .... I have actually two versions of layout (layout-v26) and (layout). All this time I was modifying the other one and uploading different one. Maybe its just a newbie mistake but I hope somebody will find it useful.

The reason why there are 2 version was because of " autofillHints="" -> quickfix -> create new version of layout "

image of my tree

Upvotes: 1

mehmoodnisar125
mehmoodnisar125

Reputation: 1529

In android studio. at right side. see gradle option. click it. and then press circular arrows button shown in red square.

In android studio. at right side. see gradle option. click it. and then press circular arrows buttons shown in red square.

Upvotes: 0

mir
mir

Reputation: 381

Google thinks it is a feature, not a bug

https://code.google.com/p/android/issues/detail?id=156263

Their proposed solution is to copy the apk(s) instead of manipulating the filename, as in e.g.

Copying APK file in Android Gradle project

Upvotes: 1

David
David

Reputation: 89

Run / Debug Configurations / Miscellaneous TAB [] Uncheck: Skip installation if APK has not changed

Android Studio doesn't always detect small changes in code.

Upvotes: 7

JamesD
JamesD

Reputation: 301

I had the same problem. After trying numerous methods that didn't work, I realized that I had accidentally changed an option in my "Run Configuration". Here's exactly what I did to fix the issue.

  1. Run --> Edit Configurations
  2. With your configuration selected on the left panel (mine says "app"), in the General tab on the right panel, there is a section called "Before launch". This section should have an option added called "Gradle-aware Make", but I had accidentally removed it.
  3. I re-added it by pressing the "+", then clicking OK in the popup (leave the input box in the popup blank).
  4. Click apply.

This fixed the problem immediately. Hope this helps someone!

Upvotes: 30

tinonetic
tinonetic

Reputation: 8036

The behaviour is erratic. I solved it by reviewing my code.It turned out that there was a resource file that was invalid. Try reverting back to the last working version of your code before the current changes... Probably a known issue that will be/was resolved out of Beta

Upvotes: 2

You should select "Deploy default APK" option in Run/Debug Configurations. After that Android Studio will upload and install new apk to your emulator/device when you run application.

Upvotes: 0

Rakesh
Rakesh

Reputation: 1035

I was also facing this issue and get solution by deleting build folder manually because some time ide cannot be able to delete this. So go to the app folder and find build folder delete this and after clean and build project and run again. projectname->app->build

Upvotes: 0

Related Questions