I follow this document to setup on-demand asset delivery like this:
// Get asset path
private fun getAbsoluteAssetPath(assetPack: String, relativeAssetPath: String): String? {
val assetPackPath: AssetPackLocation =
assetPackManager.getPackLocation(assetPack)
// asset pack is not ready
?: return null
val assetsFolderPath = assetPackPath.assetsPath()
return FilenameUtils.concat(assetsFolderPath, relativeAssetPath)
}
// download
assetPackManager.registerListener(downloadListener)
assetPackManager.fetch(listOf(packageName)).addOnCompleteListener{ res ->
Timber.i("Download $packageName ${res.isSuccessful}")
}
// access the file
var filePath = File(getAbsoluteAssetPath("myAssetPack", "test.png"));
// it throws java.io.FileNotFoundException when open this file.
There are a lot of crash reports from my users on Crashlytics, and look like it happens when they update the app with new asset package files on google play.
The problem is that I can't reproduce it on my devices.
Is there anyone know why this is happened?
P/s: before open the file, I already check the package existing and it is valid.
if(assetPackManager.getPackLocation(packageName) != null)