error: cannot find symbol FirebaseAdMobPlugin.registerNativeAdFactory(flutterEngine, "moviesTorrentAdFactory", NativeAdFactoryExample());

Viewed 618

I'm using flutter , and I tried to use Native Ads following this doc

all ads are working fine but Native ad doesn't work and it fails building the app showing this error

error: cannot find symbol FirebaseAdMobPlugin.registerNativeAdFactory(flutterEngine, "moviesTorrentAdFactory", NativeAdFactoryExample());

this is MyActivity.java file :

package tech.devm.movies_torrent;

import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.firebaseadmob.FirebaseAdMobPlugin;

import com.google.android.gms.ads.formats.UnifiedNativeAd;
import com.google.android.gms.ads.formats.UnifiedNativeAdView;
import io.flutter.plugins.firebaseadmob.FirebaseAdMobPlugin.NativeAdFactory;
import java.util.Map;

public class MainActivity extends FlutterActivity {
  @Override
  public void configureFlutterEngine(FlutterEngine flutterEngine) {
    flutterEngine.getPlugins().add(new FirebaseAdMobPlugin());

    FirebaseAdMobPlugin.registerNativeAdFactory(flutterEngine, "moviesTorrentAdFactory", NativeAdFactoryExample());
  }

  @Override
  public void cleanUpFlutterEngine(FlutterEngine flutterEngine) {
    FirebaseAdMobPlugin.unregisterNativeAdFactory(flutterEngine, "moviesTorrentAdFactory");
  }
}




class NativeAdFactoryExample implements NativeAdFactory {
  @Override
  public UnifiedNativeAdView createNativeAd(
      UnifiedNativeAd nativeAd, Map<String, Object> customOptions) {
    // Create UnifiedNativeAdView
  }
}

is there should be any changes to Manifest.xml file ? or am I missing something ? I've cleared the build using (flutter clean ) many times but nothing works any help would be much appreciated

1 Answers

I was also having the exact same issue. This is how I fix it!

Seems that this error is related with the NativeAdFactory file (eg: ListTileNativeAdFactory.java) and the layout at app/src/main/res/layout/list_title_native_ad.xml

If you go to the Google Codelabs example at https://github.com/googlecodelabs/admob-inline-ads-in-flutter/tree/main/complete and copy those files exactly like the example you will solve that problem.

Related