55

I have this random issue with ionic build or ionic run.

I've noticed that during compilation it uses the cache of my source code, therefore when making new changes it doesn't reflect upon re-compiling the app.

So my question is, how can you clear the cache for the build files? I've tried doing ionic state reset but still it doesn't work nor doing uninstall then re-install the app from my Android.

Thanks

Rene Padillo
  • 2,250
  • 4
  • 26
  • 39
  • 1
    possible duplicate of [Is it possible to clear the view cache in Ionic?](http://stackoverflow.com/questions/28676631/is-it-possible-to-clear-the-view-cache-in-ionic) – Swapnil Shende Aug 25 '15 at 07:02
  • 5
    @SwapnilShende I think this isn't a duplicate question, because my issue is with the Ionic build not with views. – Rene Padillo Aug 25 '15 at 07:04
  • Does this really happen? I am not sure on this. If you can reproduce it, then open an issue on github – InfinitePrime Aug 25 '15 at 07:11
  • @InfinitePrime yes, I'm stuck with the build for an hour already, I've doubled check everything but it seems it's using a cached source files upon building. I'll try to investigate on how to reproduce the problem. – Rene Padillo Aug 25 '15 at 07:15
  • @InfinitePrime Yes it really happens. All of a sudden it started happening in my ionic. And no matter what I do, clear browser history, restart IIS and all crazy stuff, my ionic is stuck with 2 days old changes. – Sandy Nov 24 '16 at 13:55
  • 2
    2 years and this still seems like an issue because it is happening to me. What's the point of live reload if it doesn't reload? To have to reinit the platform each time is ludicrous. – dbinott Jul 14 '17 at 02:58
  • in which platform are you facing this problem. I think you are facing problem in ios. – Khurshid Ansari Feb 16 '18 at 12:24

13 Answers13

48

What I did to solve my problem was to do re-initialize the Android platform.

ionic cordova platform remove android then ionic cordova platform add android

goto task manager and kill java se process

Obay Abd-Algader
  • 1,079
  • 12
  • 25
Rene Padillo
  • 2,250
  • 4
  • 26
  • 39
13

You need to increment your app version on your config.xml (at the top of your project folder) to reflect your changes before running:

<widget id="com.yourapp.id" version="0.0.8" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"

On this example, increment the attribute version to 0.0.9: version="0.0.9".

Then run android or run ios.

Gautier Drusch
  • 701
  • 5
  • 16
8

Remove platform :

ionic cordova platform rm android

Re add platform :

ionic cordova platform add android

Step 1) copy www folder specific platform

ionic cordova prepare android

Step 2) build apk

ionic cordova build android

Step 3) deploy latest apk in device

ionic cordova run android
Khurshid Ansari
  • 4,638
  • 2
  • 33
  • 52
6

If you use cordova build, sudo cordova build <platform>

sudo cordova prepare

at your cordova project root folder.

this command reflects your changes to builds(all platforms).

M.M
  • 2,254
  • 1
  • 20
  • 33
Kumquat601
  • 106
  • 3
  • 5
4

This might be a bug with Ionic, but to fix it usually I just ctrl+c then gulp and then re-run ionic serve.

babycakes
  • 547
  • 7
  • 21
4

I have deleted android-debug.apk from platforms/android/build/outputs/apk and then ionic cordova run android. It worked with no cache.

Sohan
  • 1,121
  • 1
  • 14
  • 27
2

Would like to answer this question as it wasted some real valuable time for me.

I emptied the platforms folder and build the solution again. BTW, I am using Visual Studio for development. And I should solve the problem.

Also it is quite obvious but still wanted to reiterate that platforms should not be part of source control.

Hope it helps.

Sandy
  • 11,332
  • 27
  • 76
  • 122
2

Try

ionic repair

This is a full clean build of all yur packages Official Documentation: https://ionicframework.com/docs/cli/commands/repair

Sisir
  • 4,584
  • 4
  • 26
  • 37
1

I had the problem where the app would load most recent changes locally using npm run dev but when I tried to run on my device with cordova run android it would load an old version. I tried all of the suggestions above and nothing worked. I finally figured out that if I did an npm run build before I did the build with cordova to my device, it would load the new version. Hope this helps someone.

Shane Richardson
  • 107
  • 1
  • 2
  • 8
1

No need to remove and add platform instead clear project file

For android users

cd android 

.gradlew clean

For ios users

cd ios
xcodebuild clean

final step

npx jetify

npx cap sync
Balaji
  • 9,657
  • 5
  • 47
  • 47
0

To complement the solution by @Renesaensz, in ionic 4.5.0 (or greater version) add cordova to the commands:

  • ionic cordova platform remove android

then ionic

  • ionic cordova platform add android
Rafael Paredes
  • 111
  • 1
  • 3
0

In order to get the plugin files present in node_modules, I also had to remove plugins and www folders, prior to regenerating the platform.

massic80
  • 322
  • 4
  • 15
0

cordova clean and closed all open files worked for me.

Raja Sekaran
  • 397
  • 4
  • 10