Crash during init of UnityAds (Android)

Hey,

We are seeing random crashes during the initialization of UnityAds on devices.

  • The version we use is 1.5.6-r2 (we are using UnityAds using mediation, through Fyber).

Here is the crash:

I have traced the code that is crashing, it seems that File.listFiles() may return null in some cases. The code then tries to iterate that null array:

File[] fileList;
FilenameFilter filter;
File[] fileList;
if (_cacheDirectory.getAbsolutePath().endsWith("UnityAdsVideoCache"))
{
  UnityAdsDeviceLog.debug("Unity Ads cache: checking cache directory " + _cacheDirectory.getAbsolutePath());
fileList = _cacheDirectory.listFiles();
}
else
{
  UnityAdsDeviceLog.debug("Unity Ads cache: checking app directory for Unity Ads cached files");
  filter = new FilenameFilter()
  {
    public boolean accept(File dir, String filename)
    {
      boolean filter = filename.startsWith("UnityAds-");
      UnityAdsDeviceLog.debug("Unity Ads cache: filtering result for file: " + filename + ", " + filter);
      return filter;
    }
  };
fileList = _cacheDirectory.listFiles(filter);
}
for (File cacheFile : fileList)
{
    ....
    }
}

Here’s the docs for listFiles() - File (Java Platform SE 7 )

Is this a known issue? has anyone else run into this?
Is this going to be fixed? or already fixed in a newer-released version?

Thx
-liortal

Are you seeing this on multiple different devices?

-Rasmus

Yes, here are examples of devices i saw it occurred on:

  • OnePlus A0001
  • Samsung GT-I9195
  • Sony D6603
  • HTC HTC One_M8
  • HTC HTC_M8x
  • HTC HTC Butterfly 2
  • HUAWEI HUAWEI GRA-L09

I have submitted a PR to the UnityAds repo yesterday, hopefully this does resolve the issue and can be merged into the code: https://github.com/Applifier/unity-ads/pull/89