Android studio "Your app does not have the latest code changes.." - android

I tried to run app from Android studio, and it worked. But after stopping and starting few times this message appears.
Uninstalling and installing over again works, but as soon I restart the program the same message reappears.
"Your app does not have the latest code changes because it was restarted manually. Please run from IDE instead."
I am running everything from IDE. Nothing it done through the phone itself.

For me even killing the app and running from Android Studio still appeared the same sentence "Your app does not have the latest.."
What always works is Run > Computer > Clean and Rerun 'app'

You saw this message because you killed and restarted your app manually after "Instant Run" applied changes to your app.
In Android Studio 2.0, a new feature was added called "Instant Run".
Instant Run is described in the Android Studio Project Suite:
Introduced in Android Studio 2.0, Instant Run is a behavior for the Run and Debug commands that significantly reduces the time between updates to your app. Instant Run pushes changes to methods and existing app resources without building a new APK, so code changes are visible almost instantly.
A demo of Instant Run can be seen in this video.
If you make a small change or changes, those changes will be implemented via Instant Run. However, since it did not build a new APK, killing that running instance of your app will discard those changes from the app installed on your device.
From the Developer site:
Note: If you need to restart your app after a crash, do not launch it from your target device. Restarting your app from your target device does not apply any of your code changes since the last cold swap or incremental build. To launch your app with all your recent changes, click Run (or Debug ) from Android Studio.
To have the changes permanently implemented to your app, kill it (actually make sure it gets killed, don't just hit the home button), and then build and run it again from Android Studio.

well if that message appears you don't need to uninstall the app
Just press the red button highlighted in the pic
it will stop your app and then if you run it again then it will run fine with latest code.
NOTE: you can press red stop button only if the app is running and your device is connected to the android studio, it will kill the app process and when you re-run it it will have the latest changes.
if this doesn't solve your problem then you can go to Run>Clean & Re-Run.
Hope it helps

Use Rerun
When pushing code changes that affect certain initializers, such as changes to an app's onCreate() method, you need to restart your app for the changes to take effect. To perform an incremental build and restart the app, click Rerun .
If you need to deploy a clean build, select Run > Clean and Rerun 'app' from the main menu, or hold down the Shift key while clicking Rerun . This action stops the running app, performs a full clean build, and deploys the new APK to your target device.
I tested the way of Shifting key while clicking Rerun, it works fine.
Link : https://developer.android.com/studio/run/index.html

Related

How can I disable instant run on Android Studio 4?

I saw a similar question but none of the answers actually tell you how to disable it, just give workarounds for the issue. I want to totally disable instant run, how can I do that?
The issue I have is that no matter what I do, use the run button, the debug button, the apply changes button, clean, etc, any code I just wrote won't run until I uninstall the app on the phone, if I don't do that all I see is the old code running. I'm guessing instant run is the issue since I always get the message that says App restart successful without requiring re-install.
From android studio 3.5 and above you cant disable it but if your running an earlier version: Go to Android Studio Settings or Preferences (for MAC) -> Build,Execution,Deployment -> Instant Run. Then deselect the "Enable Instant Run" checkbox at the top.

run app vs apply changes android studio 2.3

What is the major difference between
Run app and Apply changes?
What could be the best scenario to use each?
Thanks.
"Apply changes" will be enabled if you have "instant run" enabled and to disable instant run check https://stackoverflow.com/a/35169716/2826147
From the Android documentation: https://developer.android.com/studio/run/index.html
Apply Changes button provides a faster workflow for most incremental changes to your app. [...]
You can clickApply Changes to push certain code and resource changes to your
running app without building a new APKā€”and, in some cases, without
even restarting the current activity. [...]
Clicking Run (or Debug ) forces a cold swap and an app restart.
If you make a change to the app manifest or a resource referenced by
the manifest, Android Studio always pushes your changes with a full
APK reinstall. [...]
Apply Changes action is available only when you meet the following conditions:
Build your app using a debug build variant.
Use Android plugin for Gradle version 2.3.0 or higher.
Set minSdkVersion to 15 or higher in your app's module-level
build.gradle file.
Deploy your app to a target device running Android 5.0 (API level 21)
and higher.
When you click "Run" App icon, it will uninstall existing build and install build every time.
"Apply Changes" option will be available only if you enable "Instant Run" feature in android studio. It will swap changes to existing build and run your build. Your existing build will not get uninstalled when you do this.
The Instant Run / Apply Changes feature will try to push your changes without building and deploying a full APK, and if possible without restarting the application or even the current activity. It will resort to a full reinstall if needed. More details here.
Before Android Studio 2.3, the Instant Run feature was available through the Run (or Debug) button, as long as certain conditions were met. Starting with Studio 2.3 we have a dedicated button for Instant Run, which is the Apply Changes button. It is only available when Instant Run is possible. The Run and Debug button now always restart the app.
From the Release Notes:
A separate button to push changes with Instant Run: After deploying your app, you now click Apply Changes to quickly push incremental changes to your running app using Instant Run. The Run and Debug buttons are always available to you when you want to reliably push your changes and force an app restart
for Android Studio 3.5 and higher

How to Run app in Android Studio without kill and restart the session?

At this point, Im using Android Studio 2.1.2. When I changed the code or without changed the code, the app is always kill and restart the session when I want to run the app.
Run App
So how to run the app without kill and restart the session?
You are wondering about Instant Run facility added in most latest versions of android studio. To use it please Make sure you have up to date Gradle plug-ins and builds because it's not only enough that having latest version of Android studio will support Instant Run it also required all stuff up-to-date so Please first check it out.
To check it out if it is disable follow this steps
1) Go to File -> Settings
2) Go to Build,Execution,Deployment -> Instant Run
By default It is enabled if everything is up to date. If not you can.
Go read this for depth understanding : https://medium.com/google-developers/instant-run-how-does-it-work-294a1633367f#.mqwx46kn6
And what is supported under instant run is given here.
https://stackoverflow.com/a/33905037/5476209
You need the latest Gradle build in your project for the same And also you need to run the same app in your phone so that the patch will be installed and activity will be restarted.
Please not that every time you hit an error in run time the quick launch will get disabled and you will have to rebuild the whole project to Instant run again.
Reference :http://tools.android.com/tech-docs/instant-run

