WWW.LoadFromCacheOrDownload() on OBB fails with NPE in Java layer

Using Unity 4.6.8f1 I get the following error while using WWW.LoadFromCacheOrDownload()

I’ve checked the md5 of the OBB file and it is correct. I’ve deleted the OBB and tried again, same issue.
I didn’t see anything off with the file system permissions.

I’ll double check the generated bundle, but it looks like Unity could have caught this error better.

Target device is a nexus 9 running Android 6.0.

            string uri = "file://" + "
/storage/emulated/0/Android/obb/com.wewanttoknow.NumbersPro/main.11.com.wewanttoknow.NumbersPro.obb";
            www = WWW.LoadFromCacheOrDownload(uri , 0);       
            yield return www;
            if (www.error != null)
            {
                log ("ERROR " + www.error);
            }
10-27 06:54:15.254  3801  3816 I Unity   : MYLOG downloading file:///storage/emulated/0/Android/obb/com.wewanttoknow.NumbersPro/main.11.com.wewanttoknow.NumbersPro.obb
10-27 06:54:15.254  3801  3816 I Unity   : 
10-27 06:54:15.254  3801  3816 I Unity   : (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
10-27 06:54:15.254  3801  3816 I Unity   :
10-27 06:54:15.292  3801  3816 I Unity   : MYLOG ERROR java.lang.NullPointerException: Attempt to invoke virtual method 'int java.io.InputStream.read(byte[])' on a null object reference
10-27 06:54:15.292  3801  3816 I Unity   : 
10-27 06:54:15.292  3801  3816 I Unity   : (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)

I tested on another device, nexus 7 running Android 5.1.1 and it works fine.

Is there a known issue with android 6 and LoadFromCacheOrDownload / asset bundles ?

Android 6 has a new permission system. You need to set targetSdkVersion in your manifest to something prior to 23.

OK Thanks. I’ll try that. I also found this article about it: java - Android 6.0 open failed: EACCES (Permission denied) - Stack Overflow

Does that mean that even for OBB file reading, Unity3d will need to ask permissions to be able read them ? Is this because the file was saved (by the Google Play app itself) to the external storage ? That sounds strange.

@bitter your solution breaks package upgradability.

  1. install game with targetSdkVersion 23 on Android 6.0
  2. try to install update built with targetSdkVersion < 23. Fails

See for example 1207194 - (targetSdkVersion23) [meta] Set targetSdkVersion = 23

My log:

11-23 10:30:24.405   597   621 W PackageManager: Package com.xxxxxxxxxx new target SDK 22 doesn't support runtime permissions but the old target SDK 23 does.
11-23 10:30:24.733  8126  8126 E Finsky  : [1] PackageInstallerImpl$2.onReceive: Error -504 while installing com.xxxxxxxxxx: -26: Package com.xxxxxxxxxx new target SDK 22 doesn't support runtime permissions but the old target SDK 23 does.

Unity Bug Fix - Problem (Android 6) - Urgent

The main issue is probably that Google hasn’t updated the Google Play APK Expansion to support the Android 6.0 permission model.

I created Android 6.0 compatibility · Issue #5 · Over17/UnityOBBDownloader · GitHub

@bitter , hadn’t seen your reply. I will test it. Thank a lot

@jerome-lacoste : as far as I can see, OBBDownloader has nothing to do with your error - it was the permission which was missing. @bitter has pushed a fix for Marshmallow permissions recently, should appear in all patches soon. I’ll doublecheck OBBDownloader/LVL plugins, but at the moment they look OK to me.