question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fatal Exception: java.lang.LinkageError

See original GitHub issue

Firebase crash analytics is reporting the following error on android devices

Fatal Exception: java.lang.LinkageError: Method java.lang.Object com.google.android.gms.internal.ads.jo3.zzb() overrides final method in class Lcom/google/android/gms/internal/ads/bo3; (declaration of 'com.google.android.gms.internal.ads.jo3' appears in base.apk)
       at com.google.android.gms.internal.ads.zzcpr.<init>(zzcpr.java:310)
       at com.google.android.gms.internal.ads.zzcpq.zza(zzcpq.java:103)
       at com.google.android.gms.internal.ads.zzevk.zza(zzevk.java:365)
       at com.google.android.gms.internal.ads.zzeke.zzN(zzeke.java:58)
       at com.google.android.gms.internal.ads.zzeke.zze(zzeke.java:6)
       at com.google.android.gms.internal.ads.zzbhd.zzg(zzbhd.java:203)
       at com.google.android.gms.ads.BaseAdView.loadAd(BaseAdView.java:6)
       at io.flutter.plugins.googlemobileads.FlutterBannerAd.load(FlutterBannerAd.java:60)
       at io.flutter.plugins.googlemobileads.GoogleMobileAdsPlugin.onMethodCall(GoogleMobileAdsPlugin.java:737)
       at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:17)
       at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:18)
       at io.flutter.embedding.engine.dart.DartMessenger.lambda$handleMessageFromDart$0(DartMessenger.java:20)
       at io.flutter.embedding.engine.dart.DartMessenger.lambda$handleMessageFromDart$0$DartMessenger(DartMessenger.java)
       at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$6ZD1MYkhaLxyPjtoFDxe45u43DI.run(-.java:12)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:246)
       at android.app.ActivityThread.main(ActivityThread.java:8550)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

This is the line it errors on

at io.flutter.plugins.googlemobileads.FlutterBannerAd.load(FlutterBannerAd.java:60)

on the following devices

image

Im am using google_mobile_ads google_mobile_ads: ^1.0.1

and Flutter 2.8.0

Edit:

This is our statefull widget

class MyBannerAd extends StatefulWidget {
  const MyBannerAd();

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

class _MyBannerAdState extends State<MyBannerAd> {
  late AdSize adSize;
  late AdMobRepository adRepository;
  late AnalyticsRepository analyticsRepository;
  bool adLoaded = false;
  BannerAd? anchoredBanner;

  @override
  void initState() {
    super.initState();
    adRepository = context.read<AdMobRepository>();
    analyticsRepository = context.read<AnalyticsRepository>();

    if (SizerUtil.deviceType != DeviceType.mobile && SizerUtil.orientation == Orientation.portrait) {
      adSize = AdSize.leaderboard;
    } else {
      adSize = AdSize.largeBanner;
    }

    final bannerAd = adRepository.getBannerAd(
      size: adSize,
      onFailedLoad: (ad, error) {
        print('banner ad failed to load: $error');
        ad.dispose();
      },
      onLoad: (ad) {
        setState(() {
          adLoaded = true;
          anchoredBanner = ad as BannerAd?;
        });
      },
      onAdImpression: (_) {
        analyticsRepository.sendBannerAdShownEvent();
      },
      onAdOpened: (_) {
        analyticsRepository.sendBannerAdClickEvent();
      },
    );

    bannerAd.load();
  }

  @override
  void dispose() {
    super.dispose();
    anchoredBanner?.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<SubscriptionBloc, SubscriptionState>(
      builder: (context, state) {
        final isLoaded = !adLoaded;

        if (isLoaded || state.hasSubscribed || anchoredBanner == null) return SizedBox.shrink();

        return Container(
          color: Colors.transparent,
          width: anchoredBanner!.size.width.toDouble(),
          height: anchoredBanner!.size.height.toDouble(),
          child: Center(
            child: Container(
              color: Colors.white,
              child: AdWidget(
                ad: anchoredBanner!,
              ),
            ),
          ),
        );
      },
    );
  }
}

And this is the repo

class AdMobRepository {
  late String _releaseBannerAdId;
  late String _releaseInterstitualAdId;
  late String _releaseRewardedAdId;