Android studio build fast but run wrong in emulator

Exactly my problem, if I have small change in app about display UI (modify activity code or resource layout), Android studio build very fast and then run my app in emulator without kill "previous version" process (running in emulator), sometime it's run and display correct, but sometime it doesn't run correct what I want, I must kill process manual and rebuild project, it takes a lot of time, and makes me confused because I don't know where go wrong,
I thought this is my bug.
It happen recently when I update Android studio, I think this feature is very powerful and helpful, application mustn't rerun from the beginning whenever build new version.
But how to enabled/disabled "fast build", sometime I want Android studio build my project normally.
You have 2 solution:
1)You can also disable Instant Run from Settings > Build,Execution,Deployment > Instant Run - and disable it
2)Clean Project when studio doesn't build properly
Press the stop button before running the app and then run the app so dialog will be displayed to choose the emulator.

How do I uninstall and re-run an app on a device using Android Studio?

I am new to Android Studio and I feel that I must be doing something wrong. When running MyApp on an actual device the process goes like this.
Edit code.
Select the Run command in Android Studio. (Shift+F10)
Discover a Bug (on phone)
Navigate to Settings --> Application --> MyApp (on phone)
Force Stop (on phone)
Uninstall MyApp (on phone)
Edit code
Select the 'Run' command in Android Studio.
Repeat again and again.
This is repetitive and time consuming. Is there a way to uninstall MyApp via Android Studio?
If not is there some other more automated way to do this?
BTW I have seen this question How to automatically uninstall android app from device before installing a new version but it does not sufficiently address the issue.
I think this answer is what you're looking for. Basically edit your configuration to perform an uninstall before app launch.
From the Run menu -> Edit Configurations... -> Before Launch -> Add Gradle-aware Make -> ":app:uninstallAll"
You can execute the gradle task :app:uninstallAll to uninstall the app. The next time you hit Run your app will be reinstalled.
You can skip the force stop and uninstall step by just hitting run again. Android Studio should prompt you which device to run on and there you can select your connected device.
It will close the app and re-run your changed version.
I always just hit the "debug" icon (the bug icon) and from the debug tab (at the bottom of your screen), you can stop running the app by clicking on the stop button. No need to uninstall/reinstall app. When you're done, you can do a release build of the apk.
You can make just like this now. Check mark on Clear app storage before deployment.

Categories

Resources