Hi,
I'm getting these crashes from users.
Fatal Exception: java.lang.IllegalStateException: The ad unit ID can only be set once on InterstitialAd.
at com.google.android.gms.ads.internal.client.zzac.setAdUnitId(Unknown Source)
at com.google.android.gms.ads.InterstitialAd.setAdUnitId(Unknown Source)
at com.sbugert.rnadmob.RNAdMobInterstitialAdModule.setAdUnitID(RNAdMobInterstitialAdModule.java:88)
However, I'm only setting in the componentDidMount of my main component. There is one component above it though if that makes a difference? Perhaps I need to setAdUnitId there?
Thanks,
Daniel
I don't know you component hierarchy but it clearly means that componentDidMount is called twice.
Move setAdUnitID to the root component or move it out of the component lifecycle (e.g. call it right after importing).
@sbugert I set it to the root componentDidMount but it still gives the error. So it's fine calling it right after importing?
I have the same issue, and I have the setAdUnitID in the root componentDidMount.
It happens when you go back with the android back button. And when you try to start again the app, it fails.
Same issue for me too. Try catch statement can not work when setting ad unit id inside react-native codes. Error is coming from RNAdMobInterstitialAdModule.java file.
I have added unit id at root. It is fine. but after minimize app and call back to open, this error is throwing up.
Anything to fix?
I'm having the same error, I'm setting the ad unit on componentDidMount in my root component. Several users are experimenting this issue, is there a solution ?
Thanks!
I found a temporary solution @macuna . Open RNAdMobInterstitialAdModule.java file from node_modules\react-native-admob\android\src\main\java\com\sbugert\rnadmob. Add try cache statement into the setAdUnitID method.
@ReactMethod
public void setAdUnitID(String adUnitID) {
try {
mInterstitialAd.setAdUnitId(adUnitID);
} catch (Exception ex) {
String error = "error";
}
}
Most helpful comment
I found a temporary solution @macuna . Open RNAdMobInterstitialAdModule.java file from node_modules\react-native-admob\android\src\main\java\com\sbugert\rnadmob. Add try cache statement into the setAdUnitID method.