Search Unity

APK with expansion file (OBB) fails to load the second scene until the phone has been restarted

Discussion in 'Editor & General Support' started by Playneer, Apr 11, 2017.

  1. Playneer

    Playneer

    Joined:
    Oct 30, 2016
    Posts:
    3
    I suppose the title says it all. Even with the latest Unity version 5.6, loading the second scene fails on a freshly installed game when it has been split (Play Store Alpha release). Everything works OK after the phone is restarted. One of the devices that we're seeing this issue is LG G4.

    This would suggest that Unity still has some issues with detecting the OBB file? Some of the old threads suggested that this could be "solved" by firing up a new dummy activity and exiting it immediately, after which the original UnityActivity is returned (https://forum.unity3d.com/threads/h...ogle-play-obb-downloader.239456/#post-2868678). While this might do the trick, I would rather get this solved by some proper solution.

    I've checked that the OBB file is properly downloaded from the Play Store and it's placed under the filesystem path /android/obb/*packageName*. The file edited time-stamp doesn't seem to be updated upon the phone restart, so I'm not sure what makes it work after the phone restart.

    Any ideas?
     
  2. mpgholden

    mpgholden

    Joined:
    Aug 21, 2014
    Posts:
    16
    I'm seeing a behavior where it loads super slow - upwards of 100 seconds - but it does eventually load. It's just as slow after a restart for us, unfortunately, so maybe a different issue.

    It loads with times comparable to what we were seeing in Unity 5.4 if we don't split the APK.
     
  3. dtaralla

    dtaralla

    Joined:
    Jan 1, 2016
    Posts:
    16
    I would be really interested too by a proper solution. Can't find any "real" documentation about proper obb download/install/use, that's a shame...
     
  4. i9mobile

    i9mobile

    Joined:
    Aug 8, 2013
    Posts:
    28
    same problem here, fist time it occurs... I haven't tryed build on Unity 5.4 but it worked a few months ago.
     
  5. gencsadiku

    gencsadiku

    Joined:
    Feb 4, 2017
    Posts:
    5
    I have the same problem, in some devices works but others not!!!
     
  6. dtaralla

    dtaralla

    Joined:
    Jan 1, 2016
    Posts:
    16
    This is how we finally managed to fix it.

    According to Android doc, Since Android SdkVersion 19, developers are not required to ask the permission "WRITE_EXTERNAL_STORAGE" to access obb files on Android. Thus, Unity by default adds the following in its XML manifest file for android builds:
    However, since Android 6.0, a regression (bug) appeared and Android apps now requires again the "WRITE_EXTERNAL_STORAGE" permission if they use obb files (source, that was very difficult to find...). Unity did not patch this as this is more of an undocumented android bug, but there we are... Now, the fix that made the trick for us is the following: in your custom Assets/Plugins/Android/AndroidManifest.xml, make sure you require WRITE_EXTERNAL_STORAGE permission on all versions of android and not up to maxSdk 18:
    It's almost unbelievable how difficult it was to find the reason behind the obb bug. Hope this helps others! Please spread the word :)
     
    Yury-Habets likes this.
  7. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,067
    @dtaralla does it happen locally or when installing from Google Play?
    Could you check if having READ_EXTERNAL_STORAGE without the maxsdkversion fixes stuff for you? I'm thinking of bringing it back when OBB is enabled.
     
  8. dtaralla

    dtaralla

    Joined:
    Jan 1, 2016
    Posts:
    16
    Hello @Yuri-Habets !
    When I tried, it was only the WRITE_EXTERNAL_STORAGE permission that I required without maxSdk, READ_EXTERNAL_STORAGE without maxSdk did not make any difference (by its own or with WRITE_EXTERNAL_STORAGE). It's a pain enough to ask for its users to be able to write to their files (even if we don't), so we did not want to add a "needs also to be able to READ" while this was not actually doing anything regarding the bug.

    Note that the bug happened when installing through Google Play store (on an alpha/beta track). It was 100% reproductible, and the "fix" fixes 100% of these occurences :)
     
    lindsaytalbot likes this.
  9. lindsaytalbot

    lindsaytalbot

    Joined:
    Sep 11, 2015
    Posts:
    27
    I've lost three days to this bug. We're suppressing our prompts with
    <meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="true"/>
    and then showing a nicer prompt before it later.

    Building a test now with that line removed
     
  10. delphinius81

    delphinius81

    Joined:
    Mar 6, 2012
    Posts:
    55
    I have both WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE enabled in the manifest for all sdk versions, but still have the "restart" required bug. Using Unity 5.6.1p1 and deploying to a Samsung Galaxy S6 running some variant of Android 6.x. I see this both when doing a build & run from Unity, as well as when pulling from the Play store through the alpha channel. Problem is also exists when manually deleting the obb file and having the obb downloader run.
     
  11. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    269
    I don't think this is a correct assumption. There's plenty of developers saying that this problem still occurs whether the WRITE permission is there or not. It would make sense that it could affect and fix Android 4/5 but not for 6/7. As pointed out here: https://github.com/danikula/Google-Play-Expansion-File/issues/7 Having the permission in the manifest for Android 6/7 doesn't mean anything until you request for it and the user grants the permission, unlike the forced permission requests that happen on start up on Android 4/5, wouldn't Android 6 need the permission set before the app starts, which isn't possible?! So I'm not sure that Android 6/7 would be better off at all. Apparently the only way to fix the issue is restart the device so that the installed OBB file has the correct user account associated with the file, which on Android 6 is set to root user for some horrible reason. Most of this is discussed in the same source link you provided: https://issuetracker.google.com/issues/37075181 - this whole situation seems to be the worst OS bug I've ever seen.

    So far the best solution I can come up with is to try and capture a crash when accessing the OBB file and present a popup asking the user to restart their device :(
     
  12. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    269
    According to these guys they do a workaround where they download the obb file to a private directory for devices running api level >= 23 that doesn't require write permissions. But it means the obb file will be there twice, the first time as the auto-installed file that you can't access due to the wrong user file access issue (until a restart). I'm unclear how you would then let Unity know to use this second obb file instead thats added to the private folder instead.. and it appears even their method isnt bullet proof. Oh man... there's no good options.

    https://issuetracker.google.com/issues/37075181#comment12
     
  13. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,067
    We will be adding READ_EXTERNAL_STORAGE permission when OBB is enabled. Based on the tests, it allows to use the OBB even before the phone restart. If you have opposite experience - please share!
     
  14. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    269
    That's interesting.. in your tests does that mean you've seen results where just by having the read permission present in the manifest file even if you haven't asked the user to confirm the permission in a request popup on Android 6 (or newer), that it will allow the OBB to install with the correct user access bug occurring?

    I've also been wondering if it would be possible to set a min sdk of 23 for the read/write permissions like:
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:minSdkVersion="23" /> in order to avoid pestering Android 4/5 users with the permission request on first launch, or have you found that this obb user access bug can affect older api levels as well?

    Thanks so much, this issues is complex and variations on behaviour are so hard to get a handle on.
     
    Last edited: Jul 3, 2017
  15. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,067
    Of course it assumes the permission is granted in the very early stages of initialization - like where Unity asks for permissions on startup. Having it in the manifest means nothing on modern Androids :)

    Re minSdkVersion on permission tag - the permission dialog and the runtime permission system was introduced in Android 6 (API 23) so there's little reason to dump the permissions on earlier Androids - where it's only requested during installation process.
     
  16. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    269
    Yes but the major problem as far as I understand it is when the OBB file is auto-installed when the APK is installed, the OBB file is incorrectly assigned the 'root' user as of Android 6 / API 23 and causes a read access exception. It means that OBB file is installed before the app gets to run at all and I agree that on modern setups the manifest means nothing until the permission is granted by the user. So I'm wondering how it's even possible that adding a read permission could make any difference to Android 6.. unless it is making a difference to the auto-install process.. OR.. after granting the read permissions does this 'refresh' all of the files and change the incorrect 'root' user to what it should be? Having read/write permissions asked early on in the installation process would help for situations where you're using a backup OBB loader for cases where the OBB file did not install or has been removed manually off the sdcard by the user. But I'm failing to see how the read permission will help with the major auto-install root user issue.

    Yea I'm hoping this is the case, where the root user issue doesn't affect API levels 19 to 22, because these API levels do not need the read/write permissions to be set directly, they're granted by default.
     
  17. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,067
    I did not investigate the owners, but my assumptions are that:
    - starting from API 19, no special permissions are needed to read your own files
    - it probably implies that the owner of these files is set to your app's user
    - in android 6, a bug in the installation process does not set the owner correctly and sets it to root
    - with READ_EXTERNAL_STORAGE, you can read the files with root owner.

    So the permission is added only to workaround the bug in the installer which is affecting your phone before restart.
     
  18. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    269
    I've just done a test using an Android S5 running Android 6.0.1. I added these two permissions:
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:minSdkVersion="23" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:minSdkVersion="23" />

    I was able to install the APK and OBB files manually and locally with the correct user, the app starts up fine. Then I've uploaded these to the alpha channel on the play store and installed via a white listed testing user account. The installation automatically installs the OBB file but clearly still owned by the root user:
    drwxrwx--x root sdcard_rw 2017-07-03 20:28 co.yakand.test

    The app of course starts up with a black screen as it can't read the obb file. So this at least proves that simply by having the permissions in the manifest is not enough to negate the bug. I didn't expect it would, but had to test anyway.

    I'll report back when I have some permissions requests popups appearing to see if this refreshes the user ownership to the correct user.
     
  19. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    269
    Also by the way. I installed the same build on a Samsung S2 Tab running Android 5, and it seems that the filtering I've added to set android:minSdkVersion="23" is working. The play store still falsely prompts the user to say that 'access to media/storage' will be required while viewing the store. But when the app is actually installed and launched, the user is not hit with any of the old standard permission request popups, the obb file works and the app starts up correctly.
     
  20. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,067
    We will be double checking it by publishing to Google Play again.
     
  21. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    269
    Hey all .. so to follow up. Yes after asking for Read permission I was able to access and use the installed Obb file. Strangely I found that the Obb file user remains still set to the Root user after the permission is granted, but the app can use it. The root user is still not changed until the app is restarted. So perhaps it was never about the file being the root user or not. It doesn't really seem to matter. Although I guess for some devs they have reported that a restart and the user on the file being updated seemed to help the read access without a permission request, and then some saying the restart didn't help.. but at least the read permission seems to work in either scenario.
     
  22. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,067
    @jason_yak thanks for the update.
    It might be the combination of Android M bug making root the owner until restart, and suppressing the Unity's permission dialog on the startup. We might lack the permissions to mount the OBB on startup, and we remount it on pause-resume/restart.
     
  23. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    269
    Yea not sure. This issue does seem to be fairly wide reaching though and not just affecting Unity Android apps. I noticed that Google's documentation even acknowledges that problem if that helps at all?!

    Since Android 4.4 (API level 19), apps can read OBB expansion files without external storage permission. However, in some implementations of Android 6.0 (API level 23), you may need to declare the READ_EXTERNAL_STORAGE permission in the app manifest and ask for permission at runtime...
    https://developer.android.com/google/play/expansion-files.html#StorageLocation
     
  24. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,067
    Oh Google acknowledges the bug! :)

    However it still leaves us with this workaround for the lifecycle of Android 6 (like, forever). We'll think of adding the permission with maxSdkVersion in the manifest.
     
  25. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    269
    Yea although I'd be wary of the max value that they specify as 23. I've read that Google 'thought' that the issue was resolved as of api 24.. but plenty of people are reporting the issue on devices running Android 7 / api 24. Read to the bottom of this thread: https://issuetracker.google.com/issues/37075181

    So in my case I am actually specifying a min sdk value of 23 for the read permission so it affects from 23 up and leaves from 19 to 22 alone. If you were to add that read permission in asa enforced part of how unity builds ^ it might conflict with peoples custom declarations of that permission in their manifest files. Perhaps not.. but I've been caught out before where your compiler auto-injects entries into the manifest and would prefer to be able to have control over this myself. I think if you made it so that you don't add the entry if someone is using a custom manifest that would be best from my point of view.
     
  26. JustAnotherDude

    JustAnotherDude

    Joined:
    Oct 28, 2013
    Posts:
    159
    I'm baffled by this, how is this not affecting everyone that publishes to google play and have apks with more than 100mb ?
    Google is doing an horrible move here, it's forcing pretty much everyone to ask for such an intrusive permission just to run an 100mb+ apk ! And they don't care at all. It almost makes me put a message on the apk start that if the permission is wrong the user should reset their devices because Google can't be bothered to fix a bug on their end, and the user should switch to iPhones which are more secure...

    We usually have zero issues with publishing to ios, but damn android, everything is complicated and bugged !

    Sorry for ranting...

    It does amaze me how this issue isn't bigger, is there some secret we're missing ? Is there some way to publish +100mb games on google play that doesn't require obb ?
     
    jason_yak likes this.
  27. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,067
    @RafaelF82 there is no other way, if you publish to Google Play.
    You could use asset bundles to try to get into 100Mb.
    The issue should be isolated to Android 6 only, but now I doubt that...
     
    JustAnotherDude likes this.
  28. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,067
    @jason_yak thanks for pointing to the new google issue.
    I have no clear evidence so far that the issue happens on Android 7. If it does for you - I would appreciate the exact model and build fingerprint!

    On adding the permission - we will be checking whether the manifest already has READ_EXTERNAL_STORAGE; if it does not - add it with masSdk=23. However I will be holding this change for a while... maybe we just add it without the maxSdk, to be on the safe side.

    On the other hand, our user can easily apply a workaround by adding the permission without maxSdk or anything.
     
    JustAnotherDude likes this.
  29. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    269
    It is affecting many builds. I'm completely baffled as well. It's given our android build the worst first impression because I have to deal with long standing OS bugs. It's so frustrating to know that Google can side step these issues if they were to lift the 100mb APK delivery limit. Other android based platforms like TapTap can deliver APK's over 100mb and are completely devoid of all of these crazy issues ie. the size limit is enforced at the time of submission to Google Play. The Google Play store even has a warning message to users when an app is over 100mb, to advise them the app download is large and gives them the option to complete the download later when they're on wifi - this should be enough?! Instead all developers have to deal with all of the broken OS OBB related bugs: Android 6 read permission issues, OBB files that can go missing for various reasons or never install depending on various device OS configs so you need a backup OBB loader which then can't write the files unless you have write permissions on certain devices etc. Yup.. rant from me as well.. but all of this could be fixed overnight and would solve issues of older OS versions as well if they would lift the 100mb APK restriction.. the only other thing that using an OBB file is meant to do is that it can only be obtained when passing a license check to receive the download URL to the OBB file, but we all know that's not stopping any piracy on Google Play.
     
  30. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    269
    sounds good thanks.. and sorry I haven't been able to test on Android 7 as yet.
     
  31. JustAnotherDude

    JustAnotherDude

    Joined:
    Oct 28, 2013
    Posts:
    159
    I'm pretty sure I tested it on Samsung S7 with android 7 and the problem was there.

    Just to be 100% sure I'll try to test again, bit busy now but will try tomorrow.

    Anyway another person posted that also had that problem on android 7 on the bug report I filed in google issuetracker :
    https://issuetracker.google.com/issues/37544273

    He said :
    "Same issue for Galaxy Tab S3 with Android 7.0."


    edit: My android is definitely 7.0
     
  32. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,067
    Folks a bit of update from me.
    All Samsungs I tried had the bug (root owner, no access until restart without READ_EXTERNAL_STORAGE). Models and build fingerprints for the history:

    SGS5 samsung/kltexx/klte:6.0.1/MMB29M/G900FXXU1CPJ6:user/release-keys
    SGS5 samsung/kltexx/klte:6.0.1/MMB29M/G900FXXU1CQB3:user/release-keys
    SGS6 samsung/zerofltexx/zeroflte:7.0/NRD90M/G920FXXU5EQBG:user/test-keys
    SGS7 QCOM Verizon/heroqltevzw/heroqltevzw:6.0.1/MMB29M/G930VVRU2APG3:user/release-keys
    SGS7 Mali samsung/heroltexx/herolte:7.0/NRD90M/G930FXXU1DQD7:user/release-keys
    SGS8 QCOM samsung/dreamqltesq/dreamqltesq:7.0/NRD90M/G950USQU1AQC8:user/release-keys
    SGS8 Mali samsung/dreamltexx/dreamlte:7.0/NRD90M/G950FXXU1AQF7:user/release-keys

    It's definitely not isolated to Android 6, so we are not shipping maxSdkVersion=23 because it won't simply work on Samsungs with Android 7. We leave it with pure READ_EXTERNAL_STORAGE.
     
    JustAnotherDude likes this.
  33. i9mobile

    i9mobile

    Joined:
    Aug 8, 2013
    Posts:
    28
    I have a app recently reviewed and featured on Google Play. On the review process, here's what the Google Reviewer wrote to me:

    I. Must resolve before feature consideration:

    - The Android 6.0 (Marshmallow) release allows users to directly manage app permissions at run time. Because of this, it’s important to handle permissions properly in case a user has denied access to some or all of the required permissions. Be sure to follow the guidelines below when implementing a permission request flow:
    • If any permissions must be requested at launch, be sure to provide context to the user as to why they are being asked to allow it.
    • In the event of a user denying a permission request, avoid immediately directing the user to the app settings. Instead, educate the user as to why the app needs the permission to run and provide a way to re-trigger the request in the app. Reserve sending a user to the app settings until the app has detected that the 'Always deny' option has been selected.
    For more info:
    https://developer.android.com/about/versions/marshmallow/android-6.0.html
    https://developer.android.com/training/permissions/requesting.html
    http://developer.android.com/training/permissions/best-practices.html


    It will be a lot easier if Unity implements this guidelines to avoid user of external plugins to detect if the permission was set and manage all kinds of situation.
     
  34. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,067
  35. 265lutab

    265lutab

    Joined:
    Sep 15, 2014
    Posts:
    150
    I have added READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE and it's still not working for me. I have tried with unity 5.6.0p4, and 5.6.2p4. When I build to the phone it works fine, but when I upload it to google play and download from there I can't get to any data in the OBB until I restart the phone.
     
  36. JustAnotherDude

    JustAnotherDude

    Joined:
    Oct 28, 2013
    Posts:
    159
    Are you getting the android permission request when you run on the phone AND allowing it to run ?
     
  37. 265lutab

    265lutab

    Joined:
    Sep 15, 2014
    Posts:
    150
    I'm not getting any android permission requests
     
  38. JustAnotherDude

    JustAnotherDude

    Joined:
    Oct 28, 2013
    Posts:
    159
  39. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,067
    @265lutab your phone model, android version and the manifest would be helpful. Does it work if you just kill and restart the app?
    Are you using a plugin to override the permissions dialog in the beginning?
    The way Unity asks for the permissions (before loading the OBB) is the most compatible way.
     
  40. 265lutab

    265lutab

    Joined:
    Sep 15, 2014
    Posts:
    150
    I got it to work by changing the manifest. By default unity has
    <meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="true" />
    and I changed it to
    <meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="false" />
     
  41. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,067
    Or just remove the whole metadata tag.
     
  42. JustAnotherDude

    JustAnotherDude

    Joined:
    Oct 28, 2013
    Posts:
    159
    I just read today patch notes :
    • (none) - Android: Fixed the issue where OBB was not available after installing from Google Play on some phones until device was restarted.



      How did you guys managed to fix it ???



      Downloading it now to test.
     
  43. JustAnotherDude

    JustAnotherDude

    Joined:
    Oct 28, 2013
    Posts:
    159
    I just did a quick test and the issue was not fixed.

    Unity now "properly" asks for the read permission, but if the user denies it the game will still fail to load the obb content.

    Basically the "fix" was not helpful, we still need to force the user to give the proper permission, the way unity implemented the permission request is also not proper, google requires us to say somewhere why we are asking for the permission, the unity permission request does not show the reason.
     
  44. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,067
    The fix is to add READ_EXTERNAL_STORAGE permission. Of course, if the user denies it - OBB loading will fail.

    I've explained multiple times why we are asking for permissions at startup instead of a "dynamic" permission system. This is actually one good example when the permission must be asked as early as possible (before OBB is being loaded).

    If you want to implement a dynamic permission system, you may want a plugin, like this https://github.com/Over17/UnityAndroidPermissions .
     
  45. DaReign

    DaReign

    Joined:
    Apr 12, 2013
    Posts:
    61
    Is there available any fix for Unity 5.6.1 I used some asset store products which don't have version for unity 2017 if I switch to newer version my 6 month work I can put into trash because I will have to rewrite many things from scratch :(.

    I tried repair it on my own. I tried to add

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    and it ask me for permission when I build game in my phone through usb in unity editor, but when I publish it to Google Play and install it on phone it not ask for permission and game won't work.
    I see you posted link to plugin where it is written
    "Use Android Studio to build the AAR from the source in src/ directory."
    I completly don't know what is AAR , never used Android Studio, always worked on unity and now to fix some unity issue I have to do this in external tool :(. Well just at least please write some better instruction for less experienced user how to fix this step by step for Unity 5.6.1
     
  46. DaReign

    DaReign

    Joined:
    Apr 12, 2013
    Posts:
    61
    Maybe I misunderstood instruction but do I've to build this plugin in adroid studio before use in unity or I can just copy it to my folder and thats all ?
     
  47. JustAnotherDude

    JustAnotherDude

    Joined:
    Oct 28, 2013
    Posts:
    159
    I guess you didn't understood what I meant, the explanation I am talking about is that we have to put a message somewhere, currently we're doing it on the first scene of the build, that says to the final user, that we require permission to access his files because the expansion file needs it to read game data, this is a requirement by Google itself, if you don't do this, and only asks for the permission as unity does in it's default state (not giving the reason for the user), your game cannot be featured on the play store, because it's a Google requirement to explain why the permission is being asked.

    That's why I'm saying the current solution by unity is not proper, because :

    1 - It allows the user to deny the permission, which will make the game unplayable, the "correct"(only?) solution would be to prevent the game from continuing to load if the user denied the permission, we currently deny android users from continuing to the next scene unless he accepts the permission, there's no way around it. If the user checks the "don't ask again" checkbox, then we open the game settings window in the android so he has to manually allow it there.

    2 - As I said above, the unity permission request window doesn't explain why the permission is needed for the end user, as was said before :

     
  48. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,067
    @RafaelF82 I know the Google requirements with regard to permissions. Once again, I've explained multiple times why we don't support it out of the box.

    I've talked about this:

    Android: Fixed the issue where OBB was not available after installing from Google Play on some phones until device was restarted​

    The fix for this issue (OBB not available until phone restart) is to add READ_EXTERNAL_STORAGE permission - this is what Unity does for you now. It has nothing to do with the dynamic permission system at all.

    Also, due to the moment when we mount the OBB (before engine initialization), you have to have the permission at very early stages of the game.
     
  49. 265lutab

    265lutab

    Joined:
    Sep 15, 2014
    Posts:
    150
    What I used in 5.6.1 was changing
    <meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="true" />
    to
    <meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="false" />

    Just removing it didn't work for me because then unity puts the defalult
    "<meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="true" />"
    into the manifest when it makes the build.
     
  50. DaReign

    DaReign

    Joined:
    Apr 12, 2013
    Posts:
    61
    I think I finnally resolved this problem with plugin provided by Yury-Habets so I decided to write simple tutorial so others wouldn't have to struggle with this ;). And I hope RafaelF82 it also cover answer for your question too ;)

    1.First we have to override unity generated android manifest file and it is simple. Basically this file shows in Temp/StagingArea/AndroidManifest.xml during build , then copy this file after build to Plugins/Android. Every is covered in this video tutorial
    .
    2.Then I add 3 lines
    First in Activity tag
    <meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="true"/>
    And another two after </application> tag
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    Write permission maybe isn't necessary (you can experiment) but I add this and it is working so I left it that way.

    3.Then is this part which was hard for me when I started but now I see is simple. Download this plugin
    https://github.com/Over17/UnityAndroidPermissions
    4.Just copy Assets folder to your project Assets folder - plugin is ready to use ;)
    5.In my project in first scene in Start() I added

    CheckPermission();

    And the function is
    public void CheckPermission()
    {
    if (!GetComponent<MyPermissionCheck>().CheckPermissions())
    {
    Permisssion.SetActive(true);
    }
    else
    {
    //this else part isn't necessary
    print("permission granted");
    }
    }


    MyPermissionCheck is just this example file https://github.com/Over17/UnityAndr...ets/Scripts/AndroidPermissionsUsageExample.cs
    renamed by me , plus my few changes. And how it works
    This function check obviously if the permission is granted GetComponent<MyPermissionCheck>().CheckPermissions()
    This function CheckPermissions() in MyPermissionCheck

    public void OnGrantButtonPress()
    {
    AndroidPermissionsManager.RequestPermission(new[] { STORAGE_PERMISSION }, new AndroidPermissionCallback(
    grantedPermission =>
    {
    GetComponent<MainMenu>().Permisssion.SetActive(false);
    },
    deniedPermission =>
    {
    GetComponent<MainMenu>().Permisssion.SetActive(false);
    GetComponent<MainMenu>().PermisssionDenied.SetActive(true);
    }));
    }

    And this are my UI panels for Permission In Permission Denied,
    unityforum1.jpg unityforum2.jpg


    For Quit buttons I just add Application.Exit() function for Yes Button
    I connect in unity Editor (In Button Script On clik section) this OnGrantButtonPress().

    So when first scene starts, the star funtion in my main obejct (where scripts are attached) firing this CheckPermission() if permission are granted
    just do nothing and move on if not then Permission panel appear and Uuser decide (he get info why permissions is needed) If he click Quit then application Quit
    if he click Yes then OnGrantButtonPress() and Android Dialog show up when user can click allow or deny. If click allow then Permission palog is hidden
    and game move on if clicks deny then PermissionDenied panel shows up whit info that without this permission user can't play + button to Quit application.

    So RafaelF82 you can fire CheckPermission() function on start application or when you need this additional permissions.
    You can check in my application how It works
    https://play.google.com/store/apps/details?id=com.GrandDesign.TotalChaosRacing&pli=1

    I hope it will help others so they don't have spend many hours like I to solve this.