Skip to content
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

[Android] Ads won't load with location parameter in AdRequest #449

Closed
timhoffmannGIThub opened this issue Nov 25, 2021 · 2 comments
Closed
Assignees
Labels
bug Something isn't working e2-days Effort: < 5 days fixed Issue has been resolved and pull request linked p2-medium platform-android Android applications specifically

Comments

@timhoffmannGIThub
Copy link

Plugin Version

google_mobile_ads: 1.0.0

Steps to Reproduce

Get the User's location or use dummy data with the type LocationParams, like this:

LocationParams locationParams;
locationParams = LocationParams(
          accuracy: 5.0,
          longitude: 8.677343,
          latitude: 50.581060
      );

Implement the RewardedAd.load method like this:

RewardedAd.load(
        adUnitId: adUnit.adUnitID,
        request: AdRequest(
            location: locationParams,
        ),
        rewardedAdLoadCallback:
            RewardedAdLoadCallback(onAdLoaded: (RewardedAd ad) {
          _rewardedAdVideos[adUnit] = ad;
          print('(ads) Rewarded Video Ad for $adUnit loaded');
        }, onAdFailedToLoad: (LoadAdError error) {
          print('(ads) RewardedAd failed to load for $adUnit: $error');
        }));

So that the parameter location gets the information from our dummy data.

Expected results: Ads should load with the personalized information.

Actual results: On iOS it loads them correctly, on Android the ads won't load with an error failing to read the values.

Logs
E/DartMessenger(12021): Uncaught exception in binary message listener
E/DartMessenger(12021): java.lang.NullPointerException: Attempt to invoke virtual method 'long java.lang.Long.longValue()' on a null object reference
E/DartMessenger(12021): 	at io.flutter.plugins.googlemobileads.AdMessageCodec.readValueOfType(AdMessageCodec.java:337)
E/DartMessenger(12021): 	at io.flutter.plugins.googlemobileads.AdMessageCodec.readValueOfType(AdMessageCodec.java:240)
E/DartMessenger(12021): 	at io.flutter.plugin.common.StandardMessageCodec.readValue(StandardMessageCodec.java:333)
E/DartMessenger(12021): 	at io.flutter.plugin.common.StandardMessageCodec.readValueOfType(StandardMessageCodec.java:426)
E/DartMessenger(12021): 	at io.flutter.plugins.googlemobileads.AdMessageCodec.readValueOfType(AdMessageCodec.java:340)
E/DartMessenger(12021): 	at io.flutter.plugin.common.StandardMessageCodec.readValue(StandardMessageCodec.java:333)
E/DartMessenger(12021): 	at io.flutter.plugin.common.StandardMethodCodec.decodeMethodCall(StandardMethodCodec.java:48)
E/DartMessenger(12021): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231)
E/DartMessenger(12021): 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:84)
E/DartMessenger(12021): 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:865)
E/DartMessenger(12021): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/DartMessenger(12021): 	at android.os.MessageQueue.next(MessageQueue.java:335)
E/DartMessenger(12021): 	at android.os.Looper.loop(Looper.java:183)
E/DartMessenger(12021): 	at android.app.ActivityThread.main(ActivityThread.java:7656)
E/DartMessenger(12021): 	at java.lang.reflect.Method.invoke(Native Method)
E/DartMessenger(12021): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/DartMessenger(12021): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/flutter (12021): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method loadRewardedAd on channel plugins.flutter.io/google_mobile_ads)
E/flutter (12021): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:154:7)
E/flutter (12021): <asynchronous suspension>
E/flutter (12021): #1      RewardedAd.load (package:google_mobile_ads/src/ad_containers.dart:1218:5)
E/flutter (12021): <asynchronous suspension>
E/flutter (12021): 
@maheshj01 maheshj01 added the in triage Issue currently being evaluated label Nov 26, 2021
@maheshj01
Copy link
Collaborator

Hi @timhoffmannGIThub, Thanks for filing the issue. I am able to reproduce the issue. Ads don't load when the location is passed to AdRequest. This issue is only reproducible on Android and works fine on IOS.

