Ensuring Android Studio builds do not rely on physical device's cached version of anything

Viewed 25

TLDR

How can I ensure that when I deploy an app on a physical device via Android Studio that it is rebuilding and pushing everything from scratch and not relying on any cached version of anything on the physical device?

I'm observing strange behavior that can be fixed by clearing the physical device's app cache, or uninstalling it. This is a workaround, but not a fix. When I "run" (play button) in Android Studio I expect all changes I have made to be reflected on the app on the physical device without uninstalling or clearing the phone's cache manually.

Background

The original title for this question was going to be:

Input parameter changes value during inline debugger single step calling CameraBridgeViewBase.setMaxFrameSize

but after writing everything down in a draft here I discovered the cause of the problem, how to work around it, but not how to fix it permanently.

I was observing a method's input parameter changing when stepping into the method via an inline debugger.

I'm using OpenCV's android library and calling setMaxFrameSize() with two int values:

mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.color_blob_detection_activity_surface_view);
mOpenCvCameraView.setMaxFrameSize(1000,1000);

I updated these int values from 1000 to 200 and back again to 1000 but when entering the CameraBridgeViewBase class, it reverts back to 200. This sounds ridiculous, so let me illustrate with a step by step of what I did:

  1. Build and run the code using a value of 1000 for each input parameter of setMaxFrameSize. Note everything works as expected.
  2. Build and run the code using a value of 200 for each input parameter of setMaxFrameSize. Note everything works as expected. Resolution down, and frame rate up.
  3. Build and run the code using a value of 1000 again. Note the resolution still matches that set by the 200 value earlier.
  4. Set a breakpoint at the setMaxFrameSize method call and one inside the defition (i.e. inside my local copy of CameraBridgeViewBase)
  5. Note that the value for the input parameter is 1000 when called outside CameraBridgeViewBase, and that it is 200 within CameraBridgeViewBase. Thinking this must be a cache issue.
  6. Clear the cache and restart Android Studio. Retry the inline debugger and see the same behavior. Value is set to 1000 but upon entering CameraBridgeViewBase is now 200.
  7. Manually delete all build files in the module, and the OpenCV library. Rebuild from scratch. Try inline debugging again. Same issue persists.
  8. Thought I might have a watch that is setting it to 200, so I clear all my watches, but issue persists
  9. I intentionally set a watches of maxWidth = 1000 and maxHeight = 1000. This overrides the value of 200, and I the display appears as desired.
  10. I clear the watches, and try again. Again, the values revert to 200 upon entering CameraBridgeViewBase.
  11. I do a project-wide text search for setMaxFrameSize thinking some other thread was calling it and when I step in the debugger I was seeing that. Nothing. I also double checked the thread name and stack trace in the debugger to verify I was going directly from my call of mOpenCvCameraView.setMaxFrameSize(1000,1000); to the setMaxFrameSize() method inside CameraBridgeViewBase.
  12. I made a wip git commit and reduced my code to a minimal example with plans to paste here. Tried to rebuild and run and all sorts of other errors occurred leading me to find out that the app's cache on the physical phone I was running it on was causing ALL of this issue.

This is repeatable. I can go through Steps 1 to 3, clear the phone's app cache and the issue is gone. Repeat steps 1 -3 and it will be back. It seems the phone is keeping a cached version of CameraBridgeViewBase which contains the previous value set for maxHeight and maxWidth but this is just speculation based on what I observed in the inline debugger.

0 Answers
Related