Need Help: Runtime Error in Admob Extension Development

Hi MIT App Inventor Community,

I'm currently working on developing an extension for Admob ads, but I've run into a runtime error that I can't seem to resolve.

Error Message:

Runtime Error

Failed resolution of: Lcom/google/android/gms/ads/internal/client/zzk:

Library Used:

image

I've double-checked my code and the libraries I'm using, but I'm still not sure why this error is occurring. Has anyone encountered a similar issue or could provide some guidance on how to fix it?

Basic Code I Used to Check the Initialization:

 package com.simple.admob;

    import android.app.Activity;
    import android.content.Context;
    import androidx.annotation.*;
    import org.jetbrains.annotations.NotNull;

    import com.google.android.gms.ads.*;
    import com.google.android.gms.ads.RequestConfiguration;
    import com.google.android.gms.ads.initialization.InitializationStatus;
    import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;

    import com.google.appinventor.components.annotations.SimpleFunction;
    import com.google.appinventor.components.annotations.SimpleEvent;
    import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
    import com.google.appinventor.components.runtime.ComponentContainer;
    import com.google.appinventor.components.runtime.EventDispatcher;

    public class Admob extends AndroidNonvisibleComponent {

        private Context context;
        private Activity activity;
        private boolean testMode = true;

        public Admob(ComponentContainer container) {
            super(container.$form());
            this.context = container.$context();
            this.activity = container.$context();
        }

        @SimpleFunction(description = "Initialize AdMob SDK.")
        public void InitializeSdk() {
            MobileAds.initialize(activity, new OnInitializationCompleteListener() {
                @Override
                public void onInitializationComplete(@NonNull InitializationStatus initializationStatus) {
                    SdkInitialized();
                }
            });
        }

        @SimpleEvent(description = "Event triggered when the AdMob SDK is successfully initialized.")
        public void SdkInitialized() {
            EventDispatcher.dispatchEvent(this, "SdkInitialized");
        }
    }
    

Any help would be greatly appreciated!

Thanks in advance.

Check if any dependency is missing. If you are testing in companion, build apk and then test.

1 Like

Thank you for your suggestion! In the attached picture, I took the screenshot after testing with a built APK. Interestingly, it works fine in the companion but throws the error in the APK. You're correct that the issue is due to a missing dependency.

Could you guide me on how to identify which class or part of the dependency is missing?

Include all required dependencies with,

@UsesLibraries(libraries = "your-library.jar")

Import statement:

import com.google.appinventor.components.annotations.UsesLibraries;