Shared Chat•
GPT-4

Unity: Add android:exported

July 7, 2023
I'm sideloading Oculus Quest2 apps that I build in Unity. Today that broke. I get this error: Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present How do I add android:exported when working in Unity?
ChatGPT

The error you're encountering is related to changes made to Android's app privacy and security policies starting from Android 12 (API Level 31 or "S"). The android:exported attribute is used to define whether a given application component (like an activity, service, or broadcast receiver) is available for other apps to use.

Unity itself does not provide an interface to directly modify Android Manifest. Therefore, you have to manually create and modify an AndroidManifest.xml file.

To define the android:exported attribute in Unity, follow these steps:

  1. First, you need to locate the default AndroidManifest.xml file that Unity uses and make a copy of it. This can usually be found at <YourUnityInstallPath>/Editor/Data/PlaybackEngines/AndroidPlayer/Apk/AndroidManifest.xml.

  2. Once you've found it, copy this file to the Assets folder in your Unity project. This will be the AndroidManifest.xml file that your project uses, and it should be placed in an appropriate directory, for example: Assets/Plugins/Android/AndroidManifest.xml.

  3. Open the copied AndroidManifest.xml in a text editor. You will need to add the android:exported attribute to the relevant components (like your activities, services, receivers). The android:exported attribute can be set to either "true" or "false", depending on whether you want the component to be available to other apps.

For instance, you might have something that looks like this:

xml
<activity android:name=".YourActivity" android:exported="true"> <!-- Add this line --> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
  1. Save and close the AndroidManifest.xml file. The next time you build your project, Unity should use your custom AndroidManifest.xml file instead of the default one.

  2. If you continue to encounter issues, ensure that your target API level in Unity (in Player Settings) is set to the correct version (API Level 31 or higher in your case).

  3. Re-build your project and try sideloading it onto your Oculus Quest 2 again.

Remember that changes to the AndroidManifest.xml file should be made with care, as errors can cause your app to malfunction or fail to install. Always back up your project before making changes.

Continue this conversation
|Terms of use|Privacy policy