Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Unity 2017.2 beta is now available for download.
    Dismiss Notice

Android Permissions and the Manifest.xml

Discussion in 'Android' started by JoshOClock, Apr 8, 2011.

  1. JoshOClock

    JoshOClock

    Joined:
    Dec 8, 2010
    Posts:
    105
    Does anyone know how the permissions in the manifest are found and used?

    I tried renaming the 'Plugins' folder in hopes that the Manifest in there wouldn't be used for my build. But somehow I think maybe Unity is searching for it or something when it's building?

    My main thought is that I want 2 'Plugins/Android' folders with different configurations for my paid and free versions. Or maybe just 1 for my free with my ad set-up in there.

    But my paid seems to have the same permission requirements of my free even though I don't have ads in it.

    Anyone have any suggestions or know how to hide that Manifest when doing certain builds?
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,596
    You will have to replace the file manually, there is no way to make such a "version used in build" seperation through automatisms commonly (there is one and thats postprocess + some configuration file that tells the postprocess which file to use and which is fed from a custom editor you wrote but thats kind of is it)
     
  3. JoshOClock

    JoshOClock

    Joined:
    Dec 8, 2010
    Posts:
    105
    It would be nice to know what exact file I need to replace though to reduce the grunt work. Like just rename folder and rename AndroidManifest.xml...?
     
    Last edited: Apr 8, 2011
  4. JoshOClock

    JoshOClock

    Joined:
    Dec 8, 2010
    Posts:
    105
    Well it doesn't look like anything I do helps. For some reason the AndroidManifest.xml that Unity is building into the StagingArea has those permissions in it. I guess maybe it's remembering them somehow from a previous build or something.

    Does anyone know where it's getting those from?

    I'm getting a few complaints about Permissions (surprise surprise)... I'd really like to offer my paid version permission free.
     
  5. ZeroStride

    ZeroStride

    Joined:
    Mar 9, 2011
    Posts:
    34
    Build your APK with Unity.

    Use apktool (http://code.google.com/p/android-apktool/) or another tool of your choosing to unpack the APK. Replace the AndroidManifest.xml with one that reflects what you want. Repack the APK. Sign it. Align it. Ship it.

    My script:
    Code (csharp):
    1. java -jar apktool/apktool.jar d Racer.apk Temp/repack_apk/
    2. cp apktool/AndroidManifest.xml Temp/repack_apk/AndroidManifest.xml
    3. cp apktool/strings.xml Temp/repack_apk/res/values/strings.xml
    4. java -jar apktool/apktool.jar b Temp/repack_apk/
    5. jarsigner -verbose -keystore apktool/my-release-key.keystore Temp/repack_apk/dist/Racer.apk alias_name
    6. zipalign -v 4 Temp/repack_apk/dist/Racer.apk Racer_Xperia.apk
     
    eekgames likes this.
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,596
    Part from the editor, the other part are likely the "base" version thats present in the unity folder itself where the rest of the player comes from.

    But you can rewrite them after building with your own content (post process build player script) to replace them with your own content.


    Permission free: a few permissions are required, otherwise it will not run at all.
    Questions is which you want to get rid of
     
  7. JoshOClock

    JoshOClock

    Joined:
    Dec 8, 2010
    Posts:
    105
    @zerostride - thanks I'll give that a try.

    @dreamora - I just tested my 1.0 version I kept handy and sure enough it has no permissions when i check it via Manage Applications on the phone. There is no 'Permissions' section at all.

    The ones that are now there are:
    READ_PHONE_STATE
    ACCESS_NETWORK_STATE
    CHECK_LICENSE

    No idea where it's getting those from... it's cached them somewhere from a build I did using the Mobclix unitypackage that's offered in the forum. But now I can't get rid of them.
     
  8. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,596
    Read phone state and check license are required
    Phone state to pause the application when the phone is phoning, sleeping etc as android does not sleep applications as iOS does

    check license is potentially required for the LVL license verification (isGenuine etc checks)

    access network state is potentially added as consequence of the network checkbox in the player settings.
     
  9. JoshOClock

    JoshOClock

    Joined:
    Dec 8, 2010
    Posts:
    105
    Strong chances you know better than me.

    I'm a bit skeptical given that I load my 1.0 app and it has no permissions listed at all in the Manage Applications area.

    Also a reviewer gave me 5 stars when I first released saying explicitly "No permissions required!" and now he's knocked it down to 4 saying "Update now requires phone state and identity? Wtf?"

    I guess I'll need to make a clean project to verify.

    EDIT: I do recall adding the isGenuine though. Maybe that's what's adding them. Could be it needs to add more than one for that. I'll have a look there. Thanks.
     
    Last edited: Apr 8, 2011
  10. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,596
    thinking about it, the network state could actually be consequence of isGeniune too because the license is verified against googles server.

    But I really don't see why anyone cuts stars to 4 for this permissions as you don't access anything user stored on it at all with these permissions, so its not like you invade the system or read data you shouldn't.
    People that worried should really not use smartphones at all as thats not a world for people such a paranoia.
    Or what I wanted to say to you with that: Don't worry about it and change the wording in the form that you express the clear statement that you access no user data.
     
    Last edited: Apr 8, 2011
  11. JoshOClock

    JoshOClock

    Joined:
    Dec 8, 2010
    Posts:
    105
    BOOM! That was it.

    It was the isGenuine.

    Thank you for walking me through that.
     
  12. JoshOClock

    JoshOClock

    Joined:
    Dec 8, 2010
    Posts:
    105
    I'm noticing that Android users are a strange paranoid bunch... they are crazy sensitive about those permissions.

    Apparently it's catching because I'm getting that way too.
     
  13. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,596
    Being sensitive about it is fine, I check them too.

    But being paranoid makes only sense if you are about it for relevant things like address book access, mail access and alike. (none the less I've whatsapp installed and many of those paranoianies too)

    But the 3 permissions here are generic ones that potentially every game has that uses Googles official license verification system.
     
  14. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    590
    The permission in the manifest is automatically added to reflect what you use in your scripts. Removing those could cause your application to malfunction in random ways.

    An empty scene will not require any permissions and therefor has a clean permission list. Adding things like Vibrate or WWW to a script will add the necessary permissions for those to function.
     
  15. Waz

    Waz

    Joined:
    May 1, 2010
    Posts:
    245
    It seems (with Unity 5.1.0f1 at least), READ_PHONE_STATE, INTERNET, and ACCESS_NETWORK_STATE are all on even for a completely empty project.

    My users have complained about READ_PHONE_STATE, and it really does look bad when suggested to users.
     
    sandbaydev likes this.
  16. MadMonkey119

    MadMonkey119

    Joined:
    Dec 20, 2013
    Posts:
    27
    I'm running into this same issue. I was priding myself on lack of permissions and now I have to slam my users with these three?!
     
    sandbaydev likes this.
  17. andiB

    andiB

    Joined:
    Jan 13, 2013
    Posts:
    17
    Me too :-( Could be related to the new Network-Components they introduced in 5.1.
     
  18. mark71

    mark71

    Joined:
    Jun 14, 2015
    Posts:
    41
    I didn't notice this post and created another thread about the READ_PHONE_STATE permission that is added by Unity 5.1.
    I want to know why Unity 5.1 needs this permission,
    My apps are child directed, I need a good answer for my users because this will lead to bad ratings and questions,

    Unity .. Is this a bug? What can we do to remove this permission? Where can we find info on this change? It is not mentioned in the Unity 5.1 release notes.
     
  19. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    1,887
    Yeah just discovered the phone state permission today. That is a bummer and I'd like to see that fixed in a future version unless the components using it are actually used! I wonder if the networking needs it to know when to break off connections and such during some kind of interruption from a call or something...
     
  20. bart_bender

    bart_bender

    Joined:
    Mar 21, 2015
    Posts:
    20
    I have the same doubts about these permissions.
    some support expert could give a response about that?
     
  21. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    1,887
    It must be something unity is sticking in there when it compiles the manifest(s) files from your project with the ones that it uses internally (like ones that need networking for the new uNet stuff) and it hasn't been setup yet to NOT add the permission even if the user doesn't actually use networking. At least that's my most educated guess haha.
     
  22. MadMonkey119

    MadMonkey119

    Joined:
    Dec 20, 2013
    Posts:
    27
    You can get around these permissions by building as an 'Android Project" then importing the project into Android Studio. From there you can edit the AndroidManifest.xml and build the actual APK. Hopefully this will get fixed or at least we get a response on it soon.
     
    MD_Reptile likes this.
  23. meapps

    meapps

    Joined:
    May 21, 2013
    Posts:
    167
    You can decode the apk and change the manifest and build it and sign it and zip it again.
     
  24. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    1,887
    Does that preserve the existing keystore? You know for apps which are already uploaded to play...
     
  25. sandbaydev

    sandbaydev

    Joined:
    Aug 9, 2013
    Posts:
    39
    As a newbie, any good & simple & fast tools to do that. Links? (Win 7)
     
  26. meapps

    meapps

    Joined:
    May 21, 2013
    Posts:
    167
    No you need to sign it again and zipalign it with the same keystore.
     
  27. meapps

    meapps

    Joined:
    May 21, 2013
    Posts:
    167
    Decode it with Apktool and build it with it.
    Sign it with jarsigner again.
    And zip it with zipalign...
     
    sandbaydev likes this.
  28. sandbaydev

    sandbaydev

    Joined:
    Aug 9, 2013
    Posts:
    39
    Thanks. Will give it a go.
     
  29. meapps

    meapps

    Joined:
    May 21, 2013
    Posts:
    167
  30. jeremiasz

    jeremiasz

    Joined:
    Feb 17, 2013
    Posts:
    52
    Forget unziping, decoding, zipping and other weird stuff done to the apk files. I've just found some workaround for the manifest permission problem.

    1. Build an .apk file as always. Don't worry about manifest file.

    2. Deploy the app to the android device.

    3. Download permission manager from Google Play store. In my case this was Advanced Permission Manager. Free version will do good. You don't have to root the device.

    4. Remove permissions from apk fie and push th Save and Install button.

    5. Voila! You have New.apk file in PermMaster folder on the device - this is your apk file without unwanted permissions.
     
  31. Flarup

    Flarup

    Joined:
    Jan 7, 2010
    Posts:
    42
    Thank you VERY much for your script. I got the script working and got the unwanted permission removed. Unfortunately, the new apk file is unfortunately much larger than the original apk from Unity (size went from 75mb to 152mb). And an odd thing is, if I decode the new apk, then the full size of the folder is identical to the full size of the folder for the original apk.

    Do you know how to get the apk file size to be the same as the file size of the original apk?

    Thanks a lot in advance.
     
  32. meapps

    meapps

    Joined:
    May 21, 2013
    Posts:
    167
    @Flarup`
    have you zipalign apk too?
     
  33. Flarup

    Flarup

    Joined:
    Jan 7, 2010
    Posts:
    42
    Yes, I have zipaligned the apk too. And the apk size before zipalign and after zipalign are almost identical. I have even tried the "-z" option in the latest version of zipalign, and that only made it a little bit smaller.
     
  34. diegopandrade

    diegopandrade

    Joined:
    Sep 14, 2013
    Posts:
    1
    In the documentation (https://docs.unity3d.com/540/Documentation/Manual/android-BuildProcess.html):

    Permissions automatically added to the build manifest
    Unity automatically adds certain permissions to the manifest. The logic is defined in the file PlatformDependent/AndroidPlayer/Editor/Managed/PostProcessor/Tasks/GenerateManifest.cs :: SetPermissionAttributes. For example, if your script code references Application.internetReachability, Unity automatically adds android.permission.ACCESS_NETWORK_STATE to the manifest. You can edit GenerateManifest.cs to remove it.

    But where is the GenerateManifest.cs file?
     
  35. Krstn

    Krstn

    Joined:
    Dec 30, 2012
    Posts:
    4
    I have the exact same question. The docs are terrible in that matter. They specify a path and nothing else. The path does not exists anywhere on my system. ehh
     
    Qbit86 likes this.
  36. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    271
    Please let me know if you find a way to edit GenerateManifest.cs.