java.lang.InstantiationError: com.google.android.gms.ads.rewarded.RewardedAd
See original GitHub issueThis is a strange error and I have tried many things to fix it for the last 3 days without any success.
Please note that it was WORKING and the App is live for more than a few months now, so all the credentials are correct and I have re-checked it many times.
So I don’t know exactly what happened but I have no other place to find solution that I finally post an issue here. I hope someone could help to give me pointers.
The moment rewardedAd.load()
is called, the app crashed with error message as follows:
E/AndroidRuntime(27180): FATAL EXCEPTION: main
E/AndroidRuntime(27180): Process: com.me.app, PID: 27180
E/AndroidRuntime(27180): java.lang.InstantiationError: com.google.android.gms.ads.rewarded.RewardedAd
E/AndroidRuntime(27180): at io.flutter.plugins.googlemobileads.FlutterRewardedAd.createRewardedAd(FlutterRewardedAd.java:154)
E/AndroidRuntime(27180): at io.flutter.plugins.googlemobileads.FlutterRewardedAd.load(FlutterRewardedAd.java:95)
E/AndroidRuntime(27180): at io.flutter.plugins.googlemobileads.GoogleMobileAdsPlugin.onMethodCall(GoogleMobileAdsPlugin.java:330)
E/AndroidRuntime(27180): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/AndroidRuntime(27180): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/AndroidRuntime(27180): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
E/AndroidRuntime(27180): at android.os.MessageQueue.nativePollOnce(Native Method)
E/AndroidRuntime(27180): at android.os.MessageQueue.next(MessageQueue.java:336)
E/AndroidRuntime(27180): at android.os.Looper.loop(Looper.java:197)
E/AndroidRuntime(27180): at android.app.ActivityThread.main(ActivityThread.java:8167)
E/AndroidRuntime(27180): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(27180): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
E/AndroidRuntime(27180): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
I/Process (27180): Sending signal. PID: 27180 SIG: 9
In my code:
MobileAds.instance.initialize()
is called in main.dart
and once the initialization is done the RewardedAd
is being initialized like this:
_rewardedAd = RewardedAd(
adUnitId: AdManager.rewardedAdUnitId,
listener: AdListener(
onRewardedAdUserEarnedReward: (RewardedAd ad, RewardItem reward) {
print('Rewarded Ad successful: $ad reward: $reward');
// Give reward to user
},
onAdLoaded: (Ad ad) {
setState(() {
isAdsLoading = false;
});
},
onAdFailedToLoad: (Ad ad, LoadAdError error) {
print('Error Rewarded Video Ad failed to load: $error');
},
),
request: AdRequest())
..load();
If I remove the ..load()
it won’t crash but it won’t ever load. Once again, this didn’t crash before.
What I have done to fix this:
- I have rechecked all the credentials: App ID and Ad unit Id are all correct.
- Go through the documentations again to make sure my
AndroidManifest.xml
are correctly set. - Tried both versions 0.12.1+1 and 0.11.0+4
- Tried both debug and release mode
- Tried both in Android Virtual Device and real device.
- There are many others that I don’t remember anymore.
Note: The live version is working fine. And I have tried to upload the app to Closed Testing release, but it still crashed.
Plugin Version
version ^0.12.1+1
Steps to Reproduce
I’m not sure how to reproduce this. Because everything was working and the app is live without problems until 3 days ago.
- Initialize:
MobileAds.instance.initialize()
- Initialize RewardedAds
- Call
rewardedAds.load()
Expected results: Shouldn’t crash and shows the ad
Actual results:
It crashes, the app closed and there was no exception caught except the FATAL EXCEPTION
message
Logs
It is a long log, so I only include the error part here, but you can read all the full log here
[ +35 ms] E/AndroidRuntime(31757): FATAL EXCEPTION: main
[ ] E/AndroidRuntime(31757): Process: com.me.app, PID: 31757
[ ] E/AndroidRuntime(31757): java.lang.InstantiationError:
com.google.android.gms.ads.rewarded.RewardedAd
[ ] E/AndroidRuntime(31757): at
io.flutter.plugins.googlemobileads.FlutterRewardedAd.createRewardedAd(FlutterRewardedAd.java:154)
[ ] E/AndroidRuntime(31757): at
io.flutter.plugins.googlemobileads.FlutterRewardedAd.load(FlutterRewardedAd.java:95)
[ ] E/AndroidRuntime(31757): at
io.flutter.plugins.googlemobileads.GoogleMobileAdsPlugin.onMethodCall(GoogleMobileAdsPlugin.java:330)
[ ] E/AndroidRuntime(31757): at
io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
[ ] E/AndroidRuntime(31757): at
io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
[ ] E/AndroidRuntime(31757): at
io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
[ ] E/AndroidRuntime(31757): at android.os.MessageQueue.nativePollOnce(Native Method)
[ ] E/AndroidRuntime(31757): at android.os.MessageQueue.next(MessageQueue.java:336)
[ ] E/AndroidRuntime(31757): at android.os.Looper.loop(Looper.java:197)
[ ] E/AndroidRuntime(31757): at android.app.ActivityThread.main(ActivityThread.java:8167)
[ ] E/AndroidRuntime(31757): at java.lang.reflect.Method.invoke(Native Method)
[ ] E/AndroidRuntime(31757): at
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
[ ] E/AndroidRuntime(31757): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
[ +33 ms] I/Process (31757): Sending signal. PID: 31757 SIG: 9
[ +261 ms] Service protocol connection closed.
[ ] Lost connection to device.
[ +2 ms] executing: /Volumes/ME/Applications/Android/sdk/platform-tools/adb -s 5a53414a33573398 forward
--list
[ +11 ms] Exit code 0 from: /Volumes/ME/Applications/Android/sdk/platform-tools/adb -s 5a53414a33573398
forward --list
[ ] 5a53414a33573398 tcp:59154 tcp:34485
[ +1 ms] executing: /Volumes/ME/Applications/Android/sdk/platform-tools/adb -s 5a53414a33573398 forward
--remove tcp:59154
[ +13 ms] DevFS: Deleting filesystem on the device
(file:///data/user/0/com.me.app/code_cache/my_appCGPZRY/my_app/)
[ +257 ms] Ignored error while cleaning up DevFS: TimeoutException after 0:00:00.250000: Future not completed
[ +3 ms] executing: /Volumes/ME/Applications/Android/sdk/platform-tools/adb -s 5a53414a33573398 forward
--list
[ +16 ms] Exit code 0 from: /Volumes/ME/Applications/Android/sdk/platform-tools/adb -s 5a53414a33573398
forward --list
[ +2 ms] "flutter run" took 140,682ms.
[ +4 ms] Running shutdown hooks
[ ] Shutdown hook priority 4
[ +1 ms] Shutdown hooks complete
[ ] exiting with code 0
Analyzing my_app...
No issues found! (ran in 6.1s)
[✓] Flutter (Channel stable, 2.0.5, on macOS 11.2.2 20D80 darwin-x64, locale en-US)
• Flutter version 2.0.5 at /Users/ME/development/flutter
• Framework revision adc687823a (12 days ago), 2021-04-16 09:40:20 -0700
• Engine revision b09f014e96
• Dart version 2.12.3
• Pub download mirror https://pub.flutter-io.cn
• Flutter download mirror https://storage.flutter-io.cn
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /Volumes/ME/Applications/Android/sdk
• Platform android-30, build-tools 30.0.2
• ANDROID_HOME = /Volumes/ME/Applications/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.4, Build version 12D4e
• CocoaPods version 1.10.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
[✓] VS Code (version 1.55.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.8.0
[✓] Connected device (3 available)
• SM G960U1 (mobile) • 5a5341 • android-arm64 • Android 10 (API 29)
• ME iPho (mobile) • b3ebbe938628 • ios • iOS 14.4.2
• Chrome (web) • chrome • web-javascript • Google Chrome
90.0.4430.85
• No issues found!
Issue Analytics
- State:
- Created 2 years ago
- Comments:11
Top GitHub Comments
@zenkog can you try changing
com.google.android.gms:play-services-ads:19.8.0
tocom.google.android.gms:play-services-ads:19.7.0
in your app/build.gradle?So For now the workaround is by downgrading to:
com.google.android.gms:play-services-ads:19.7.0
inapp/build.gradle
.I will close this issue for now and if someone else still facing issue we can re-open it Thanks