Search code examples
androidgoogle-play-servicesandroid-manifestphoto-picker

Automatic install of the backported version of the Android Photo Picker not playing nicely with Android Studio


I'm trying to implement the new Android Photo Picker but I'm running into an issue when trying to setup the automatic install of the backported photo picker module on older devices.

According to the docs we need to add the following to our app's manifest file to allow this:

<!-- Trigger Google Play services to install the backported photo picker module -->
<service android:name="com.google.android.gms.metadata.ModuleDependencies"
         android:enabled="false"
         android:exported="false">
    <intent-filter>
        <action android:name="com.google.android.gms.metadata.MODULE_DEPENDENCIES" />
    </intent-filter>
    <meta-data android:name="photopicker_activity:0:required" android:value="" />
</service>

However, when I do that, I get an error in Android Studio about "com.google.android.gms.metadata.ModuleDependencies" not being recognized or resolved.

enter image description here

How can we fix this?


Solution

  • The docs weren't correct as reported in this issue.

    The recommendation is to add a tools:ignore="MissingClass" attribute and to also suppress AndroidDomInspection:

    <!--
        Prompt Google Play services to install the backported photo picker module
        https://developer.android.com/training/data-storage/shared/photopicker#device-availability
    -->
    <!--suppress AndroidDomInspection -->
    <service android:name="com.google.android.gms.metadata.ModuleDependencies"
        android:enabled="false"
        android:exported="false"
        tools:ignore="MissingClass">
        <intent-filter>
            <action android:name="com.google.android.gms.metadata.MODULE_DEPENDENCIES" />
        </intent-filter>
        <meta-data android:name="photopicker_activity:0:required" android:value="" />
    </service>