Search Unity

Unity Bug Fix - Problem (Android 6) - Urgent

Discussion in 'Android' started by MrEsquire, Nov 13, 2015.

  1. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Hi,

    So I downloaded the latest 4.6.9p2 release to take advantage of a few iOS fixes as always
    (Don't expect much from Android)

    Changes
    • Android: Android 6.0 - Limit targetSdk to 22 because of permission handling issues for Marshmallow (case 739831, 732504).

    So now I need to update my application on the Google Play store with a bug fix for customers, this is the error I get:

    This configuration cannot be published for the following reason(s):

    • It is forbidden to downgrade devices which previously used M permissions (target SDK 23 and above) to APKs which use old style permissions (target SDK 22 and below). This occurs in the change from version 21 (target SDK 23) to version 23 (target SDK 22).

    So how does Unity plan to help with this issue and existing customers who wish to update Apps?
    This fix is not ideal, please developer respond.

    EDIT: As I thought downgrading to 4.6.9 fixed the issue, but I wish for proper solution as there are Android 6 bugs within 4.6.9 and you still need support 4.6.9 for another month!
     
    Last edited: Nov 13, 2015
  2. GuillaumeZAHRA

    GuillaumeZAHRA

    Joined:
    Jan 5, 2013
    Posts:
    53
    Juste released our game and...Using targetSdkVersion 23...Just great...Watching for some informations from Unity and/or Google on this point...
     
  3. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    I think the issue is not for new releases as this be okay, just if someone has a existing release and then they upgrade there App in the future, this problem I had...I definitely looking for some kind of explanation to this..
     
    paradizIsCool likes this.
  4. GuillaumeZAHRA

    GuillaumeZAHRA

    Joined:
    Jan 5, 2013
    Posts:
    53
    Humm, you may be right but i can't be sure if everything is managed correctly "by default" if the fresh installation is on target 23 SDK.

    Or maybe i have misunderstood something. I completely understand your point of view, correct me if i'm right, but you are concerned about user, using a previous version of the app with targetSDK 22 and then upgrading to targetSDK 23, which has a complete different system of permission.

    But even for fresh install on targetSDK 23, is everything about the permissions, managed correctly "by the time" of use ? Does Unity need to implement something to "Ask acccess" to a permission to the user, as it may have revoked a previous granted permission by denying it explicitly or just by not using the application, as i have read that there is a sort of process like this now.

    I want to avoid problems of users like "Ho my save game just disappear!" because internally the system revoked the "WRITE EXTERNAL STORAGE PERMISSION", and that Unity may not have managed to Re-ASK for this permission.

    Of course theses changes only affect Android 6.0 but...I think that "Something must be done" about it, and maybe on Unity side, but i can't be sure.
     
    MrEsquire likes this.
  5. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530
    Most likely Unity 4.6 will never support Android M as the target version, the changes needed to make it fully M target compatible are just too many to be introduced this late in the life cycle. It is as far as we know still compatible with Android M as long as you keep targetSDKVersion below 23 - this is why we capped the SDK version by default.

    If you really need to target Android M and the only incompatibility you see is with runtime permissions, then what you can do is write a plugin that takes care of the runtime permissions on startup. Basically on startup you make sure to ask for any dangerous permissions listed in the AndroidManifest and then you bump targetSDKVersion to 23.

    If I have time later maybe I can compile a small code sample for you.
     
  6. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530
  7. GuillaumeZAHRA

    GuillaumeZAHRA

    Joined:
    Jan 5, 2013
    Posts:
    53
    As our game has been released with targetSDKVersion 23, using Unity 4.6.9p1, i think we don't have many choice for Android 6.0, as we can't re-upload an new Build with a lower SDK, isn't it ?

    However, i will take a look and test on your code, if we can manage the worst scenarios with this.
     
    Last edited: Nov 15, 2015
  8. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    I think I understand, Just so we are clear, on Unity 4.6.9 final release I have set my game to Minimum API level 15, reason for this was so I can target more devices and customers.

    Now when I load the same project in Unity 4.6.9p2 not changing anything but fixing a bug for the game, I get the error from Google play. So you telling me this expected?

    If I target SDK23 minim API, then I lose hell lot customers, or I got this completely wrong and noob mistake?
     
  9. GuillaumeZAHRA

    GuillaumeZAHRA

    Joined:
    Jan 5, 2013
    Posts:
    53
    Correct me if i'm wrong, but you will never have any problem if your customer is on previous Android version, as older API Level will be used internally. You may just have some issue on Marshmallow (Android 6.0 / API Level 23) if you use some critical permissions that can be disabled by the user or by time inactivity (not totally sure about this).

    The good thing in my opinion is:

    - set minimum SDK as low as you can: On my project its "API Level 9" actually.
    - set targetSDK to the newest, as you have already published your game on "API Level 23".
    - Add the Java code that check permissions for Android 6.0. It only have to be checked on this SDK level, because older SDK grant permissions always at install time, and permissions cannot be revoked manually.

    Actually, i'm developping a Unity Plugin thanks to Bitter code snippet, that check and ask permissions if required, and call a success callback or fail callback in C#, this way you can manage Android 6.0 (Marshmallow) behavior the way you prefer. Older SDK version will so always return success.

    I plan to set the plugin compatible from API Level 9 minimum (Android 2.3.1), thanks to the Android Support V4 Library, and i will share it as a free asset.
     
    MrEsquire and bitter like this.
  10. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Thanks for the detailed reply, where do I set the targetSDK, so somehow between 4.6.9 and 4.6.9p2 Unity changes the settings for this?
     
  11. GuillaumeZAHRA

    GuillaumeZAHRA

    Joined:
    Jan 5, 2013
    Posts:
    53
    You can't change it by the Unity Editor GUI (but you can change the Minimum via the GUI). I always set targetSDK with the AndroidManifest.xml file from my Unity Project.

    But in my opinion, there is no need to go on Unity 4.6.9p2 if you only target Android.
    From my own side, i have Unity 4.6.9p1 for Android, and Unity 4.6.9p2 on my Mac Mini for iOS.

    However, 4.6.9p1 or 4.6.9p2, the problem is still the same, if you have send on Google Play a targetSDK 23, you will have to manage theses possible dynamic permissions for Android.

    Still working on my plugin, cause i have some issue.
     
    Last edited: Nov 16, 2015
  12. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    I understand, but im just getting confused i have not changed anything between the 4.6.9
    Build and the patch 2 build.. So why has google play thrown this error to me - so its something Unity is doing.. Maybe im not getting something.hence my first posting.. I think there two things being discussed in the thread..
     
  13. GuillaumeZAHRA

    GuillaumeZAHRA

    Joined:
    Jan 5, 2013
    Posts:
    53
    Yes maybe Unity is capping the targetSDK. To be sure, after any APK build, you can go to Temp/StagingArea folder and look what is the targetSDK setted in the final AndroidManifest.xml...Or if you want to be 100% sure, take a look at the metadata of your apk file with aapt -d badging "yourapk.apk" .
     
  14. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Perfect, thank you, will do some further tests tommorow and compare the .apks created in the different versions of Unity..
     
  15. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530
    Yes, if you don't explicitly set targetSDKVersion Unity will cap it to 22.
     
  16. GuillaumeZAHRA

    GuillaumeZAHRA

    Joined:
    Jan 5, 2013
    Posts:
    53
    Still working on my plugin. It seem that something go wrong, and it seem that the "catch" code is called, however, its very difficult to debug a Android Module from Unity as you can't!

    So i will try to test the module behavior with a real Android Test App with Android Studio...So i still have to do some test...
     
  17. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530
    FYI, we are currently discussing putting a version of this code in Unity 4. However, I can't make any promises since it will require some non-trivial changes to the life cycle.
     
  18. GuillaumeZAHRA

    GuillaumeZAHRA

    Joined:
    Jan 5, 2013
    Posts:
    53
    In wich form do you think this will be managed on Unity 4 ? Automatically at app start, or will i need to register a callback in the App to take my own decision of "What to do then" if permission granted or not ?
     
  19. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530
    The plan is to automatically ask for all permissions on startup.
     
  20. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Ah I see, for some reason was not aware of this..Think the minimum API confused me with target SDK. In this case I think I be able solve my issues : Cheers for all the feedback.
     
  21. paradizIsCool

    paradizIsCool

    Joined:
    Jul 10, 2014
    Posts:
    178
    Hi,

    I'm facing exactly same issue as MrEsquire.
    Do you have any update about this case ?
    Does the sample code provide by bitter a right way to target sdk 23 with p2 ?
    I really need to make en update relatively quickly.

    Thanks
     
  22. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530
    Hi,

    I wanted to let you know I pushed a patch for this into 4.6 this weekend so hopefully it will be part of the next patch release. Which should be imminent.
     
  23. paradizIsCool

    paradizIsCool

    Joined:
    Jul 10, 2014
    Posts:
    178
    Nice !
     
  24. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530
    I will also apply a similar patch to Unity 5.2 and 5.3
     
  25. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,746
    I see in the newest 4.6.9 patch release that:

    "Android: Added support for Marshmallow runtime permissions."

    How does that work? Do we need to do anything? Are there docs?

    Or does the new patch release now auto build to target 23 and it auto asks permissions?
     
  26. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530
    Yes, assuming your SDK has API-23 platform installed.
     
    AcidArrow likes this.
  27. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,746
    Good to know, thanks!
     
  28. Playrion

    Playrion

    Joined:
    Sep 12, 2014
    Posts:
    4
    What is happening if the user dismiss the authorization or disable it in the settings.
    For exemple, we are using SQLite, and writing the file in the SDCard, but if the user doesn't accept to let us use his SDCard, how can we know if it's authorized or not?
     
    AcidArrow likes this.
  29. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    I do see a change in permissions( testing on Nexus 9 Android 6), but its abit worrying, the first thing the users sees a popup:
    Game would like to manage your phone calls, deny or accept
    then Game would like to manage your media/photos, deny or accept.

    Not sure whats going on here and if this is expected behavior as the game has nothing to do with phone and media?
     
  30. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    And here we come back to permissions.... :)

    Here is how Google interprets their own permissions.

    The "phone calls" looks like READ_PHONE_STATE, we force that if you are accessing deviceUniqueIdentifier, or it can come from a plugin.
    The "Manage your media/photos" looke like WRITE_EXTERNAL_STORAGE, we add it if you force write access to SD card in the Player settings, or it can some from a plugin.

    There has been much discussion with regards to permissions in 5.1, but I think we fixed these. Can't remember the status in 4.6 - sorry - I rarely deal with it.

    So, as a bottom line - Android M exposed your permissions to the user once again. You need to check your required permissions, determine where they come from (could be a plugin) and decide what to do.
     
  31. Playrion

    Playrion

    Joined:
    Sep 12, 2014
    Posts:
    4
    I think MrEsquire is saying that it asks for all the permissions at once. Maybe it could ask for the permission only when it needs it. We got a Nexus 6P yesterday and it asks for the permissions only when it needs it. Would it be possible to do that?
     
  32. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    Async permission request may be implemented. At the moment, IIRC, there are some issues with the callback mechanism that makes it unusable with Unity - @bitter has more details.

    However, the chances this potential fix will get into 4.6 are very slim.
     
  33. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,746
    Would WRITE_EXTERNAL_STORAGE be asked for permission from the user if install location is set to "automatic" in the player settings? (in Unity 4.6.9p3) (After all automatic does mean "sometimes to the external")

    We did a test, and our app asks for access to Photos/Media etc, which we don't think we need. Is there any way for the permissions prompt to not appear?

    (does the OBB downloader need it? our app is pretty big and is split to apk+obb)
     
  34. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    I understand this but when the user downloads the app and uses it fist time he gets a default google permissions popup. This new one is not same and two promps appear. Imagine the shock when users starts game and it says the game wants to manage your phone calls! Huum I still think few things need bit tweaking..please check 4.6 before it dies out.
     
    elias_t and AcidArrow like this.
  35. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,746
    For those of us that are stuck* with 4.6.x for our mobile projects for quite a bit more time, leaving 4.6 in a state where things that are out NOW don't work properly is really not ok.

    *personally we could be unstuck if enlighten was on par with beast as far as baked lightmaps go. But it has a long way to go. I'm not sure even 5.4 will do it.
     
    MrEsquire and elias_t like this.
  36. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    In the end I reverted to 4.6.9 final again, I appreciate the developer making a hack for this issue and it does work.
    It just not professional solution and its a horrible user experience and knowing Android users paranoid and confused.
     
  37. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    @AcidArrow :
    "Automatic" does not force SD card permission. Enabling OBB - does.
     
    AcidArrow likes this.
  38. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    One more thing: we ask for all the permissions on startup to ensure all plugins are working correctly. Asynchronous request can be missed by the plugin having its own activity.
     
  39. noname77

    noname77

    Joined:
    Oct 6, 2015
    Posts:
    9
    Hi @bitter,

    Any update or timeline on implementing runtime permissions for Marshmallow in 5.2 / 5.3?
    I couldn't find any info on that outside of this thread and I am wondering if it's better to wait or should I dive into writing my own plugin (which obviously I'd rather not).

    Thanks,
    nnm
     
  40. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    @noname77: I'll answer for @bitter

    Requesting dangerous permissions should be in the following versions:
    5.3.0f3 and later
    5.2.4 FINAL.
     
  41. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    There are a few more things going into latest patch releases, including 4.7 FINAL:
    - fix for the black screen when there's a custom permission without proper declaration
    - feature to disable the Unity permission dialog at all, through a special metadata field in the manifest, if you want to implement it on your own. Beware: if you silence the Unity dialog and don't implement your own, you'll end up with all dangerous permissions denied.
     
  42. protostarDean

    protostarDean

    Joined:
    Jun 26, 2014
    Posts:
    7
    It's great to know that it exists, but could you tell us more about this special metadata field?

    Having the permission request popping up right at the start with no explanation is really not a great solution. I can't imagine anyone saying yes to that prompt...
     
  43. TrihedronNate

    TrihedronNate

    Joined:
    Jul 2, 2012
    Posts:
    2
    I'm seeing a problem with an app built with 4.6.9f1 (before the permissions patches) and 6.0 when installed via the Google Play Store.

    Manual installation of the .apk and .obb works, but Store download, access to the .obb fails. Amusingly if I then nuke the obb directory and recreate it, and reinstall the .obb it works fine.

    It *sounds* like this might be a WRITE_EXTERNAL_STORAGE permission issue, which is still in the manifest for that build. I force-strip it postprocess it in a current build and all seems well on manual installation (but haven't tested Google Play install), which is what I expected since the app only accesses data/obb directories for its own bundle identifier.

    But, that makes me wonder:

    * Does Unity actually *need* WRITE_EXTERNAL_STORAGE permissions on 6.0 to be able to access the .obb? It seems like it shouldn't.

    The publisher wants WRITE_EXTERNAL_STORAGE requirement to go away, which makes sense. They also want targetSdk to be 23 (6.0), which also makes sense. But I can't tell if I should try testing a build without WRITE_EXTERNAL_STORAGE specified via Google Play installation on 6.0, or if I need it to be put back and republish with 4.7 so it will request the permission...
     
  44. Svirsky

    Svirsky

    Joined:
    Sep 16, 2015
    Posts:
    5
    What is the "special" metadata property in the manifest to disable the auto permissions dialogue?
     
  45. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    Yes.
    We need this permission to be able to download the obb. (maybe for something else, but this is what immediately comes to mind).
     
  46. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    Code (XML):
    1. <meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="true" />
    Add this to activity or application tag in the manifest.
     
    MrEsquire likes this.
  47. sekari

    sekari

    Joined:
    Jan 13, 2015
    Posts:
    27
    Hi Yury,

    I have couple of questions:

    1) Can we rely on SkipPermissionsDialog meta-data for future use or is this some kind of a temporary solution?
    2) Unity asks dangerous permission at start on black screen, when this issue will be resolved?
    3) Are you guys planning to introduce a runtime permission management system where we can query current allowed/denied permissions?

    Thank you in advance
     
  48. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Does this happen with SkipPermissionDisalog enabled?

    Now that 4.7 is officially out and no more support for 4x, I'm worried we are left with a ugly permissions issue for Android 6 devices. My main problem is I have a nice game finished in 4.6 series and updating to Unity 5 is not a possibility as it involve much work and lots of redesign (Although for all new projects moved onto Unity 5.3).

    Technically the last 4.6 patch was may I say a JOKE.. I know you guys don't wish to work on old stuff anymore, but really you left Android in a unfinished state, should have checked with Unity QA for existing graphic related problems and android related issues before discounting the support. (Oh yeh forgot Unity QA disappeared).

    Cheers
     
  49. sekari

    sekari

    Joined:
    Jan 13, 2015
    Posts:
    27
    Nope. SkipPermissionsDialog meta-tag works as expected. However I feel too uncomfortable due to lack of documentation about current state of permissions issue on Unity 4.7. It is definitely not resolved.

    By the way I have discovered a horrifying truth last night, you may want to hear that. Assume you are building your application with Android API 23 and you have external storage permission (WRITE_EXTERNAL) defined in your manifest file. An Android 5 device installs your app (accepts all permissions on install) from store without any problem. When that device updates its OS to Android 6, the storage permission gets automatically revoked from the user by the OS! First I thought this was a bug about SkipPermissionsDialog, however I have realized that all other applications built with API 23 experience this situation. Please be aware.
     
    bluescrn and MrEsquire like this.
  50. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Thank you for the feedback, much appreciated.
    I understand how you feel, because there been so many threads and postings that the whole issue is some what been confused into multiple issue. I thank Unity for the SkipPermission fix as this was needed for sure.

    I think these issues where not raised before but with Android 6 coming out more people started seeing problems with permissions. I like to be a fair person, but honestly Unity had heads up, there number of threads where I ask if Unity will support new Android and the response was nothing. Hence I knew from day one there would be issues.

    Think with the release of 5.3 its a wake up call.