AppLovin / AppLovin-MAX-SDK-Android

Other
210 stars 95 forks source link

onSdkInitialized method is not triggered when I initialize the SDK without an Activity. #673

Open mertkesgin opened 2 weeks ago

mertkesgin commented 2 weeks ago

MAX SDK Version

12.5.0

Device/Platform Info

Android

Current Behavior

I am trying to initialize the SDK without Activity. Although the SDK is initialized, the onSdkInitialized method is not triggered.

val initConfig = AppLovinSdkInitializationConfiguration
            .builder(applovinAppId, getApplicationContext())
            .setMediationProvider(AppLovinMediationProvider.MAX)
            .build()

AppLovinSdk.getInstance(getApplicationContext())
    .initialize(initConfig) {
        // This block is never triggered
    }

I can see the following error in the logs;

[AppLovinSdk] Auto-initing adapters for non-MAX mediation provider: admob
[AppLovinSdk] 
**********
Attempting to init 3rd-party SDKs without an Activity instance.
**********

This is how I know that the SDK is initialized even though the onSdkInitialized method is not triggered;

scope.launch {
    while (true) {
        Log.d(TAG, "isInitialized: ${appLovinSdk.isInitialized}")
        if (appLovinSdk.isInitialized) break
        delay(500)
    }
}

NOTE: When I initialize the SDK from an Activity, the onSdkInitialized method is triggered.

Expected Behavior

After initializing the SDK without Activity, the onSdkInitialized method must be triggered;

val initConfig = AppLovinSdkInitializationConfiguration
            .builder(applovinAppId, getApplicationContext())
            .setMediationProvider(AppLovinMediationProvider.MAX)
            .build()

AppLovinSdk.getInstance(getApplicationContext())
    .initialize(initConfig) {
        // This block must be triggered when the SDK is initialized.
    }

How to Reproduce

You can try to initialize the SDK without Activity.

Additional Info

No response

cemtuver-applovin commented 2 weeks ago

Hey @mertkesgin! I have created a sample project in which the AppLovin SDK was initialized in a service without an Activity. However, I was unable to reproduce the issue, and the callback was invoked as expected.

I believe the issue you are facing is due to you and AdMob Mediation trying to initialize our SDK simultaneously. While you are setting the mediation provider to "MAX", the logs show mediation provider: admob. Could you please check if this might be the case for you?

Please let me know if this fixes the callback issue for you.

mertkesgin commented 2 weeks ago

Even when I disable AdMob and initialize the AppLovin SDK, the same issue persists. Could you please add the following scenario to your sample project and test it again?

anyRxSingleFunction()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .doOnSuccess { 
                // Init AppLovin SDK
            }
            .subscribe()
            .addTo(compositeDisposable)
cemtuver-applovin commented 2 weeks ago

Hi @mertkesgin, thanks for checking. Would you be able to create a sample Android Studio project where this issue reproduces and share the project with me? This will allow me to investigate your use case directly.