code sample
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(home: AdSample());
  }
}

class AdSample extends StatefulWidget {
  const AdSample({Key? key}) : super(key: key);

  @override
  _AdSampleState createState() => _AdSampleState();
}

class _AdSampleState extends State<AdSample> {

  BannerAd? _bannerAd;
  bool _bannerAdIsLoaded = false;

  @override
  void initState() {
    super.initState();
    _bannerAd = BannerAd(
        size: AdSize.banner,
        adUnitId: Platform.isAndroid
            ? 'ca-app-pub-3940256099942544/6300978111'
            : 'ca-app-pub-3940256099942544/2934735716',
        listener: BannerAdListener(
          onAdLoaded: (Ad ad) {
            print('BannerAd loaded.');
            setState(() {
              _bannerAdIsLoaded = true;
            });
          },
          onAdFailedToLoad: (Ad ad, LoadAdError error) {
            print('BannerAd failedToLoad: $error');
            ad.dispose();
          },
          onAdOpened: (Ad ad) => print('BannerAd onAdOpened.'),
          onAdClosed: (Ad ad) => print('BannerAd onAdClosed.'),
        ),
        request: const AdRequest(
            location: LocationParams(
                accuracy: 5.0, longitude: 8.677343, latitude: 50.581060)))
      ..load();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Video player'),
      ),
      resizeToAvoidBottomInset: false,
      body: Container(
        height: 200,
        alignment: Alignment.center,
        child: _buildView(),
      ),
    );
  }

  Widget _buildView() {
    return Column(
      children: [
        _bannerAdView(),
      ],
    );
  }

  Widget _bannerAdView() {
    final BannerAd? bannerAd = _bannerAd;
    if (_bannerAdIsLoaded && bannerAd != null) {
      return SizedBox(
          height: bannerAd.size.height.toDouble(),
          width: bannerAd.size.width.toDouble(),
          child: AdWidget(ad: bannerAd));
    } else {
      return Container();
    }
  }

  @override
  void dispose() {
    _bannerAd?.dispose();
    super.dispose();
  }
 
}
flutter doctor -v
[✓] Flutter (Channel stable, 2.5.3, on macOS 12.0.1 21A559 darwin-arm, locale en-GB)
    • Flutter version 2.5.3 at /Users/mahesh/Documents/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18116933e7 (6 weeks ago), 2021-10-15 10:46:35 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/mahesh/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 13.1, Build version 13A1030d
    • CocoaPods version 1.10.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.2)
    • 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 11.0.8+10-b944.6916264)

