ammarahm-ed / react-native-admob-native-ads

A simple and robust library for creating & displaying Admob Native Advanced Ads in your React Native App using Native Views.
https://ammarahm-ed.github.io/react-native-admob-native-ads/docs/introduction/
MIT License
402 stars 135 forks source link

error while updating property 'mediaView' of a view managed by:RNGADNativeView null the specified child already has a parent. You must call removeView() on the child's parent first. #287

Closed deepakkumar089551 closed 1 month ago

deepakkumar089551 commented 2 years ago

when second time open same page then show error- error while updating property 'mediaView' of a view managed by:RNGADNativeView null the specified child already has a parent. You must call removeView() on the child's parent first.

deepakkumar089551 commented 2 years ago

critical issue please reply fast

ammarahm-ed commented 2 years ago

@deepakkumar089551 Share complete crash details from adb logcat. and it would be best if you can provide an example repository where i can test and fix it soon.

rakeshp947 commented 2 years ago

@ammarahm-ed Hi Ammar I think I'm having same problem please resolve my issue I have already created issue.

ammarahm-ed commented 2 years ago

@rakeshp947 if you can provide an example that can reproduce the issue, i will look into fixing it.

rakeshp947 commented 2 years ago

@ammarahm-ed I already provided you the complete logs, please have a look - here To reproduce this error add a video ad in the flatlist and scroll very fast till the end, it will happen.

rakeshp947 commented 2 years ago

@ammarahm-ed Any update on this??

MamoshiSE commented 1 year ago

Did anyone find solution for this? I am currently getting the crash: "Exception com.facebook.react.bridge.JSApplicationIllegalArgumentException: Error while updating property 'mediaview' of a view managed by: RNGADNativeView"

It's occuring very frequently for an high percentage of the app users.

luongminh2410dev commented 1 year ago

any update?

luongminh2410dev commented 1 year ago

work for me Add this code in node_modules/react-native-admob-native-ads/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNAdmobMediaView.java

     @Override
     protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        // Add this
        if(this != null){
            this.removeAllViews();
        }
     }
lean098 commented 1 year ago

any update?

lean098 commented 1 year ago

I generated a release version and installed it only on my phone, I did some tests and realized that the app crashes only when the ad is a video, when it renders an image, it works fine.

Using NativeMediaView of course, I can't show a capture or anything like that because this only happens in production, Mr. @luongminh2410dev solution didn't work for me, unfortunately!

Complete log:

