AppLovin / AppLovin-MAX-SDK-Android

Other
233 stars 104 forks source link

Null Pointer Exception after upgrading SDK to 12.4.2 #657

Closed BinaryCores closed 6 months ago

BinaryCores commented 7 months ago

Following exceptions are occurring in all of our apps and due to this crash rate is very high in Android Vitals. Kindly provide the solution for it or kindly fix it soon.

Exception java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.applovin.sdk.AppLovinSdkSettings.isVerboseLoggingEnabled()' on a null object reference at com.applovin.impl.vj.c (SourceFile:497) at com.applovin.impl.sdk.t.a (SourceFile:15) at com.applovin.impl.sdk.t.a (SourceFile:14) at com.applovin.impl.mediation.ads.a.logApiCall (SourceFile:4) at com.applovin.mediation.nativeAds.MaxNativeAdLoader. (SourceFile:3) at com.applovin.mediation.nativeAds.MaxNativeAdLoader. (SourceFile:1) at com.BinaryCores.GalaxyA23Wallpapers.binary_cores_fragments.FragmentCategory.onCreateView (FragmentCategory.java:67) at androidx.fragment.app.Fragment.performCreateView (Fragment.java:2963) at androidx.fragment.app.FragmentStateManager.createView (FragmentStateManager.java:518) at androidx.fragment.app.FragmentStateManager.moveToExpectedState (FragmentStateManager.java:282) at androidx.fragment.app.FragmentStore.moveToExpectedState (FragmentStore.java:112) at androidx.fragment.app.FragmentManager.moveToState (FragmentManager.java:1647) at androidx.fragment.app.FragmentManager.dispatchStateChange (FragmentManager.java:3128) at androidx.fragment.app.FragmentManager.dispatchActivityCreated (FragmentManager.java:3072) at androidx.fragment.app.FragmentController.dispatchActivityCreated (FragmentController.java:251) at androidx.fragment.app.FragmentActivity.onStart (FragmentActivity.java:502) at androidx.appcompat.app.AppCompatActivity.onStart (AppCompatActivity.java:251) at android.app.Instrumentation.callActivityOnStart (Instrumentation.java:1582) at android.app.Activity.performStart (Activity.java:8977) at android.app.ActivityThread.handleStartActivity (ActivityThread.java:4198) at android.app.servertransaction.TransactionExecutor.performLifecycleSequence (TransactionExecutor.java:225) at android.app.servertransaction.TransactionExecutor.cycleToPath (TransactionExecutor.java:205) at android.app.servertransaction.TransactionExecutor.executeLifecycleState (TransactionExecutor.java:177) at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:98) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2685) at android.os.Handler.dispatchMessage (Handler.java:106) at android.os.Looper.loopOnce (Looper.java:230) at android.os.Looper.loop (Looper.java:319) at android.app.ActivityThread.main (ActivityThread.java:8893) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:608) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1103)

LouisYubo commented 7 months ago

We have the same issue, which occurs when using setHasUserConsent

Fatal Exception: java.lang.NullPointerException
Attempt to invoke virtual method 'boolean com.applovin.sdk.AppLovinSdkSettings.isVerboseLoggingEnabled()' on a null object reference
com.applovin.impl.vj.c (SourceFile:497)
com.applovin.impl.sdk.t.a (SourceFile:15)
com.applovin.impl.sdk.t.a (SourceFile:14)
com.applovin.communicator.AppLovinCommunicator.a (SourceFile:7)
com.applovin.communicator.AppLovinCommunicator.a (SourceFile:4)
com.applovin.impl.sdk.h.<init> (SourceFile:8)
com.applovin.impl.sdk.k.o (SourceFile:1)
com.applovin.impl.sdk.k.P0
com.applovin.sdk.AppLovinSdk.reinitialize (SourceFile:2)
com.applovin.sdk.AppLovinSdk.reinitializeAll (SourceFile:5)
com.applovin.sdk.AppLovinPrivacySettings.setHasUserConsent (SourceFile:6)
adurandet commented 7 months ago

