Search code examples
androidandroid-photo-picker

Class referenced in the manifest, `com.google.android.gms.metadata.ModuleDependencies`, was not found in the project or the libraries error


These day I want to make google photo picker under api level 30 so I write AndroidManifest.xml

<!-- suppress AndroidDomInspection -->
        <!-- 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>

theses code to install the backported photo picker module. what can I do for make photo picker under api level 30?? plus these are my build.gradle.kts dependencies

dependencies {

    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.appcompat)
    implementation(libs.material)
    implementation(libs.androidx.constraintlayout)
    implementation(libs.androidx.navigation.fragment.ktx)
    implementation(libs.androidx.navigation.ui.ktx)
    implementation(libs.play.services.base)
    testImplementation(libs.junit)
    androidTestImplementation(libs.androidx.junit)
    androidTestImplementation(libs.androidx.espresso.core)
    implementation(libs.androidx.activity.ktx)

}

I already check about google playstore service activate in emulator. the playstore service is already activate. And also api level over 30 can see perfect google photo picker.


Solution

  • Solution 1

    Add these dependencies:

    implementation("com.google.android.gms:play-services-base:18.3.0")
    

    This is your manifest file

    <manifest>
        <application>
            <!-- 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>
    
            <!-- Play Services Availability -->
            <meta-data
                android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version" />
        </application>
    
        <!-- Required Permissions -->
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    </manifest>
    

    Solution 2

    Add these dependencies:

    implementation("com.google.android.gms:play-services-auth:20.7.0")
    implementation("androidx.activity:activity:1.8.0")
    

    Then use this code to implement photo picker:

    val pickSingleMedia = registerForActivityResult(PickVisualMedia()) { uri ->
        if (uri != null) {
            // Handle selected media
        }
    }
    
    // Launch picker
    pickSingleMedia.launch(PickVisualMediaRequest(PickVisualMedia.ImageOnly))
    

    The manifest entry you showed is no longer needed. The new ActivityResult API handles photo picking across API levels automatically.

    please let me know if still you are in problem. Thanks