Exception com.facebook.react.bridge.JSApplicationIllegalArgumentException: Error while updating property 'mediaview' of a view managed by: RNGADNativeView at com.facebook.react.uimanager.ViewManagersPropertyCache$PropSetter.updateViewProp (ViewManagersPropertyCache.java) at com.facebook.react.uimanager.ViewManagerPropertyUpdater$FallbackViewManagerSetter.setProperty (ViewManagerPropertyUpdater.java) at com.facebook.react.uimanager.ViewManagerPropertyUpdater.updateProps (ViewManagerPropertyUpdater.java) at com.facebook.react.uimanager.ViewManager.updateProperties at com.facebook.react.uimanager.NativeViewHierarchyManager.updateProperties (NativeViewHierarchyManager.java) at com.facebook.react.uimanager.UIViewOperationQueue$UpdatePropertiesOperation.execute (UIViewOperationQueue.java) at com.facebook.react.uimanager.UIViewOperationQueue$1.run (UIViewOperationQueue.java) at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches (UIViewOperationQueue.java) at com.facebook.react.uimanager.UIViewOperationQueue.access$2600 (UIViewOperationQueue.java) at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded (UIViewOperationQueue.java) at com.facebook.react.uimanager.GuardedFrameCallback.doFrame (GuardedFrameCallback.java) at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame (ReactChoreographer.java) at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame (ChoreographerCompat.java) at android.view.Choreographer$CallbackRecord.run (Choreographer.java:970) at android.view.Choreographer.doCallbacks (Choreographer.java:796) at android.view.Choreographer.doFrame (Choreographer.java:727) at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:957) at android.os.Handler.handleCallback (Handler.java:938) at android.os.Handler.dispatchMessage (Handler.java:99) at android.os.Looper.loop (Looper.java:250) at android.app.ActivityThread.main (ActivityThread.java:7851) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:958) Caused by java.lang.reflect.InvocationTargetException: at java.lang.reflect.Method.invoke at com.facebook.react.uimanager.ViewManagersPropertyCache$PropSetter.updateViewProp (ViewManagersPropertyCache.java) Caused by java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. at android.view.ViewGroup.addViewInner (ViewGroup.java:5235) at android.view.ViewGroup.addView (ViewGroup.java:5064) at android.view.ViewGroup.addView (ViewGroup.java:5036) at com.google.android.gms.ads.nonagon.ad.nativead.br.e (:com.google.android.gms.policy_ads_fdr_dynamite@233012805@233012802057.555274289.555274289:69) at com.google.android.gms.ads.nonagon.ad.nativead.br.d (:com.google.android.gms.policy_ads_fdr_dynamite@233012805@233012802057.555274289.555274289:2) at com.google.android.gms.ads.nonagon.ad.nativead.bp.run (:com.google.android.gms.policy_ads_fdr_dynamite@233012805@233012802057.555274289.555274289:254) at com.google.android.gms.ads.internal.util.future.c.execute (:com.google.android.gms.policy_ads_fdr_dynamite@233012805@233012802057.555274289.555274289:15) at com.google.android.gms.ads.internal.util.future.d.execute (:com.google.android.gms.policy_ads_fdr_dynamite@233012805@233012802057.555274289.555274289:3) at com.google.android.gms.ads.nonagon.ad.nativead.an.z (:com.google.android.gms.policy_ads_fdr_dynamite@233012805@233012802057.555274289.555274289:19) at com.google.android.gms.ads.nonagon.ad.nativead.an.y (:com.google.android.gms.policy_ads_fdr_dynamite@233012805@233012802057.555274289.555274289:28) at com.google.android.gms.ads.nonagon.ad.nativead.bn.bI (:com.google.android.gms.policy_ads_fdr_dynamite@233012805@233012802057.555274289.555274289:37) at com.google.android.gms.ads.internal.formats.client.l.bN (:com.google.android.gms.policy_ads_fdr_dynamite@233012805@233012802057.555274289.555274289:213) at m.aig.onTransact (:com.google.android.gms.policy_ads_fdr_dynamite@233012805@233012802057.555274289.555274289:21) at android.os.Binder.transact (Binder.java:1052) at com.google.android.gms.internal.ads.zzatj.zzbh (zzatj.java) at com.google.android.gms.internal.ads.zzben.zzbw (zzben.java) at com.google.android.gms.ads.nativead.NativeAdView.setNativeAd (NativeAdView.java) at com.ammarahmed.rnadmob.nativeads.RNAdmobNativeView.setNativeAd (RNAdmobNativeView.java) at com.ammarahmed.rnadmob.nativeads.RNAdmobNativeViewManager.setMediaView

luongminh2410dev commented 1 year ago

@lean098 Unfortunately, I encountered your same situation, but it worked for me I try to remove unfocused ads on the screen and when other ads show (which are videos), this avoids conflicts with the previous ads version:

My patch-package:

diff --git a/node_modules/react-native-admob-native-ads/android/build.gradle b/node_modules/react-native-admob-native-ads/android/build.gradle
index be307ad..c6a9c5b 100755
--- a/node_modules/react-native-admob-native-ads/android/build.gradle
+++ b/node_modules/react-native-admob-native-ads/android/build.gradle
@@ -55,7 +55,7 @@ dependencies {
     implementation 'com.facebook.react:react-native:+'
     implementation "com.google.android.gms:play-services-ads:${safeExtGet('googlePlayServicesAdsVersion', '20.+')}"
     implementation 'com.android.support:support-annotations:28.0.0'
-    implementation 'com.google.ads.mediation:facebook:6.+'
+    implementation 'com.google.ads.mediation:facebook:6.11.+'
     implementation 'androidx.appcompat:appcompat:1.2.0'
     implementation 'com.android.support.constraint:constraint-layout:2.0.4'
 }
