简体   繁体   English

如果从 Google Play 商店下载 apk 和 obb,则无法在 android 10 设备上访问 obb 扩展文件

[英]Cannot reach obb expansion file on android 10 device if apk and obb is downloaded from Google Play store

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.我从很多地方寻找解决方案( 如果在 Android 10+ 中禁用旧的外部存储访问则以编程方式测试https://developer.android.com/google/play/expansion-files.html#Downloading等),但是不知道错误的确切原因。 If app is downloaded from Google Play only in case for android 10 devices, it gives this error:如果仅在 android 10 设备的情况下从 Google Play 下载应用程序,则会出现以下错误:

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)该程序可以找到 obb 文件(即使在 android 10 设备上)

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但是,当存储管理器用于从 Google Play 商店下载的应用程序时

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

it cannot reach obb expansion file and terminates app with above error.它无法访问 obb 扩展文件并以上述错误终止应用程序。

App can be downloaded from Google Play, but works only for android 9 or below devices.应用程序可从 Google Play 下载,但仅适用于 android 9 或以下设备。 If I create apk and install it on android 10 device, the app can reach obb file without any problem.如果我创建 apk 并将其安装在 android 10 设备上,该应用程序可以毫无问题地访问 obb 文件。 What do I miss to be able run app on android 10 devices when it is downloaded from Google Play store?当从 Google Play 商店下载应用程序时,我想念什么才能在 android 10 设备上运行应用程序? Help would be appreciated.帮助将不胜感激。

Update:更新:

I found the cause of the error on Android 10 device, though I still don't know the answer:我在 Android 10 设备上找到了错误的原因,但我仍然不知道答案:

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如果 apk 版本代码(app gradle 中的版本代码)与 obb 文件名中的版本代码匹配(如果我理解的话应该是这样的( https://developer.android.com/google/play/expansion-files) ),然后在 obbbexpansionmanager 类中,该行

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.如果我将下载的应用程序的 obb 文件更改为不同的版本代码(在 apk 的版本代码为 9 时使用版本代码 8、1、10 进行测试),则应用程序启动并且不会出现上述错误。 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.但是,除了 apk 的版本代码之外,我不能在 obb 文件的名称中使用不同的版本代码,以便能够从 Google Play 商店下载带有 obb 的 apk。 Furthermore, the media files cannot be reached from obb file unless it matches version codes.此外,除非匹配版本代码,否则无法从 obb 文件访问媒体文件。 If the device is under Android 10 then app works with same version code in apk and in obb expansion file.如果设备在 Android 10 下,则应用程序在 apk 和 obb 扩展文件中使用相同的版本代码。

A substitute method can be used instead of Environment.getExternalStorageDirectory() which is Context.getObbDir() which will return the full path of the OBB directory meant for the running application, ie: /storage/emulated/0/Android/obb/packageName .可以使用替代方法代替Environment.getExternalStorageDirectory() Context.getObbDir()它将返回用于运行应用程序的 OBB 目录的完整路径,即: /storage/emulated/0/Android/obb/packageName .

This can replace the code part Environment.getExternalStorageDirectory() + "/Android/obb/" + packageName .这可以替换代码部分Environment.getExternalStorageDirectory() + "/Android/obb/" + packageName More details of this method can be found here .可以在此处找到此方法的更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Android中挂载加密的obb apk扩展文件 - Mounting an encrypted obb apk expansion file in Android Google Play卡在扩展文件上传(OBB)上 - Google Play stuck on expansion file upload (OBB) 无法提取从Google Play应用程序下载的obb文件 - Unable to extract obb file downloaded from google play application 从APK扩展文件中读取内容(来自obb文件) - Read content from APK expansion file (from obb file) 使用API​​将OBB扩展文件上传到Google Play草稿工件 - Upload OBB expansion file to Google Play draft artifact using API 诊断无法从 OBB 文件加载/拆分 APK 扩展文件 android build(在 Unity 中) - Diagnosing failure to load from OBB file / split APK expansion file android build (in Unity) 手动下载的android obb文件,通过Play商店更新应用后删除 - Manually downloaded android obb file, deleted after app update through Play Store 我的obb文件已自动从设备中删除(Android扩展文件) - My obb file is getting removed from device automatically (android expansion files) 无法从android扩展文件OBB播放Exoplayer中的OGG音频文件 - Unable to play OGG audio file in Exoplayer from android Expansion file OBB 扩展文件-无法从Android 4.2上的/ sdcard / Android / obb /加载.obb - Expansion file - can't load .obb from /sdcard/Android/obb/ on Android 4.2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM