Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feature Request A way to stop unity for adding unwanted permissions when building for android

Discussion in 'VR' started by jdscogin, Dec 26, 2022.

  1. jdscogin

    jdscogin

    Joined:
    Oct 26, 2014
    Posts:
    88
    I am requesting a switch or something to tell unity when it makes the manifest, to not include the Record_Audio and Microphone permissions. When creating an Oculus Quest app, and uploading it to the Oculus App store, it lists those permissions as not needed and fails to accept it. Anytime a routine references a Microphone, or Recording, Unity automatically adds those permissions to the android manifest. I have done a lot of searching, and to remove those permissions is very hard. This would make it much easier to get a Unity app on the Oculus App store.
    Thanks
     
    honor0102 likes this.
  2. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    780
    How about removing the parts of your code referencing the microphone, or recording?
     
  3. jdscogin

    jdscogin

    Joined:
    Oct 26, 2014
    Posts:
    88
    I guess that would work, but it is not my code that includes it. It is in the Oculus code. And removing that might work, but each time Oculus is updated, it would be back. That has to be a better way. How many people create games for Oculus Quest?
     
    Shane_Michael likes this.
  4. jdscogin

    jdscogin

    Joined:
    Oct 26, 2014
    Posts:
    88
    Watch this video and you can see how hard it is to do.



    There really should be a better way!
     
  5. jdscogin

    jdscogin

    Joined:
    Oct 26, 2014
    Posts:
    88
    Come on people that create Quest 2 Games. Back me up!
     
  6. jj-unity

    jj-unity

    Unity Technologies

    Joined:
    Jan 4, 2017
    Posts:
    70
    I'll look into this issue. Thanks for bringing it up! We already explicitly remove the BLUETOOTH permission in this case, but it looks like there are other permissions we need to look at as well.
     
    GameFinder likes this.
  7. jdscogin

    jdscogin

    Joined:
    Oct 26, 2014
    Posts:
    88
    Thanks so much.
     
  8. jdscogin

    jdscogin

    Joined:
    Oct 26, 2014
    Posts:
    88
    Any update?
     
  9. Niter88

    Niter88

    Joined:
    Jul 24, 2019
    Posts:
    112
    Did you know that you can use a custom AndroidManifest and other custom stuff?
     
  10. jdscogin

    jdscogin

    Joined:
    Oct 26, 2014
    Posts:
    88
    No.
     
    Niter88 likes this.
  11. Niter88

    Niter88

    Joined:
    Jul 24, 2019
    Posts:
    112
  12. Tanya_Li

    Tanya_Li

    Unity Technologies

    Joined:
    Jun 29, 2020
    Posts:
    102
    We recently had a fix related in our OpenXR XR Plugin package: Meta/Oculus builds now don't include Bluetooth permissions in Android manifest by default when using Microphone class in script code. Fix will be included in our OpenXR SDK 1.7.0 release, which will be released very soon at the beginning of March.
     
    Niter88 likes this.
  13. jdscogin

    jdscogin

    Joined:
    Oct 26, 2014
    Posts:
    88
    Will this also exclude the Microphone Permissions?
     
  14. luispuertolas

    luispuertolas

    Joined:
    Sep 26, 2017
    Posts:
    7
    Ok, so basically there "is no fix" but there is a hack. After building your program, download Apktool, decompress the APK, modify de manifest, and recompress to apk. After that, you will need to use zipalign to align the apk. Then finally, sign the apk with apksigner. zipalign and apksigner are on the unity editor instalation SDK\build-tools\30.0.3\

    I managed to publish my app yesterday with Oculus Integration 50 and Unity 2022.2.16f1.
     
  15. reddo

    reddo

    Joined:
    Jul 1, 2015
    Posts:
    39
    ohskaren likes this.
  16. jdscogin

    jdscogin

    Joined:
    Oct 26, 2014
    Posts:
    88
  17. honor0102

    honor0102

    Joined:
    Jan 30, 2019
    Posts:
    25
    long time after this question posted but still this problem may be annoying for someone!
    I had a similar problem ,one plugin was adding some unwanted permissions and found an easy way to remove them,it may work in your case too.
    A brief explaination:
    Enable the custom Android Manifest option in player settings
    Open the created android manifest file and add permissions you dont want with property of tools:node="remove" and it will override it! no decompile or any tricky method needed!
    like this:
    (add these tags before starting of application tag in manifest file)

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


    i explained it on another topic too check it out if you need

    hope it helps
     
    Last edited: Jun 10, 2023
    RageAgainstThePixel and eXntrc like this.
  18. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    983
    What condition removes this?

    So I can't get BLUETOOTH to remove with line
    Code (CSharp):
    1. <uses-permission android:name="android.permission.BLUETOOTH" tools:node="remove" />
    And yes the manifest is including tools
    Code (CSharp):
    1. xmlns:tools="http://schemas.android.com/tools"
    This is preventing publishing
     
  19. honor0102

    honor0102

    Joined:
    Jan 30, 2019
    Posts:
    25
    try this:

    <uses-permission android:name="android.permission.BLUETOOTH" tools:node="remove" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" tools:node="remove" />
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" tools:node="remove" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" tools:node="remove" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" tools:node="remove" />

    if it still didn't fix the problem,I recommend you to check your code to see which component or plugin needs Bluetooth ,if didn't find anything check manifest merger report and see what exactly is adding that permission(because hopefuly the source of it will be mentioned there) , and if that didn't help too,you may need to try the hard way,something like decompiling and editing manifest and resigning.(check this)
     
    Last edited: Jun 10, 2023
  20. unity-chris

    unity-chris

    Unity Technologies

    Joined:
    Nov 10, 2022
    Posts:
    29
  21. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    983
    Older versions of Unity allowed us to just specify what permissions we wanted (if I remember correctly). Not sure why this was removed. (current approach is over engineered).

    Also Unity's build process breaks and doesn't export AndroidManifest.xml for AndroidStudio project so I can't edit the merged manifest file. And "tools:node="remove"" doesn't work for BLUETOOTH. Logs tell me nothing useful.
    So I'm left with micro-removing code trying to figure out what is breaking Unity.

    The underlining build system in Unity for Android has been very problematic over the years for plugins, manifest etc.
    AndroidManifest settings should always be explicit. This implicit stuff just causes a nightmare of problems & waists huge amounts of time.
    Also the UnityActivity should never need to be overwritten for handling common Android events etc. You need a Java callback interface system which can be hooked for UnityActivity events that also get propagated to C# delegate events. (this has been needed since I've been using Unity 3)
     
  22. unity-chris

    unity-chris

    Unity Technologies

    Joined:
    Nov 10, 2022
    Posts:
    29
    This is a bug that's fixed in the latest version of the XR Management package (4.4.0 at time of writing).

    With the new editor API in XR Management, its easier to specify the permissions required through code. Here's the documentation on that: https://docs.unity3d.com/Packages/c...ity.XR.Management.AndroidManifest.Editor.html.

    I'm not sure if in-editor manifest settings were offered before natively, but the option to provide a custom manifest allows the best fine tuning, although more technical.
     
  23. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    983
    Problem is this ""tools:node="remove"" doesn't work for BLUETOOTH".

    Unity is already programmatically modifying even a custom AndroidManifest.xml file. (this is whats over-engineered)
    Instead we should just have requirements for specific features documented we need to enable like it was a long time ago.

    Sadly the AndroidManifest file itself is a pretty bad design. (so I blame Google mostly).
     
  24. ohskaren

    ohskaren

    Joined:
    Mar 31, 2022
    Posts:
    4
    @jdscogin I just ran into the same issue with my builds and can confirm I was able to fix it using a custom AndroidManifest.xml file, so my builds now upload to the App Lab Alpha channel without errors. This is without having to remove any code or the complicated steps mentioned in the video above. Some past posts referenced this method, but I wanted to share the step-by-step process that worked or me in this thread in case others missed it. @zezba9000 I haven't tested this with the BLUETOOTH permission, so I'm not sure if the same process will work for you :/

    Note: I'm using Unity 2021.2.8f1 and targeting Android version 32. @Chris-Mxx it'd be great if Unity added check boxes in Player Settings> Publishing Settings> Build to automate the steps below (if it isn't already in newer versions)!

    Here's the steps I followed:

    1. In the Unity Editor, go to Oculus>Tools> Create store-compatible AndroidManifest.xml
    2. In Player Settings> Publishing Settings> Build, make sure Custom Main Manifest checkbox is checked
    3. In Assets, search for AndroidManifest.xml and open it up in your code editor
    4. Add this after <manifest xmlns:android="http://schemas.android.com/apk/res/android" :



    5. Add these two lines after <uses-feature android:name="android.hardware.vr.headtracking" android:version="1" android:required="true" />:

    <uses-permission android:name="android.permission.RECORD_AUDIO" tools:node="remove" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" tools:node="remove" />​

    6. Increment your Version/Bundle Version Code and enter in your Keystore/Project Key passwords under Player Settings> Publishing Settings, then make a build as usual
    7. Upload your build to desired channel using Meta Quest Developer Hub







     
    jinxed_byte likes this.
  25. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    983
  26. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    299
    But that's exactly the issue, even with a custom manifest unity overwriting the permission (for unclear reasons). Meaning the bluetooth permission is kept and there is no evident way to remove it.

    We currently have only 2 options:

    1. Remove Vivox as our VoiP solution
    2. Post-build hack the apk manifest

    We most likely will remove Vivox as it is preventing us to publish on the official store.

    Is there any solution planned for this issue?
     
  27. Holonautic_Nemanja

    Holonautic_Nemanja

    Joined:
    Nov 19, 2018
    Posts:
    2
    This doesn't seem to work in Unity 2022.3. Even after updating to 4.4.0, the AndroidManifest file still doesn't get exported. Is this bug not planned to be fixed in Unity 2022.3?
     
    MadeFromPolygons likes this.
  28. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,949
    Unity is removing the internet access permission when using only built in unity packages and building for XR. this is really getting annoying - why cant we just edit the manifest ourselves, why would you remove internet access of all things? Overriding custom manifest doesnt work, as others have said
     
    zezba9000 likes this.
  29. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    983
    Yep I'm now running into this with Quest build. What a nightmare. Please guys... let us manually edit what permission get added and keep this simple. This is now getting ridicules to the point of wasting entire days trying to hack around the most basic build things in Unity for Android.
     
    dfm31 and MadeFromPolygons like this.
  30. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,949
    Agreed, this is insane just let us control the manifest, why have black box systems affect it like this?
     
    dfm31 and zezba9000 like this.
  31. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,949
  32. Pyr3z

    Pyr3z

    Joined:
    Jul 6, 2017
    Posts:
    32
    @MadeFromPolygons FWIW, if you export to Android Studio (implying you need to run the final build there, which can be a pain), there you will have full control over the final AndroidManifest.xml, and Unity won't be able to interfere

    ☜(゚ヮ゚☜)
     
  33. dfm31

    dfm31

    Joined:
    Dec 19, 2022
    Posts:
    2
    The solution by @ohskaren works, but I also had to create a custom launcher manifest as well, following the same steps.
     
  34. Mohamed_Elmejrab

    Mohamed_Elmejrab

    Joined:
    Aug 10, 2018
    Posts:
    2
    I had the same problem but different cause, I'll explain what worked in my case.

    Background: In my case I was making a game with ads integrated, then we decided to remove them entirely so the package was removed from the Package Manager, the Ads service was disabled from the project settings, and then updated the App Content section on Google Play Console to state that we're not using ads.

    Problem: When pushing to production it gave an error that you are using Ads but not declaring so on App Content section, if I revert the changes on App Content, it gives the opposite error where the it says permission is not declared whereas I am saying we are using ads now, the error is suppressible if you wish to do so, it may solve it but that is not what we tried.

    Cause: In this case we had an Internal Testing track still live with Ads in it, suspecting it is the cause of the second error (Permission not declared, App Content says game has ads), that is what turned out to be true.

    Solution: I updated the Internal Test track with a new release that does not have the AD_ID permission, suppressed the error and published the update. Now when I went to create a new release back in Production track it did not throw an error, so the permission is not declared and the App Content states that we don't use ads, which is the correct state.

    Hope this helps if someone gets into the same case as ours.
     
  35. unity_E689A8827B3C59AC4AA1

    unity_E689A8827B3C59AC4AA1

    Joined:
    Aug 2, 2023
    Posts:
    12
    this is fixed in latest packages