Feral Cat

Building just because.

Invariant Violation: requireNativeComponent: “RNGADBannerView” was not found in the UIManager.

Happen to be getting the Invariant Violation: requireNativeComponent: “RNGADBannerView” was not found in the UIManager error? Did you use the really useful react-native-admob lib at some point, remove it, but are still getting this weird error? Maybe you’re using another lib, removed it, and are getting a similar error? I spent nearly three full days trying to iron this out! Hopefully I’ll save you some time.

Recreating my Problem

So, recreating the problem. My error would only show itself when I ran the android version of my app in release mode. I did that using the following.

react-native run-android --variant=release

So this was especially annoying. I was naive to believe that the dev and release versions would be behave similarly.

What I Initially Tried

I even went as far as using Firebase’s Test Lab to see if it would point me towards the problematic code. Surprise, surprise. Firebase told all was good. But users and friends were telling me other wise!

So, my first reaction was to search my project for any remnants of the react-native-admob lib. I found some info in the index.android.bundle file located at yourproject/android/app/src/main/assets. I tried to hack away the problematic code manually but eventually gave up when I came across more errors.

My next attempt assumed that I had incorrectly cut out react-native-admob. I went through it’s installation instructions backwards hoping to catch some random piece of code I had left lying around. Again, nada.

Keep in mind that after each and every attempt at resolving the problem I’d blow away my local instance of my application and start over by cloning it. I didn’t want to introduce more problems.

Next, I tried updating everything in my application. I tried clearing my watchman caches, npm’s caches, deleting my package.json, deleting my node modules. NOTHING WORKED.

What I Found

So after literally 24 hours of being stumped I decided to revisit where I found the only instance of RNGADBannerView, the index.android.bundle. Instead of hacking away at the file I decided to do research on how to recreate the file. I found the following command during that research.

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

Solution

  1. Delete the index.android.bundle
  2. Execute the following command from the root of the project.
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

After that, I ran react-native run-android –version=release and all was good! Happy coding!

Leave a Reply

Your email address will not be published. Required fields are marked *