  AdMobRepository() {
    if (Platform.isAndroid) {
      _releaseBannerAdId = Constants.androidBannedAdId;
      _releaseInterstitualAdId = Constants.androidInterstitualAdId;
      _releaseRewardedAdId = Constants.androidRewardedAdId;
    } else if (Platform.isIOS) {
      _releaseBannerAdId = Constants.iosBannerAdId;
      _releaseInterstitualAdId = Constants.iosInterstitualAdId;
      _releaseRewardedAdId = Constants.iosRewardedAdId;
    } else {
      _releaseBannerAdId = "";
      _releaseInterstitualAdId = "";
      _releaseRewardedAdId = "";
    }
  }

  BannerAd getBannerAd({
    required AdSize size,
    void Function(Ad, LoadAdError)? onFailedLoad,
    void Function(Ad)? onLoad,
    void Function(Ad)? onAdOpened,
    void Function(Ad)? onAdImpression,
  }) {
    return BannerAd(
      adUnitId: kReleaseMode ? _releaseBannerAdId : BannerAd.testAdUnitId,
      request: AdRequest(),
      size: size,
      listener: BannerAdListener(
        onAdFailedToLoad: onFailedLoad ?? onFailedLoadFallback,
        onAdLoaded: onLoad,
        onAdImpression: onAdImpression,
        onAdOpened: onAdOpened,
      ),
    );
  }

  void onFailedLoadFallback(Ad ad, LoadAdError error) {
    ad.dispose();
  }

  void getInterstitualAd({required void Function(LoadAdError) onFailedLoad, void Function(InterstitialAd)? onLoad}) {
    InterstitialAd.load(
      adUnitId: kReleaseMode ? _releaseInterstitualAdId : InterstitialAd.testAdUnitId,
      request: AdRequest(),
      adLoadCallback: InterstitialAdLoadCallback(
        onAdLoaded: onLoad ?? onInterstitialAdLoadedFallback,
        onAdFailedToLoad: onFailedLoad,
      ),
    );
  }

  void onInterstitialAdLoadedFallback(InterstitialAd ad) {
    ad.fullScreenContentCallback = FullScreenContentCallback(
      onAdDismissedFullScreenContent: (ad) => ad.dispose(),
      onAdFailedToShowFullScreenContent: (ad, error) => ad.dispose(),
    );
  }

  void getRewardAd({required String userId, required void Function(LoadAdError) onFailedLoad, void Function(RewardedAd)? onLoad}) {
    RewardedAd.load(
      adUnitId: kReleaseMode ? _releaseRewardedAdId : RewardedAd.testAdUnitId,
      request: AdRequest(),
      rewardedAdLoadCallback: RewardedAdLoadCallback(
        onAdLoaded: onLoad ?? onRewardedAdLoadedFallback,
        onAdFailedToLoad: onFailedLoad,
      ),
      serverSideVerificationOptions: ServerSideVerificationOptions(userId: userId),
    );
  }

  void onRewardedAdLoadedFallback(RewardedAd ad) {
    ad.fullScreenContentCallback = FullScreenContentCallback(
      onAdDismissedFullScreenContent: (ad) => ad.dispose(),
      onAdFailedToShowFullScreenContent: (ad, error) => ad.dispose(),
    );
  }
}

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:26
  • Comments:53

github_iconTop GitHub Comments

7reactions
Pielgrincommented, Jan 19, 2022

I fixed it ! For me the solution was to update app/build.gradle and explicitly this line :

classpath 'com.android.tools.build:gradle:4.1.1' to classpath 'com.android.tools.build:gradle:4.2.2'

3reactions
Tobias-Kellercommented, Sep 20, 2022

Getting the same crashes with Flutter (Channel stable, 3.3.0) and google_mobile_ads 2.0.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flutter - Fatal Exception: java.lang.LinkageError - Stack Overflow
I've a Flutter app project and just for some users (7% of my user base) the app crash and Play Store is reporting...
Read more >
Fatal Exception: java.lang.VerifyError or java.lang.LinkageError
I was facing this issue when i was creating release apk with progurad. Due to proguard, method name was conflicting. stack track for...
Read more >
Fatal Exception: java.lang.LinkageError with Flutter and AdMob
I upgraded the Google Mobile Ads SDK in my app a couple of weeks ago and I started noticing lately that I'm getting...
Read more >
LinkageError - Android Developers
android.app.appsearch.observer. Overview. Interfaces. ObserverCallback. Classes. DocumentChangeInfo · ObserverSpec · ObserverSpec.Builder · SchemaChangeInfo.
Read more >
How to resolved Linkage error - HCL support
java.lang.LinkageError: loading constraint violation. Websphere server is not using the expected class loader to load class, hence this this exception is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found