\ No newline at end of file
diff --git a/node_modules/react-native-admob-native-ads/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNAdmobMediaView.java b/node_modules/react-native-admob-native-ads/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNAdmobMediaView.java
index d489ecf..2254f61 100644
--- a/node_modules/react-native-admob-native-ads/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNAdmobMediaView.java
+++ b/node_modules/react-native-admob-native-ads/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNAdmobMediaView.java
@@ -62,7 +62,9 @@ public class RNAdmobMediaView extends MediaView {
     @Override
     protected void onDetachedFromWindow() {
         super.onDetachedFromWindow();
-
+        if(this != null){
+            this.removeAllViews();
+        }
     }

     @Override
diff --git a/node_modules/react-native-admob-native-ads/ios/RNAdMobManager/RNAdMobUnifiedAdQueueWrapper.m b/node_modules/react-native-admob-native-ads/ios/RNAdMobManager/RNAdMobUnifiedAdQueueWrapper.m
index 2f4724a..21d86e1 100644
--- a/node_modules/react-native-admob-native-ads/ios/RNAdMobManager/RNAdMobUnifiedAdQueueWrapper.m
+++ b/node_modules/react-native-admob-native-ads/ios/RNAdMobManager/RNAdMobUnifiedAdQueueWrapper.m
@@ -75,7 +75,7 @@ -(instancetype)initWithConfig:(NSDictionary *)config repo:(NSString *)repo{

     //Set request options
     if ([config objectForKey:@"adChoicesPlacement"]){
-        [adPlacementOptions setPreferredAdChoicesPosition:((NSNumber *)[config objectForKey:@"adChoicesPlacement"]).intValue];
+        [adPlacementOptions setPreferredAdChoicesPosition: GADAdChoicesPositionTopRightCorner];
     }
     if ([config objectForKey:@"mediaAspectRatio"]){
         [adMediaOptions setMediaAspectRatio:((NSNumber *)[config objectForKey:@"mediaAspectRatio"]).intValue];
diff --git a/node_modules/react-native-admob-native-ads/react-native-admob-native-ads.podspec b/node_modules/react-native-admob-native-ads/react-native-admob-native-ads.podspec
index 7b92e8e..5c9e7d4 100755
--- a/node_modules/react-native-admob-native-ads/react-native-admob-native-ads.podspec
+++ b/node_modules/react-native-admob-native-ads/react-native-admob-native-ads.podspec
@@ -19,7 +19,7 @@ Pod::Spec.new do |s|
   # So instead we add the default location of the framework to the framework
   # search paths, and we rely on consumers of this library to add
   # Google-Mobile-Ads-SDK as a direct dependency.
-  s.weak_frameworks        = 'GoogleMobileAds', 'FacebookAdapter'
+  s.weak_frameworks        = 'GoogleMobileAds', 'MetaAdapter'
   s.pod_target_xcconfig    = {
     'FRAMEWORK_SEARCH_PATHS' => '"$(PODS_ROOT)/Google-Mobile-Ads-SDK/Frameworks/**" '\
                                 '"$(PODS_ROOT)/FBAudienceNetwork/**" '\
@@ -27,4 +27,5 @@ Pod::Spec.new do |s|
   }

   s.dependency 'React-Core'
+  s.dependency 'Google-Mobile-Ads-SDK', '~>9.12.0'
 end
lean098 commented 1 year ago

@luongminh2410dev Thanks man, I'll update my apps according to your patch

ammarahm-ed commented 1 month ago

Fixed in v0.7.5. @luongminh2410dev Thanks for the fix.