Search Unity

Help Please - Question about Google Play OBB Downloader

Discussion in 'Android' started by Zaddo67, Apr 9, 2014.

  1. Zaddo67

    Zaddo67

    Joined:
    Aug 14, 2012
    Posts:
    489
    My APK is bigger than Google's 50Mb limit. So, I need to split it. I am trying to work out the right way to do this.

    I have googled for a few days and I have a lot of resources to use.

    One of the key unanswered Questions I have is; Should I use Unity's Google Play OBB Downloader?

    This question has been posted in another thread
    (here)

    But unfortunately not answered.

    My concern is the comments on the Asset store that advise not to use it.

    If I don't use this asset, my next questions is, How do you manage downloading the OBB?

    I am desperate for an answer to these questions. Please help.

    THx.
     
    Last edited: Apr 9, 2014
  2. m-y

    m-y

    Joined:
    Sep 22, 2013
    Posts:
    472
    yes man u should download obb
    cause it will work well on google play
     
  3. Zaddo67

    Zaddo67

    Joined:
    Aug 14, 2012
    Posts:
    489
    Thx M.Y.
     
  4. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    You shouldn't need to do anything special? There's an option in Unity's Android Player settings to do the split. Then, when uploading to Google Play, you just need to upload your APK, and THEN upload the APK again as a new version. On the second upload you'll get a dialog box asking if you want to add any OBB files. At that point you can upload your OBB and you're all good.
     
  5. Zaddo67

    Zaddo67

    Joined:
    Aug 14, 2012
    Posts:
    489
    My understanding was that, the APK and OBB get uploaded to Google, as you said.

    But when the customer purchases the game on Google Play, their device will download the APK file and only sometimes the OBB.

    In the case where the OBB is not downloaded with APK, the first scene in Unity needs to detect this and handle the downloading of the OBB. This is what the "Google Play OBB Downloader" asset does.

    Steve, are you saying that this is no longer needed? i.e. OBB will always be downloaded with APK?
     
  6. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    Hmm... don't know about that then. All I know is that I uploaded a build, and it never asked for the OBB. The Google Play store (customer facing) said the game was 8MB to download. I did some reading and didn't find much, then decided to upload again. The second time I got the additional dialog which uploaded the OBB, and then the store entry updated to say 58MB. At that point I assumed everything was all good...

    ...now you have me worried :)

    I've only done one Android release so far so I'm far from an expert unfortunately.
     
  7. Zaddo67

    Zaddo67

    Joined:
    Aug 14, 2012
    Posts:
    489

    Sorry, didn't want to cause worry for anyone else.;)

    I found this on Google Play developer:

    http://developer.android.com/google/play/expansion-files.html

    It essentially says you need to cater for downloading the OBB.

    I am just concerned about the Negative comments on the asset store against Unity's OBB downloader. It looks like it could be painful implementing. From the comments, I gather it has some compatibility issues with v4 of Unity.
     
    Last edited: Apr 10, 2014
  8. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,125
    I've spent the last few days attempting this OBB thing to work.

    The confusion seems to stem that the way the OBB thing works has changed. The more recent threads / information is here:
    http://forum.unity3d.com/threads/135224-More-Google-OBB-drama/page3
    http://developer.android.com/google/play/expansion-files.html


    The gist is this:
    1. you don't need to use any "downloader scripts" - just click the "split application binaries" checkbox in the player settings
    2. you must rename the created OBB file like so:


    [main|patch].<expansion-version>.<package-name>.obb

    main.314159.com.example.app.obb

    does this mean no versions like 1.0 only 2334? I think so...

    3. for testing, place the obb file inside your device in these places:


    <shared-storage>/Android/obb/com.bigfishgames.google.heuiful/main.44.com.bigfishgames.google.heuifull.obb


    /sdcard/Android/obb/com.bigfishgames.google.heuifull/main.44.com.bigfishgames.google.heuifull.obb


    And.. it should work! or in my case, not work. I want to go home...
     
  9. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,125
    Just an update- the OBB thing did end up working when uploading to google play (wasn't able to get it to work for testing right away)

    for that:
    1. check the "split application binary" checkbox in player settings
    2. build
    3. rename your files as:


    main.1.com.yourcompanyname.productname.obb
    com.yourcompanyname.productname.apk

    where "1" is the version number (no 1.0 or anything like that - it has to be 1-9999999).
    and

    com.yourcompanyname.productname

    is your bundle id

    example:

    main.1.com.blizzard.warcraft.obb
    com.blizzard.warcraft.apk

    4. upload to google play - with each upload you have to increase the version number
     
    Last edited: Apr 16, 2014
    Zaddo67 likes this.
  10. Zaddo67

    Zaddo67

    Joined:
    Aug 14, 2012
    Posts:
    489
    After my initial post in April, I optimised my project and managed to get the APK back under 50Mb. But after a few more months of development, my project has crept back over 50Mb and optimising won't fix it this time.

    So, today, I worked through splitting my project into APK + OBB.

    For anyone else, trying to work through this. I highly recommend this tutorial:

    http://www.exoa.fr/tutorial-unity-4-apk-splitting-google-play-obb/#comment-179

    Here are some questions I found answers to as I worked through this process.

    Note. My bundle identifier is, com.zoneoffun.ropez, I use this name to demonstrate naming conventions below.

    1. The obb file that unity creates is named, RopeZ.main.obb.
    a. You don't need to rename this if you uploading to Google Play. When you upload, it automatically gets renamed into the correct format by Google..
    b. If you are going to side load it directly onto you Android device. Then you will need to rename it. This is the format: main.5.com.zoneoffun.ropez.obb, it needs to go into the folder ??/Android/obb/com.zoneoffun.ropez/ , I expect each device has OBB's in a diferent location, so I have just given a partial path.
    2. The big question, Do you need to include a OBB downloader in your game? I don't know... I tested downloading from google play without a downloader, and it downloads the APK and OBB at the same time and everything works. In researching, apparently some older devices won't download them together. So just to be on the safe side, I built the downloader into my game. Using the tutorial found via link above, it didn't take long, less than than 1/2 a day to code and test.

    3. You cannot use a APK with an OBB from a different build. It just doesn't work. The pair unity creates in a build, must go together.

    4. Yurithebeast's post above was helpfull. But just to clarifiy, the version number in the OBB file name is the "Bundle Version Code", you can have decimal places in your "Bundle Version". Also Yuri, renamed his APK. I didn't need to do this.

    5. Be patient when you upload your APK & OBB to Google. It does take several hours before it is available.
     
    Last edited: Sep 1, 2014
  11. florianpenzkofer

    florianpenzkofer

    Unity Technologies

    Joined:
    Sep 2, 2014
    Posts:
    479
    Yes, you need a downloader. Not all devices download the OBB automatically. Also in some cases the OBB can be removed from the device in which case it needs to be re-downloaded.
     
  12. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    319
    "Not all devices download the OBB automatically"

    Is there any documentation on which devices don't download automatically? Is it older versions of Android?

    "Also in some cases the OBB can be removed from the device in which case it needs to be re-downloaded." - Could you just not request the user redownload the app from the store in this case?
     
    FaberVi likes this.
  13. FaberVi

    FaberVi

    Joined:
    Nov 11, 2014
    Posts:
    146
    No other info?
     
  14. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    I'm pretty sure it's probably an older set of devices that are limited by the Play Store version or OS.

    Also, you can't just redownload a game unless you uninstall it, which would delete all data for that game.

    What info are you needing?
     
  15. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    865
    Is all this Obb downloading relevant for Unity5?
     
  16. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    319
  17. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    Yeah the nice thing is that they just upped it from 50MB to 100MB so unless your game is going a little larger than a standard single dev game, you won't even need OBB support!
     
  18. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    865
    yes we were testing spliting the app into apk and obb since its over 100Mb but testing on devices there is no downloading through intial scene but the complete app is downloaded from Google Play, so i wonder what is the relevance of obb downloader script
     
  19. mh114

    mh114

    Joined:
    Nov 17, 2013
    Posts:
    295
    It has been answered: "Yes, you need a downloader. Not all devices download the OBB automatically. Also in some cases the OBB can be removed from the device in which case it needs to be re-downloaded."
     
  20. unisip

    unisip

    Joined:
    Sep 15, 2010
    Posts:
    340
    So, looking at the Unity doc and the forums, this is still quite confusing
    - Unity says you need to handle the download using their plugin mostly for older devices and in case the OBB gets removed from the device for some reason
    - quite a few developers say you don't need to worry about it, you just make sure the OBB is renamed properly and you're good to go

    My project is only targetting recent devices running Android 4.4+, should I worry about this or just upload properly named APK and OBB to Google Play and that's it?
     
  21. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    It depends on how much risk you are willing to take.

    If you target Android 4.4 and up, I'm pretty sure that every device will auto download the OBB with the main APK initially. HOWEVER, the OBB file could still be purposefully or accidentally removed from the device, or maybe it was even only partially downloaded (something funny happened during download) and in either case, the game is unplayable. Since you have no plugin to handle checking to make sure the OBB is there, the game will be useless. The user will have to uninstall and try re-downloading the app, which will erase any save data on the device.

    So again, it's all about how much risk you are willing to make. If you are expecting to make thousands of dollars from your app and it's crucial that everything is perfect, no questions asked, I'd use the plugin. Otherwise if this is some hobby app that will get 100 downloads, don't worry about it.
     
    mh114 likes this.
  22. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    We found that on the HTC One M8 running Android 5.0.2, among others, that the OBB was not downloaded. So you definitely need to include code to check for and download the OBB.

    Also, you don't need to use the plugin, you can quite safely make your own scene in Unity that handles it, especially if you're able to host the obb yourself.
     
  23. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Hi,

    One question about the obb file :
    - the Unity downloader documentation says that it will downloaded into the SD Card - but what about devices which have no SD Card ?

    - if the device downloads the .apk and the .obb files at the same time automatically, will the .obb file be downloaded into the SD Card to ? Again, what about devices without SD Card ?

    Thanks
     
  24. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639

    The OBB download helper script has this:

    Code (CSharp):
    1. public static string GetExpansionFilePath()
    2.     {
    3.         populateOBBData();
    4.  
    5.         if (Environment.CallStatic<string>("getExternalStorageState") != Environment_MEDIA_MOUNTED)
    6.             return null;
    7.            
    8.         const string obbPath = "Android/obb";
    9.            
    10.         using (AndroidJavaObject externalStorageDirectory = Environment.CallStatic<AndroidJavaObject>("getExternalStorageDirectory"))
    11.         {
    12.             string root = externalStorageDirectory.Call<string>("getPath");
    13.             return String.Format("{0}/{1}/{2}", root, obbPath, obb_package);
    14.         }
    15.     }
    SD card really has nothing to do with anything, Android knows what it's doing.
     
  25. ppolonio

    ppolonio

    Joined:
    Jan 13, 2016
    Posts:
    2
    I've been trying to test this, but I haven't uploaded my test app to the Play Store (and don't really want to just yet). Therefore, I have no public key, and I always get a security fatal exception. Can anyone recommend a way around this, please?
     
  26. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    You get your key when you have the app store page created, doesn't have to be published.
     
  27. DanjelRicci

    DanjelRicci

    Joined:
    Mar 8, 2010
    Posts:
    310
    I'll just post here instead of opening a new thread; we too have this OBB problem with our new project, which is just that little bigger than 100mb.
    We now have our game uploaded on Google Play; after downloading and launching it, the game freezes as soon as it loads any content inside the OBB file. This happens in any publishing mode (alpha, beta, release) but with some devices only, such as Galaxy S4 and OnePlus One. What we don't understand is why the problem solves itself after rebooting the device.
    Did anyone of you discover some more on this issue?
     
  28. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    After rebooting it works every time you open the game?
     
  29. DanjelRicci

    DanjelRicci

    Joined:
    Mar 8, 2010
    Posts:
    310
    Yes, exactly.
     
  30. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    I haven't looked at these scripts for a long time, but I'm guessing maybe there's some condition where it checks to see if the OBB exists or something and it's mishandling something. Does it show any content from the OBB or just freezes when accessing it?
     
  31. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    531
    I'm so confused about this whole OBB process. Does this sum it up:

    So if have an app over 100mb, I need to rename my OBB file to main.<build version code>.<bundleid>.obb if I want it to be automatically installed with the APK. But in some cases the OBB can fail to load, user can remove it or Android is just buggy on some device and/or OS version combinations in which case a backup OBB loader is recommended. Then if you have any videos in StreamingAssets, they can't be played from an OBB file and need to be copied somewhere where they can be played unnecessarily inflating the app install size, but if the disc space runs out and the copy fails you would perhaps show an alert... or do something else.

    is that kind of what needs to happen to get an Android app releasable?! :confused::(:rolleyes::eek::mad::oops:..o_Oo_Oo_O
     
  32. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    I'm not sure about streaming assets, but yes, you want to have some code to download the OBB from Google servers in case it wasn't downloaded properly, or whatever.
     
  33. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    531
    Damn... seems like such a bizarre setup. It's such a bad user experience that users would download an app, only to find they have another monster download they need to wait for before playing. It sounds like Google realised this along the way and half way fixed this with automatic obb downloading, but why not just remove the 100mb APK limitation. Instead we've got a solution that mostly works, but can fail in many situations. Sigh.
     
  34. LAustralien

    LAustralien

    Joined:
    Apr 20, 2013
    Posts:
    11
    I have the exact same problem as DanjelRicci in that I need to reboot my Android for the game to work properly after it has been downloaded from the Google Play store (both APK and OBB files). Has anyone else had this problem and manage to solve it? Thanks
     
  35. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    We had an issue where we had to navigate to another Activity in the Android app for it to recognise that the OBB exists. So we made a dummy Activity which simply exit immediately and returned back to the UnityActivity. After that the OBB worked fine without a restart.

    You simply have to account for the OBB not being there on start up and put in contingencies to download it yourself. You always need to rename the OBB to that convention (it baffles me why Unity doesn't automatically). AFAIK it's entirely up to Android / Play Store as to whether it will download the OBB automatically or not. But either way the user / other apps can delete it for whatever reason, so you should always account for it not being there.
     
    AcidArrow likes this.
  36. JustAnotherDude

    JustAnotherDude

    Joined:
    Oct 28, 2013
    Posts:
    279
    Could you elaborate on that ?

    I'm having this issue where the app downloaded from google play needs a phone restart to recognize the obb, failing to see a reason why...
     
    Last edited: Apr 24, 2017
    gencsadiku likes this.
  37. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    I don't have the code anymore but I basically created an AAR with an activity that in it's onCreate (may be remembering that method name incorrectly) it closed itself and returned to the Unity activity.
     
  38. delphinius81

    delphinius81

    Joined:
    Mar 6, 2012
    Posts:
    57
    For people that stumble on this thread due to the obb restart issue, I found this guide for creating an aar for Unity. Gonna try creating an empty activity that launches the first time the game is run / after the obb download to see if that can consistently fix this issue.
     
  39. JustAnotherDude

    JustAnotherDude

    Joined:
    Oct 28, 2013
    Posts:
    279
    Did you have any success ?

    I tried but was unable to have a fix for this issue, still marking my games as requiring read_external_storage to have them work without restart, which is very annoying.
     
  40. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    531
    Hey there... out of interest what Android OS version and device are you testing with? If Android 6 or newer does the issue only resolve after the user permits the read permission?

    There's a very similar thread going on over here that I've been adding findings to as well: https://forum.unity3d.com/threads/a...phone-has-been-restarted.465714/#post-3130969
     
  41. JustAnotherDude

    JustAnotherDude

    Joined:
    Oct 28, 2013
    Posts:
    279
    I tested on Samsung S7 with android 7 and on LG G2 D805 with android 5.0.2.

    The game only works if the user authorizes the READ_EXTERNAL_STORAGE (which I want to avoid since I don't really need access to the player private pictures ¬¬) or if he restarts...
     
  42. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    531
    Strange that Android 5 requires the permission as well.. that API level is meant to be granted read permissions by default. I've not had to use the permission for a Samsung S2 Tab running 5.0.2. I've actually got it the permission there but filtered so it only affects from Android 6 and up:

    Code (CSharp):
    1. <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:minSdkVersion="23" />
     
    JustAnotherDude likes this.
  43. GuilhermeDuarte21

    GuilhermeDuarte21

    Joined:
    Oct 29, 2016
    Posts:
    6
    Hi, so I'm in doubt about the .OBB is it really necessary to install the unity asset right? "Google Play OBB Downloader". By searching I made some devices do not download the .OBB. So the application has to check if the .OBB exists and download it. I was wondering how to set up this google asset because it asks for a Public Key and I do not know where I can get it.