-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AdManagerBannerAd flickering and fails to display in Android Samsung #1229
Comments
Adding one more video on other device. Screen_Recording_20250115_140426_BNR.dev.mp4 |
Recording it in the camera rather than in the phone shows more problems, specially when going bottom to top. However, my main concern is with the Samsung A51 where they do not show at all. VID-20250115-WA0005.mp4 |
Hi @memoriasIT, it appears your calling What if you loaded those ads only once and passed in the loaded ad to the appropriate ad index ? That may help with your performance issues |
I did modify the code so the elements are preloaded. I also tried wrapping the ad with RepaintBoundary just in case, but it did nothing. I don't have access to the Samsung A51 at the moment, but this is a video of a Samsung S20. The "artifacts" are more clear at the end of the video: WhatsApp.Video.2025-01-15.at.18.25.49.mp4I will try to get a video of the A51 running this tomorrow morning (GMT timezone), but I don't think this will fix it. Codeimport 'dart:async';
import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(
const MaterialApp(
home: GoogleAdsTest(),
),
);
}
class GoogleAdsTest extends StatefulWidget {
const GoogleAdsTest({super.key});
@override
State<GoogleAdsTest> createState() => _GoogleAdsTestState();
}
class _GoogleAdsTestState extends State<GoogleAdsTest> {
final Map<int, AdManagerBannerAd> _loadedAds = {};
final Map<int, bool> _adLoadStatus = {};
final int _adFrequency = 10;
@override
void initState() {
super.initState();
unawaited(_preloadAds());
}
@override
void dispose() {
// Dispose of all loaded ads to release resources
for (final ad in _loadedAds.values) {
unawaited(ad.dispose());
}
super.dispose();
}
Future<void> _preloadAds() async {
for (var i = _adFrequency - 1; i < 50; i += _adFrequency) {
await _loadAd(i);
}
}
Future<void> _loadAd(int index) async {
if (_loadedAds.containsKey(index)) return;
final ad = AdManagerBannerAd(
adUnitId: 'ca-app-pub-3940256099942544/9214589741',
request: const AdManagerAdRequest(),
sizes: [const AdSize(width: 320, height: 250)],
listener: AdManagerBannerAdListener(
onAdLoaded: (ad) {
setState(() {
_loadedAds[index] = ad as AdManagerBannerAd;
_adLoadStatus[index] = true;
});
},
onAdFailedToLoad: (ad, error) {
debugPrint('Ad failed to load at index $index: $error');
ad.dispose();
setState(() {
_adLoadStatus[index] = false;
});
},
),
);
await ad.load();
}
Widget _buildAd(int index) {
final ad = _loadedAds[index];
final isLoaded = _adLoadStatus[index] ?? false;
if (ad != null && isLoaded) {
return SizedBox(
width: 320,
height: 250,
child: AdWidget(ad: ad),
);
}
return const SizedBox.shrink();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
itemCount: 50,
itemBuilder: (context, index) {
if ((index + 1) % _adFrequency == 0) {
return _buildAd(index);
}
return Container(
height: 50,
color: index.isOdd ? Colors.red : Colors.blue,
alignment: Alignment.center,
margin: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
child: Text(
'Item ${index + 1}',
style: const TextStyle(color: Colors.white, fontSize: 18),
),
);
},
),
);
}
}
</details> ``` |
Hi @memoriasIT, this looks a lot better. I see some lagging around |
I came across this thread with a lot of people having problems with One UI 4.x, so I upgraded the Samsung S20 to 5.1 I will ask the client (Samsung A51) tomorrow for their One UI version and maybe an upgrade makes it better for them. Thanks for the help until now by the way :) Samsung S20 on profile mode: WhatsApp.Video.2025-01-15.at.19.57.01.1.mp4 |
I talked with two colleagues having issues with the ads and having Samsung A51s. I am a bit out of ideas now ☹ |
Hi @memoriasIT, considering this only happens on some but not all devices, the issue doesn't appear to be directly related to a feasible action item for the google_mobile_ads flutter plugin. Preloading the banner ads did see improvement in the scrolling performance. With Android, some devices are less performant than others which may affect app behavior. For example, the Samsung A51 is an older device from 2020 and banner ads each contain a webview which are very task-heavy objects. As far as addressing the banner ad not appearing at all, is that something that has been resolved with preloading the ads? |
Unfortunately it does not get fixed with these changes... :( |
I see. For the banner issue of it not appearing, to double check is this reproducible only on certain devices? Or others? If so, can you share the ad request and response from ad inspector so I can take a closer look? To confirm if it is a Flutter issue |
Unfortunately I don't have more android phones to test, but it is reproducible on multiple A51s I can try to provide more data on Monday |
I just tested on a Samsung A53 with android 14 and One UI: 6.1 |
We did some investigation with the phone. We discovered that the problem is with the rendering. Searching for problems on the Flutter SDK will show the issue I recorded on my first video. From the package standpoint I am not sure how much can be solved, perhaps making the Ad Inspector Skia compatible so it can be used on older hardware. Nice thread with the black screen issue (what I get when opening ad inspector): Problems with Web Views with Impeller (Glitches like in the first video I posted here): flutter/flutter#160804 (comment)
Some other devices you can find in other issues: flutter/flutter#159834 (comment)
|
Hi @memoriasIT, thank you for taking a closer look in to this. We also have noticed for some that disabling impeller improves ad rendering #1171 (comment) and that older devices have seen performance issues relative to newer devices. It's been well documented as you've shared that a lot of these issues are related to the Flutter SDK and not something that the google mobile ads plugin can resolve. I've shared with @LTPhantom that ad inspector is a black screen for your environment. I think we can close this ticket out as we've identified workarounds for these Flutter SDK limitations. |
Environment
Flutter 3.27.2 on macOS, compiling to android as APK.
See Flutter doctor at the end for more info.
Plugin Version
5.2.0
Describe the problem
Using a minimal implementation of an AdManagerBannerAd in a ListView the ads flicker and don't show in the phone "Samsung Galaxy A51, with Android 13". The issue doesn't seem to appear in iOS (or at least not in the iPhones I tried with).
Other phones that I tested it with:
It will also behave fine in emulators. Here I provide two videos:
Emulator (works fine)
https://github.com/user-attachments/assets/6d4dd790-ddaf-43e1-bdd8-a64a20ade839
Failing to work (Samsung Galaxy A51) |
Screen_recording_20250115_133226.mp4
Steps to Reproduce
Expected results:
The ads load without any issues.
Actual results:
The ads don't show and there are artifacts in Samsung Galaxy A51.
Other relevant information
I tried with Flutter 3.27.1 and 3.27.2
I also tried with a fork of the package and updating the webview related dependencies. But it also did not work:
https://github.com/memoriasIT/googleads-mobile-flutter/blob/patch-1/packages/google_mobile_ads/pubspec.yaml
Code
Logs
Unfortunately I am not able to provide logs from the Samsung Galaxy A51 as it's the client's phone.
But here I provide the logs for the android emulator.
Logs
The text was updated successfully, but these errors were encountered: