'How to force refresh the cached source files upon Ionic build/run?

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



Solution 1:[1]

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

Solution 2:[2]

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.

Solution 3:[3]

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

Solution 4:[4]

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).

Solution 5:[5]

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

Solution 6:[6]

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

Solution 7:[7]

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.

Solution 8:[8]

Try

ionic repair

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

Solution 9:[9]

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.

Solution 10:[10]

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

Solution 11:[11]

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

Solution 12:[12]

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.