22

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?

karlingen
  • 13,800
  • 5
  • 43
  • 74
  • If nothing else, you could try adding a dependency on `com.google.android.gms:play-services-home`, version `16.0.0-beta1` or higher. Google's docs for [Matter integration](https://developers.home.google.com/matter/apis/home) show the same sort of `com.google.android.gms.metadata.MODULE_DEPENDENCIES` `` element. If that works, you might then be able to identify the specific dependency that contains the class. – CommonsWare Apr 16 '23 at 17:15
  • It seems some one logged an Issue : Track it here : https://issuetracker.google.com/issues/279636992 – Jaydeep Devda Apr 26 '23 at 07:29
  • I tried adding com.google.android.gms:play-services-home:16.0.0-beta1, it doesn't include com.google.android.gms.metadata.ModuleDependencies either. – Andreas May 07 '23 at 18:19
  • have the same issue, any workarounds? is there an updated issue tracker link for this? – KingKongCoder May 18 '23 at 16:39
  • 1
    https://issuetracker.google.com/issues/280659181 looks similar – ace1234 May 20 '23 at 05:43

2 Answers2

9

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>
karlingen
  • 13,800
  • 5
  • 43
  • 74
0

It seems like this is solved by adding the following attribute: tools:ignore="MissingClass" to the XML node with the ModuleDependencies class. The documentation was updated: https://developer.android.com/training/data-storage/shared/photopicker#device-availability

Andreas
  • 185
  • 12
  • Adding `tools:ignore="MissingClass"` does nothing for me. I'm still seeing `Unresolved package 'gms'`, `Unresolved package 'metadata' ` and `Unresolved class 'ModuleDependencies' ` – karlingen May 22 '23 at 12:32
  • That's just an IDE error right? It's because the class is does not exist. It does compile however. – Andreas May 22 '23 at 13:59
  • We've always been able to compile with the IDE error. Adding that attribute does nothing – karlingen May 23 '23 at 12:38