How to prevent Unity from adding unwanted Permissions to your Android Manifest
We recently noticed that something in our Unity Android app's build process was adding unwanted permissions to the final AndroidManifest.xml
, specifically READ_PHONE_STATE
. This might be due to some library we're using or something about Unity 6 (we didn't really investigate this) but regardless of what was trying to add that permission, we needed to make sure it wasn't included in the final output.
After a bit of research I found the easiest way to force the build to NOT include this permission in the final manifest is as follows:
- Add the tools namespace to your root manifest\:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<!-- Other manifest entries -->
</manifest>
- Add an entry forcing the removal of the unwanted permission in the final build:
<uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove" />
Your final manifest should look something like this:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<!-- Other manifest entries -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove" />
</manifest>