Cannot reach obb expansion file on android 10 device if apk and obb is downloaded from Google Play store-ThrowExceptions

Exception or error:

I looked for solutions from many places (Test programmatically if in Android 10+ the legacy external storage access is disabled, https://developer.android.com/google/play/expansion-files.html#Downloading, etc.), but don’t know the exact cause of the error.
If app is downloaded from Google Play only in case for android 10 devices, it gives this error:

Caused by: java.lang.IllegalArgumentException: Couldn't get OBB info for /storage/emulated/0/Android/obb/packageName/main.package_version.packageName.obb

The program can find the obb file (even on android 10 devices)

File mainFile = new File(Environment.getExternalStorageDirectory() + "/Android/obb/" + packageName + "/" + "main." + packageVersion + "." + packageName + ".obb")
mainFile.getAbsolutpath()

gets the file path too. However, when Storage Manager is used for app that is downloaded from Google Play store

sm.mountObb(mainFile.getAbsolutePath(), null, mainObbStateChangeListener );

it cannot reach obb expansion file and terminates app with above error.

App can be downloaded from Google Play, but works only for android 9 or below devices. If I create apk and install it on android 10 device, the app can reach obb file without any problem.
What do I miss to be able run app on android 10 devices when it is downloaded from Google Play store? Help would be appreciated.

Update:

I found the cause of the error on Android 10 device, though I still don’t know the answer:

If the apk version code (the version code in app gradle) matches to the version code in the obb file name (which it should be if I understood well (https://developer.android.com/google/play/expansion-files), then in the obbexpansionmanager class, the line

sm.mountObb(mainFile.getAbsolutePath(), null, mainObbStateChangeListener ); 

throws this error:

Caused by: java.lang.IllegalArgumentException: Couldn't get OBB info for /storage/emulated/0/Android/obb/packageName/main.package_version.packageName.obb. 

If I change the downloaded app’s obb file to a different version code (tested with version code 8, 1, 10 when apk’s version code was 9) then app starts and above error does not come up. However, I cannot use different version code in the obb file’s name other than the apk’s version code to be able to download apk with obb from Google Play store. Furthermore, the media files cannot be reached from obb file unless it matches version codes.
If the device is under Android 10 then app works with same version code in apk and in obb expansion file.

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *