Freelancing for Pale Blue

Looking for flexible work opportunities that fit your schedule?


Avoiding unintentional device exclusion in an Android app

Android Aug 30, 2024

When releasing the latest version of one of our apps, I encountered an unexpected issue: a warning in the Google Play Console indicated that a significant number of devices would no longer be able to install the update. This was surprising since we hadn’t made any major changes that should have limited device compatibility.

Investigating the AndroidManifest.xml

To understand what was happening, I opened our AndroidManifest.xml, but there was no mention of the problematic feature. This led me to suspect that a library we were using had merged its own manifest with ours, introducing the issue.

Android libraries can contribute their own manifest entries when merged into your project. These entries might include permissions, activities, or, as in this case, hardware feature requirements. The key to solving the problem was figuring out which library was responsible.

Using the merged manifest view

Android Studio offers a useful but somewhat hidden tool called the Merged Manifest view. This feature allows you to see the final manifest as it will be packaged into your APK/AAB, including annotations that show where each line originated.

To access the Merged Manifest view open your AndroidManifest.xml in Android Studio and click on the Merged Manifest tab at the bottom of the editor window. The view will display a combined manifest, highlighting the source of each element.

Using this tool, I discovered that one of our dependencies was adding a feature requirement for the NFC hardware. This was the reason for the sudden drop in compatible devices.

Possible remedies

Once you identify the problematic library, you have two options.

If the library isn’t essential, consider removing or replacing it with an alternative that doesn’t introduce unwanted features. This is the simplest solution but may not always be feasible.

If the library is necessary, you can override the manifest entry by adding the following line to your AndroidManifest.xml:

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

This tells the build system to replace the required attribute with false, ensuring your app remains available on devices without this hardware.

Be cautious with this approach. Declaring a feature as not required means your app must handle cases where the feature is missing. The library setting this in the manifest might expect to find this feature without any check, which might lead to crashes!

The Merged Manifest view in Android Studio is a powerful tool for diagnosing issues related to the AndroidManifest.xml. By understanding how libraries contribute to your app’s final manifest, you can prevent unintentional feature declarations that limit device compatibility.

Happy coding!

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.