Same issue while trying to configure settings

val initConfig = AppLovinSdkInitializationConfiguration.builder(AppLovinKey.appLovinKey, context)
            .setMediationProvider(AppLovinMediationProvider.MAX)
            .configureSettings { settings ->
                settings.termsAndPrivacyPolicyFlowSettings.apply {
                    isEnabled = true
                    privacyPolicyUri = Uri.parse(Urls.privacy)
                    termsOfServiceUri = Uri.parse(Urls.terms)
                }
            }
            .build()

It doesn't happen if I don't minify. It must be a R8 / proguard issue

vudt98 commented 7 months ago

Same issue while trying to configure settings

val initConfig = AppLovinSdkInitializationConfiguration.builder(AppLovinKey.appLovinKey, context)
            .setMediationProvider(AppLovinMediationProvider.MAX)
            .configureSettings { settings ->
                settings.termsAndPrivacyPolicyFlowSettings.apply {
                    isEnabled = true
                    privacyPolicyUri = Uri.parse(Urls.privacy)
                    termsOfServiceUri = Uri.parse(Urls.terms)
                }
            }
            .build()

It doesn't happen if I don't minify. It must be a R8 / proguard issue

I don't think so, because today I also encountered this error while testing with the debug version that doesn't use R8 and minify. But it's really difficult to reproduce it.

christophercong commented 7 months ago

Hey all, we have a fix for this going out in next release. In the meantime, the work-around is to not call AppLovinSdk.getInstance(context) until you are ready to initialize the SDK (with the call to - initialize

adurandet commented 7 months ago

@christophercong not sure to understand your workaround.

In my code, AppLovinSdk.getInstance(context) is the last call I am doing.

        val initConfig = AppLovinSdkInitializationConfiguration.builder(AppLovinKey.appLovinKey, context)
            .setMediationProvider(AppLovinMediationProvider.MAX)
            .configureSettings { settings ->
                settings.termsAndPrivacyPolicyFlowSettings.apply {
                    isEnabled = true
                    privacyPolicyUri = Uri.parse(Urls.privacy)
                    termsOfServiceUri = Uri.parse(Urls.terms)
                }
            }
            .build()

        AppLovinSdk.getInstance(context)
            .initialize(initConfig) {
                _isInitialized.value = true
            }
adurandet commented 7 months ago

Just to add more info. I tried to initiliaze the terms and pricacy using the json integration (as per your documentation) and I am still facing the issue.

I think it is not be the same issue as the isVerboseLoggingEnable() as the logs are not the same. I have opened a separate issue.

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equalsIgnoreCase(java.lang.String)' on a null object reference
       at com.applovin.impl.r4.a(SourceFile:1601)
       at com.applovin.impl.r4.a(SourceFile:2963)
       at com.applovin.impl.r4.a(SourceFile:2259)
       at android.os.Handler.handleCallback(Handler.java:959)
       at android.os.Handler.dispatchMessage(Handler.java:100)
       at android.os.Looper.loopOnce(Looper.java:232)
       at android.os.Looper.loop(Looper.java:317)
       at android.app.ActivityThread.main(ActivityThread.java:8501)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)
[PersistentPostbackQueueSaveTask] Postbacks queue file does not exist.
BinaryCores commented 7 months ago

Any update on this? When it will be resolved?

christophercong commented 6 months ago

Hi all, this has been resolved in the new the Android SDK release 12.5.0. Note: to configure the terms/privacy settings pre-init, we have changed the API to the following:

val settings = AppLovinSdk.getInstance(this).settings
settings.termsAndPrivacyPolicyFlowSettings.apply {
  isEnabled = true
  privacyPolicyUri = Uri.parse("«https://your_company_name.com/privacy_policy»")
  termsOfServiceUri = Uri.parse("«https://your_company_name.com/terms_of_service»")
}