Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Resolved Unity removes "android.permission.INTERNET" in the build.apk after build is completed

Discussion in 'Android' started by DaNueromancer, Jul 29, 2023.

  1. DaNueromancer

    DaNueromancer

    Joined:
    Mar 28, 2023
    Posts:
    3
    Hi, I am building a TCP Client VR application that is being deployed to the Meta Quest Pro. Initially I was getting a SocketException of Access Denied and after doing a little research I found out that I need to add the following statement to my AndroidManfiest.xml, which I did:
    <uses-permission android:name="android.permission.INTERNET" />


    I am using 2022.3.5f1 version for the editor. My application initiates a socket connection to a server hosted on my local machine. Both headset and the local machine are connected to the same wi-fi and the application works completely fine on the local machine (tested using XR Simulator that comes with the OpenXR plug-in). I have also tried to access the server's frontend from the headset's browser using the local machines IP and that works fine as well.

    I have also set the "Internet Access" to "Require" from "Auto" which gives me the following warnings after build is completed:

    1) Library\Bee\artifacts\Android\Manifest\LauncherManifestDiag.txt: Unable to find Unity activity in manifest. Some attributes may not be set properly and need to be set manually.

    2) Library\Bee\artifacts\Android\Manifest\LauncherManifestDiag.txt: Unity is trying to add element uses-permission#android.permission.INTERNET but it is already declared by the user in Assets/Plugins/Android\AndroidManifest.xml.

    3) Library\Bee\artifacts\Android\Manifest\LauncherManifestDiag.txt: Unity is trying to add element uses-permission#android.permission.ACCESS_NETWORK_STATE but it is already declared by the user in Assets/Plugins/Android\AndroidManifest.xml.

    2 & 3 makes sense as I did add those permissions manually. I do not know if I should be worrying about 1.

    Here is the main issue that I believe is causing the socket connection to fail. After I built to my headset and decompile the latest build.apk, the AndroidManifest.xml in the build.apk looks like this:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="0.1" android:installLocation="auto" android:compileSdkVersion="32" android:compileSdkVersionCodename="12" package="com.DefaultCompany.ScannerDemo" platformBuildVersionCode="32" platformBuildVersionName="12">
    <uses-sdk android:minSdkVersion="29" android:targetSdkVersion="32"/>
    <supports-screens android:anyDensity="true" android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true"/>
    <uses-permission android:name="com.oculus.permission.HAND_TRACKING"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
    <uses-feature android:name="android.hardware.vr.headtracking" android:required="true" android:version="1"/>
    <uses-feature android:name="oculus.software.handtracking" android:required="false"/>
    <uses-feature android:name="android.hardware.vulkan.version" android:required="true"/>
    <uses-feature android:name="android.hardware.microphone" android:required="false"/>
    <uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
    <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false"/>
    <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false"/>
    <application android:label="@String/app_name" android:icon="@Mipmap/app_icon" android:allowBackup="false" android:extractNativeLibs="true" android:networkSecurityConfig="@XML/network_sec_config">
    <meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="false"/>
    <meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only"/>
    <meta-data android:name="com.oculus.handtracking.frequency" android:value="HIGH"/>
    <meta-data android:name="com.oculus.handtracking.version" android:value="V2.0"/>
    <meta-data android:name="unity.splash-mode" android:value="0"/>
    <meta-data android:name="unity.splash-enable" android:value="true"/>
    <meta-data android:name="unity.launch-fullscreen" android:value="true"/>
    <meta-data android:name="unity.allow-resizable-window" android:value="false"/>
    <meta-data android:name="notch.config" android:value="portrait|landscape"/>
    <meta-data android:name="unity.auto-report-fully-drawn" android:value="true"/>
    <activity android:theme="@StyLe/Theme.Black.NoTitleBar.Fullscreen" android:name="com.unity3d.player.UnityPlayerActivity" android:exported="true" android:excludeFromRecents="true" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
    <intent-filter>
    <category android:name="android.intent.category.LAUNCHER"/>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="com.oculus.intent.category.VR"/>
    </intent-filter>
    <meta-data android:name="notch_support" android:value="true"/>
    <meta-data android:name="com.oculus.vr.focusaware" android:value="true"/>
    </activity>
    <meta-data android:name="com.oculus.supportedDevices" android:value="quest|quest2|cambria"/>
    </application>
    </manifest>

    As you can see, the tag for INTERNET permission is missing in the file. It seems as if it gets removed during the build. I have tried a bunch of methods and have spent almost 9 hours now trying to figure out what is going wrong and creating new builds show the same behavior of AndroidManifest.xml not having the INTERNET permission.

    My sincerest apologies for the long post.

    I greatly appreciate any assistance that can be offered.

    Thanks.
     
    Last edited: Jul 29, 2023
  2. manugil

    manugil

    Unity Technologies

    Joined:
    Jan 13, 2020
    Posts:
    43
    Hey @DaNueromancer,

    Do you mind sharing your custom manifest in
    Assets/Plugins/Android\AndroidManifest.xml
    here?

    Thank you! :)
     
    DaNueromancer likes this.
  3. DaNueromancer

    DaNueromancer

    Joined:
    Mar 28, 2023
    Posts:
    3
    Thanks for your response. My custom manifest is below:
    Code (CSharp):
    1. <?xml version="1.0" encoding="utf-8" standalone="no"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
    3.   <uses-permission android:name="com.oculus.permission.HAND_TRACKING" />
    4.   <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    5.   <uses-permission android:name="android.permission.INTERNET" />
    6.   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    7.   <application android:label="@string/app_name" android:icon="@mipmap/app_icon" android:allowBackup="false">
    8.     <activity android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" android:configChanges="locale|fontScale|keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode" android:launchMode="singleTask" android:name="com.unity3d.player.UnityPlayerActivity" android:excludeFromRecents="true" android:exported="true">
    9.       <intent-filter>
    10.         <action android:name="android.intent.action.MAIN" />
    11.         <category android:name="android.intent.category.LAUNCHER" />
    12.       </intent-filter>
    13.     </activity>
    14.     <meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="false" />
    15.     <meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only" />
    16.     <meta-data android:name="com.oculus.handtracking.frequency" android:value="HIGH" />
    17.     <meta-data android:name="com.oculus.handtracking.version" android:value="V2.0" />
    18.   </application>
    19.   <uses-feature android:name="android.hardware.vr.headtracking" android:version="1" android:required="true" />
    20.   <uses-feature android:name="oculus.software.handtracking" android:required="false" />
    21. </manifest>
    Also, I am about to create a small test project and see if I can reproduce this error. I wanted to do this after none of the methods that I used to fix the issue worked but I also wanted to see if there is a way to fix it without creating a new project as I have made some progress in my existing project.
     
  4. DaNueromancer

    DaNueromancer

    Joined:
    Mar 28, 2023
    Posts:
    3
    @manugil I wanted to let you know that I have resolved the issue. I had to change a "Meta Quest Support" feature's setting so that Internet access is not removed. I honestly had no clue about this setting option. I believe it is a security thing, but anyways, here is what I did:

    1) Go to Project Setting -> XR Plug-in Management -> Open XR

    2) Under Android tab, in the OpenXR Feature Groups. Select the gear symbol for "Meta Quest Support" feature row. This will open the settings editor for that feature

    Meta Quest Support setting.jpg

    3) In the settings editor, under "Feature Settings" section there is a sub-section called "Manifest Settings"

    4) Uncheck the "Force Remove Internet" option under the "Manifest Setting" sub-section

    Meta Quest Support setting editor.jpg

    After doing this,
    <uses-permission android:name="android.permission.INTERNET" />
    appeared in the AndroidManifest.xml of the decompiled build.apk and my app was able to successfully initiate a socket connection.
     
    Last edited: Aug 1, 2023
    Fonsi_123 and Archtica like this.
  5. manugil

    manugil

    Unity Technologies

    Joined:
    Jan 13, 2020
    Posts:
    43
    Thanks for such a detailed explanation on how to solve this issue, it will definitely help other users facing it. According to the release notes on the OpenXR Plugin, seems like "
    Force remove Internet Permission
    " is a relatively new option.
     
    DaNueromancer likes this.
  6. Archtica

    Archtica

    Joined:
    Mar 23, 2018
    Posts:
    47
    Thank you so much @DaNueromance, this helped me too! Impossible to know.
     
    DaNueromancer likes this.
  7. abreu9999

    abreu9999

    Joined:
    Jun 14, 2016
    Posts:
    1
    I still have this issue with version 2023.1.9f1. The option "Force Remove Internet" is re-enabled and removing the option and building again is not enough to include Internet access in the APK manifest. Instead I need to do a clean build to update the manifest file in the APK.
     
    T3ddyTheGiant and MikleRe like this.
  8. T3ddyTheGiant

    T3ddyTheGiant

    Joined:
    Aug 1, 2018
    Posts:
    11
    Okay so this is such a gotcha moment...

    The next question is how can we programmatically remove the Meta Quest Support feature when unneeded for builds for the interim. The force remove internet toggle is reenabled, eg. after recompiling scripts, from the editor processor (super annoying).

    Even more annoying is that support feature has internal fields, so we can't simply set the field.

    Is this a situation where we need to use a post gradle callback script and force the internet permission to be present?
     
  9. semateos

    semateos

    Joined:
    May 11, 2016
    Posts:
    14
    I had this issue appear out of nowhere switching from unity 2022.3.9 to 2022.3.11 - I think it may be due to upgrading from Oculus XR Plugin 4.0.0 to 4.1.1. Unchecking the checkbox did not bring back the internet permission. I had to manually add the permission line to my custom manifest file.
     
  10. semateos

    semateos

    Joined:
    May 11, 2016
    Posts:
    14
    Oh wait, it's still being removed! The checkbox is unchecked! What fresh hell is this?
     
  11. semateos

    semateos

    Joined:
    May 11, 2016
    Posts:
    14
    Oh, and the checkbox comes back checked after restarting unity.
     
  12. T3ddyTheGiant

    T3ddyTheGiant

    Joined:
    Aug 1, 2018
    Posts:
    11
    Best option is to just downgrade OpenXR to v1.7.0 for the interim
     
  13. semateos

    semateos

    Joined:
    May 11, 2016
    Posts:
    14
    manugil likes this.
  14. kblood

    kblood

    Joined:
    Jun 20, 2012
    Posts:
    92
    Is this really seen as "resolved"? I think maybe I got this to work once, using a custom AndroidManifest and removing that option with "force disable Internet", but it never fully worked and now I the webrequests consistently fail every time and Unity keeps reenabling that option.

    Shouldnt the custom manifest solve this? I am trying to get gltfast to work on the Quest 3. Seems in 2022.3.11 I cannot even downgrade the plugin to 1.7.0, so I guess I might have to download an older version of Unity 2022.3 to get this to work?
     
  15. T3ddyTheGiant

    T3ddyTheGiant

    Joined:
    Aug 1, 2018
    Posts:
    11
    Custom manifest does not solve this - manifests are merged together and modified by whatever build processors are included in the project. You could write a post gradle callback script to force include the internet permission as a last resort.
     
  16. manugil

    manugil

    Unity Technologies

    Joined:
    Jan 13, 2020
    Posts:
    43
    According to OXRB-252, this issue has now been fixed for OpenXR 1.9.1.
     
    AijiFab likes this.
  17. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,685
    And what is the prospective release date for 1.9.1 @manugil , because the only available version on 2022.3 currently is 1.8.2?
     
    taimex likes this.
  18. steve-synth

    steve-synth

    Joined:
    Aug 22, 2023
    Posts:
    1
  19. JDH

    JDH

    Joined:
    Jul 1, 2013
    Posts:
    1
    No it is not available. I'm pulling my hair out trying to find it. They have documentation posted for 1.9.1 but you can't actually download or install a version 1.9 anywhere. Package manager only lets you get 1.8.2 or previous.

    Unity when will 1.9.1 be available? I really need this fix so we can actually automate our build and it produces a working apk.
     
    AndreaDAn likes this.
  20. MasyMo

    MasyMo

    Joined:
    Mar 26, 2022
    Posts:
    1
    @JDH: I case you havnt already fixed it. Try this is the package Manger -> upload_2023-11-21_12-58-20.png
     

    Attached Files:

    cliv3dev and BroccoliGamesCZ like this.
  21. nobatgeldi

    nobatgeldi

    Joined:
    Feb 6, 2016
    Posts:
    2