fbsamples / audience-network

Open source projects to demonstrate SDK and sample code usages and integration, and to collaborate and support peers in this community.
https://developers.facebook.com/docs/audience-network
Other
318 stars 371 forks source link

ClassCastException:com.facebook.ads.redexgen.X.Th.A0I #141

Closed NiaNingXue closed 3 years ago

NiaNingXue commented 3 years ago

Hi, I update the audience network sdk to 6.2.1, crash happens on many users' devices, include android 6.0 - android 10. The previous version I use is 5.11.0 and has no this issue.

java.lang.ClassCastException: android.view.ViewRootImpl cannot be cast to android.view.ViewGroup com.facebook.ads.redexgen.X.Th.A0I com.facebook.ads.redexgen.X.5C.registerViewForInteraction com.facebook.ads.NativeAd.registerViewForInteraction NativeAd.java:8 com.sample.app.ad.view.NativeAdView.bindNativeAd NativeAdView.java:20 android.view.View.measure View.java:20089 androidx.constraintlayout.widget.ConstraintLayout.onMeasure ConstraintLayout.java:72 android.view.View.measure View.java:20089 android.view.ViewGroup.measureChildWithMargins ViewGroup.java:6415 android.widget.FrameLayout.onMeasure FrameLayout.java:214 androidx.appcompat.widget.ContentFrameLayout.onMeasure ContentFrameLayout.java:21 android.view.View.measure View.java:20089 android.view.ViewGroup.measureChildWithMargins ViewGroup.java:6415 android.widget.LinearLayout.measureChildBeforeLayout LinearLayout.java:1705 android.widget.LinearLayout.measureVertical LinearLayout.java:797 android.widget.LinearLayout.onMeasure LinearLayout.java:657 android.view.View.measure View.java:20089 android.view.ViewGroup.measureChildWithMargins ViewGroup.java:6415 android.widget.FrameLayout.onMeasure FrameLayout.java:214 android.view.View.measure View.java:20089 android.view.ViewGroup.measureChildWithMargins ViewGroup.java:6415 android.widget.LinearLayout.measureChildBeforeLayout LinearLayout.java:1705 android.widget.LinearLayout.measureVertical LinearLayout.java:797 android.widget.LinearLayout.onMeasure LinearLayout.java:657 android.view.View.measure View.java:20089 android.view.ViewGroup.measureChildWithMargins ViewGroup.java:6415 android.widget.FrameLayout.onMeasure FrameLayout.java:214 com.android.internal.policy.DecorView.onMeasure DecorView.java:743 android.view.View.measure View.java:20089 android.view.ViewRootImpl.performMeasure ViewRootImpl.java:2640 android.view.ViewRootImpl.measureHierarchy ViewRootImpl.java:1577 android.view.ViewRootImpl.performTraversals ViewRootImpl.java:1846 android.view.ViewRootImpl.doTraversal ViewRootImpl.java:1462 android.view.ViewRootImpl$TraversalRunnable.run ViewRootImpl.java:7013 android.view.Choreographer$CallbackRecord.run Choreographer.java:924 android.view.Choreographer.doCallbacks Choreographer.java:726 android.view.Choreographer.doFrame Choreographer.java:661 android.view.Choreographer$FrameDisplayEventReceiver.run Choreographer.java:910 android.os.Handler.handleCallback Handler.java:836 android.os.Handler.dispatchMessage Handler.java:103 android.os.Looper.loop Looper.java:203 android.os.Handler.handleCallback Handler.java:836 android.os.Handler.dispatchMessage Handler.java:103 android.os.Looper.loop Looper.java:203 android.app.ActivityThread.main ActivityThread.java:6328 java.lang.reflect.Method.invoke Method.java com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run ZygoteInit.java:1076 com.android.internal.os.ZygoteInit.main ZygoteInit.java:937

gwheet commented 3 years ago

It's probably happens because you add MediaView directly into Activity root layout (ViewRootImpl). Create some child layout under ViewRootImpl, for example, FragmentLayout and add MediaView inside this layout. It should fix the issue.

RodXander commented 3 years ago

I also have this issue. I checked what @gwheet said, but all my MediaViews are inside ConstraintLayouts. This is my stack trace:

Fatal Exception: java.lang.ClassCastException: android.view.ViewRootImpl cannot be cast to android.view.ViewGroup
       at com.facebook.ads.redexgen.X.b5.A0I(b5.java:68031)
       at com.facebook.ads.redexgen.X.5F.registerViewForInteraction(5F.java:13636)
       at com.facebook.ads.redexgen.X.5F.registerViewForInteraction(5F.java:13644)
       at com.facebook.ads.NativeAd.registerViewForInteraction(NativeAd.java:5)
       at com.google.ads.mediation.facebook.rtb.FacebookRtbNativeAd.trackViews(FacebookRtbNativeAd.java:2)
       at com.google.android.gms.internal.ads.zzart.zzx(zzart.java:20)
       at com.google.android.gms.internal.ads.zzaqp.zzbA(zzaqp.java:8)
       at com.google.android.gms.internal.ads.zzhx.onTransact(zzhx.java:20)
       at android.os.Binder.transact(Binder.java:675)
       at gc.bb(gc.java:2)
       at com.google.android.gms.ads.internal.mediation.client.q.x(q.java)
       at com.google.android.gms.ads.nonagon.ad.nativead.cl.a(cl.java:23)
       at com.google.android.gms.ads.nonagon.ad.nativead.ak.h(ak.java:4)
       at com.google.android.gms.ads.nonagon.ad.nativead.ak.g(ak.java:2)
       at com.google.android.gms.ads.nonagon.ad.nativead.bj.d(bj.java:6)
       at com.google.android.gms.ads.internal.formats.client.k.bA(k.java:26)
       at gd.onTransact(gd.java:4)
       at android.os.Binder.transact(Binder.java:675)
       at com.google.android.gms.internal.ads.zzhw.zzbj(zzhw.java:7)
       at com.google.android.gms.internal.ads.zzahm.zzd(zzahm.java:8)
       at com.google.android.gms.ads.nativead.NativeAdView.setNativeAd(NativeAdView.java:8)
       at com.rodxander.bloodpressureapp.ad.AppAdsManager.populateNativeAdView(AppAdsManager.java:144)
       at com.rodxander.bloodpressureapp.ui.base.BaseActivity.lambda$showAd$1(BaseActivity.java:2)
       at com.rodxander.bloodpressureapp.ui.base.-$$Lambda$BaseActivity$TJ5or2Bst9qHurP0CqODtmlHuBo.run(-.java:2)
       at android.os.Handler.handleCallback(Handler.java:873)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7156)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
Nghicv commented 2 years ago

Hi @RodXander. I am getting the same crash. Did you resolve the issue?

momshardadevi commented 2 years ago

hi, I am also getting the same crash...

sonusourav commented 1 year ago

Facing the same issue, has anyone got any fix for this?

tangeriner commented 1 year ago

facebook-sdk is so terrible!