Search code examples
androidandroid-manifestmanifestandroid-library

How to make android library uses-permission optional instead of required


One of the libraries I am using specifies:

    <uses-feature android:name="android.hardware.camera" android:required="true" />

But I am handling the case where the camera is not available so I'd like to make it required="false".

Currently I am just removing it completely with

    <uses-feature android:name="android.hardware.camera" tools:node="remove" />

in my manifest file. That's not ideal because then it doesn't show up in the merged manifest at all. How do I get it to appear in the merged manifest file as

    <uses-feature android:name="android.hardware.camera" android:required="false" />

?


Solution

  • <uses-feature android:name="android.hardware.camera" android:required="false" tools:replace="required" />
    

    tools:replace replaces a lower-priority attribute and so should give you what you want.