[✓] IntelliJ IDEA Community Edition (version 2021.2.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 60.1.4
    • Dart plugin version 212.5080.8

[✓] VS Code (version 1.61.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.28.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 12.0.1 21A559 darwin-arm
    • Chrome (web)    • chrome • web-javascript • Google Chrome 96.0.4664.55

• No issues found!
logs
Launching lib/main.dart on Redmi K20 Pro in debug mode...
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
✓  Built build/app/outputs/flutter-apk/app-debug.apk.
W/FlutterActivityAndFragmentDelegate(21559): A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps.
Connecting to VM Service at ws://127.0.0.1:53802/R9UVWP9S-nQ=/ws
E/flutter (21559): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Null check operator used on a null value
E/flutter (21559): #0      MethodChannel.binaryMessenger
E/flutter (21559): #1      MethodChannel._invokeMethod
E/flutter (21559): #2      MethodChannel.invokeMethod
E/flutter (21559): #3      PlatformViewsService.synchronizeToNativeViewHierarchy
E/flutter (21559): #4      main
E/flutter (21559): #5      _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:145:25)
E/flutter (21559): #6      _rootRun (dart:async/zone.dart:1428:13)
E/flutter (21559): #7      _CustomZone.run (dart:async/zone.dart:1328:19)
E/flutter (21559): #8      _runZoned (dart:async/zone.dart:1863:10)
E/flutter (21559): #9      runZonedGuarded (dart:async/zone.dart:1851:12)
E/flutter (21559): #10     _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:141:5)
E/flutter (21559): #11     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:283:19)
E/flutter (21559): #12     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
E/flutter (21559):
D/SurfaceView(21559): UPDATE null, mIsCastMode = false
I/ple.ads_exampl(21559): ProcessProfilingInfo new_methods=1123 is saved saved_to_disk=1 resolve_classes_delay=8000
W/Looper  (21559): PerfMonitor doFrame : time=638ms vsyncFrame=13195823 latency=14ms procState=2 historyMsgCount=1
E/DartMessenger(21559): Uncaught exception in binary message listener
E/DartMessenger(21559): java.lang.NullPointerException: Attempt to invoke virtual method 'long java.lang.Long.longValue()' on a null object reference
E/DartMessenger(21559): 	at io.flutter.plugins.googlemobileads.AdMessageCodec.readValueOfType(AdMessageCodec.java:337)
E/DartMessenger(21559): 	at io.flutter.plugins.googlemobileads.AdMessageCodec.readValueOfType(AdMessageCodec.java:240)
E/DartMessenger(21559): 	at io.flutter.plugin.common.StandardMessageCodec.readValue(StandardMessageCodec.java:333)
E/DartMessenger(21559): 	at io.flutter.plugin.common.StandardMessageCodec.readValueOfType(StandardMessageCodec.java:426)
E/DartMessenger(21559): 	at io.flutter.plugins.googlemobileads.AdMessageCodec.readValueOfType(AdMessageCodec.java:340)
E/DartMessenger(21559): 	at io.flutter.plugin.common.StandardMessageCodec.readValue(StandardMessageCodec.java:333)
E/DartMessenger(21559): 	at io.flutter.plugin.common.StandardMethodCodec.decodeMethodCall(StandardMethodCodec.java:48)
E/DartMessenger(21559): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231)
E/DartMessenger(21559): 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:84)
E/DartMessenger(21559): 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:865)
E/DartMessenger(21559): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/DartMessenger(21559): 	at android.os.MessageQueue.next(MessageQueue.java:335)
E/DartMessenger(21559): 	at android.os.Looper.loop(Looper.java:193)
E/DartMessenger(21559): 	at android.app.ActivityThread.main(ActivityThread.java:8061)
E/DartMessenger(21559): 	at java.lang.reflect.Method.invoke(Native Method)
E/DartMessenger(21559): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
E/DartMessenger(21559): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
E/flutter (21559): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method loadBannerAd on channel plugins.flutter.io/google_mobile_ads)
E/flutter (21559): #0      MethodChannel._invokeMethod
E/flutter (21559): <asynchronous suspension>
E/flutter (21559): #1      BannerAd.load
E/flutter (21559): <asynchronous suspension>
E/flutter (21559):

@maheshj01 maheshj01 added bug Something isn't working e2-days Effort: < 5 days p2-medium platform-android Android applications specifically and removed in triage Issue currently being evaluated labels Nov 26, 2021
@maheshj01 maheshj01 changed the title (Android) Ads won't load with 'location' parameter [Android] Ads won't load with 'location' parameter in AdRequest Nov 26, 2021
@maheshj01 maheshj01 changed the title [Android] Ads won't load with 'location' parameter in AdRequest [Android] Ads won't load with location parameter in AdRequest Nov 26, 2021
@jjliu15 jjliu15 self-assigned this Dec 1, 2021
@jjliu15
Copy link
Collaborator

jjliu15 commented Dec 2, 2021

Should be fixed by #452, in v1.0.1

@jjliu15 jjliu15 closed this as completed Dec 2, 2021
@maheshj01 maheshj01 added the fixed Issue has been resolved and pull request linked label Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working e2-days Effort: < 5 days fixed Issue has been resolved and pull request linked p2-medium platform-android Android applications specifically
Projects
None yet
Development

No branches or pull requests

3 participants