Weird Ionic Android Image Cache Issue

I’m having a weird issue with images on my production built app on Android:

  • When the app is initially installed and ran on the phone, the images show up fine.
  • If I close and re-open the app, the images do not show up.
  • If I go to my phone’s “Manage Application” option, clear data in storage for that app, then restart, the image shows up again.

I’m not doing anything special. Just an img src=“assets/img/myimage.png”

Does anyone have any idea how I would go about fixing this issue?

Did you remote debug the problem on the device already? Follow these instructions here to debug the problem in Chrome dev tools: Look at the console and network tabs for errors.

Thanks for the quick reply Sujan!
I’ll give it a go and update you on the outcome.

Ok. It seems like the second time I run the app, it’s requesting the file at: file:///data/user/0/assets/myimage.png
The assets folder nor the file exists in the device storage.

Is this normal behavior for android devices?

Where is it requesting the file on first run?

What is your ionic info?
Are you using Ionic Deploy in your app?

1 Like

The first time I launch the app, it’s requesting: file:///android_asset/www/assets/img/myimage.png

ionic info:

@ionic/cli-utils  : 1.18.0
ionic (Ionic CLI) : 3.18.0

global packages:

cordova (Cordova CLI) : 7.1.0

local packages:

@ionic/app-scripts : 3.1.2
Cordova Platforms  : android 6.3.0
Ionic Framework    : ionic-angular 3.9.2


Android SDK Tools : 26.1.1
Node              : v6.12.0
npm               : 5.5.1
OS                : Linux 4.10

Environment Variables:

ANDROID_HOME : /home/comp/Android/Sdk


backend : pro

Ok, so your replies helped me to resolving the issue.

So before I manually built for android release, I changed where the resource was pointing to i.e. from …/…/assets/img to assets/img but I did not push the latest changes to Deploy.

So every time I started the app initially, the local resource would be loaded, but behind the scenes, Deploy would update the link from the old commit.

All I needed to do was update my commit to the latest and it worked every time.

Thanks again Sujan!

1 Like