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.

NativeAdError, Can't find NativeAdFactory with id

See original GitHub issue

Plugin Version

google_mobile_ads: ^0.13.0

Hi, I am facing this error on flutter native ads (android) PlatformException(NativeAdError, Can't find NativeAdFactory with id: homeScreen, null, null)

this is my HomeScreenNativeAd.kt file

class HomeScreenNativeAd(val context: Context) : GoogleMobileAdsPlugin.NativeAdFactory {

    override fun createNativeAd(
            nativeAd: NativeAd,
            customOptions: MutableMap<String, Any>?
    ): NativeAdView {
        val homeScreenNativeView = LayoutInflater.from(context)
                .inflate(R.layout.home_screen_native_ad, null) as NativeAdView

        with(homeScreenNativeView) {
            val attributionViewSmall =
                    findViewById<TextView>(R.id.tv_home_item_native_ad_attribution_small)


            val icon = findViewById<ImageView>(R.id.home_item_bg_image)


            val image = nativeAd.icon
            if (image != null) {
                attributionViewSmall.visibility = View.VISIBLE
                icon.setImageDrawable(image.drawable)
            } else {
                attributionViewSmall.visibility = View.INVISIBLE
            }
            this.iconView = iconView

            val adV =   findViewById<TextView>(R.id.adviser)
            adV.text = nativeAd.advertiser
            this.advertiserView =adV

            val ctaButton =   findViewById<TextView>(R.id.home_screen_cta_button)
            ctaButton.text = nativeAd.callToAction
            this.callToActionView = ctaButton

            val adDesc =   findViewById<TextView>(R.id.home_item_ad_desc)
            adDesc.text = nativeAd.body
            this.bodyView = ctaButton



            val headlineView = findViewById<TextView>(R.id.home_item_ad_title)
            headlineView.text = nativeAd.headline
            this.headlineView = headlineView




            setNativeAd(nativeAd)
        }

        return homeScreenNativeView
    }
}

home_screen_native_ad.xml file

`
<com.google.android.gms.ads.nativead.NativeAdView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <RelativeLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"

            android:layout_height="160dp">



            <FrameLayout
                android:layout_width="match_parent"
                android:background="#00ffffff"
                android:layout_height="140dp"/>

            <RelativeLayout

                android:layout_width="match_parent"
                android:layout_height="190dp"
                android:layout_marginTop="16dp"
                android:layout_marginEnd="16dp"
                android:layout_marginBottom="16dp"
                android:gravity="start"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/home_item_bg_image"
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:scaleType="centerCrop"
                    android:layout_marginLeft="16dp"


                    />


                <TextView
                    android:id="@+id/home_item_ad_title"
                    android:layout_width="220dp"

                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:layout_toRightOf="@+id/home_item_bg_image"
                    android:ellipsize="end"
                    android:lines="1"
                    android:maxLines="1"
                    android:textColor="#FFFFFFFF"
                    android:textSize="20sp"
                    tools:text="Headline" />

                <TextView
                    android:id="@+id/adviser"
                    android:layout_width="229dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:layout_marginTop="32dp"
                    android:layout_toRightOf="@+id/home_item_bg_image"
                    android:ellipsize="end"
                    android:lines="1"
                    android:maxLines="1"
                    android:textColor="#FFFFFFFF"
                    android:textSize="14sp"
                    tools:text="Advertiser" />


                <TextView
                    android:id="@+id/tv_home_item_native_ad_attribution_small"
                    android:layout_width="35dp"
                    android:layout_height="20dp"
                    android:layout_marginLeft="10dp"
                    android:layout_toRightOf="@+id/home_item_ad_title"
                    android:background="@color/softOrange"
                    android:gravity="center"
                    android:lines="1"
                    android:maxLines="1"
                    android:text="Ad"
                    android:textColor="#FFFF"
                    android:textSize="12sp" />



            </RelativeLayout>

            <TextView
                android:id="@+id/home_item_ad_desc"
                android:layout_width="270dp"
                android:layout_height="40dp"
                android:layout_marginTop="85dp"
                android:ellipsize="end"
                android:lines="2"
                android:gravity="center_vertical"
                android:maxLines="2"
                android:textColor="#FFFFFFFF"
                android:textSize="14sp"
                android:layout_marginLeft="16dp"
                tools:text="Headline" />

            <TextView
                android:id="@+id/home_screen_cta_button"
                android:layout_width="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_height="30dp"
                android:layout_toRightOf="@+id/home_item_ad_desc"
                android:layout_marginTop="100dp"
                android:text="INSTALL"
                android:gravity="center"
                android:ellipsize="end"
                android:lines="1"
                android:textColor="#FFF"
                android:maxLines="1"
                android:textSize="18sp"
                />


        </RelativeLayout>
    </FrameLayout>
</com.google.android.gms.ads.nativead.NativeAdView>`

MainActivity.kt


`class MainActivity : FlutterActivity() {
    private val CHANNEL = "verified.cv/channel" //The channel name you set in your main.dart file

    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {
            // Note: this method is invoked on the main thread.
            call, result ->

            if (call.method == "createNotificationChannel") {
                val argData = call.arguments as java.util.HashMap<String, String>
                val completed = createNotificationChannel(argData)
                if (completed == true) {
                    result.success(completed)
                } else {
                    result.error("Error Code", "Error Message", null)
                }
            } else {
                result.notImplemented()
            }
        }
        GoogleMobileAdsPlugin.registerNativeAdFactory(
                flutterEngine, "listTile", ListTileNativeAdFactory(context))
        GoogleMobileAdsPlugin.registerNativeAdFactory(
                flutterEngine, "skillCard", SkillCardNativeFactory(context))
        GoogleMobileAdsPlugin.registerNativeAdFactory(
                flutterEngine, "homeScreen", HomeScreenNativeAd(context))
        GoogleMobileAdsPlugin.registerNativeAdFactory(
                flutterEngine, "feedItem", FeedItemNativeFactory(context))


    }

    override fun cleanUpFlutterEngine(flutterEngine: FlutterEngine) {
        super.cleanUpFlutterEngine(flutterEngine)

        // TODO: Unregister the ListTileNativeAdFactory
        GoogleMobileAdsPlugin.unregisterNativeAdFactory(flutterEngine, "listTile")
        GoogleMobileAdsPlugin.unregisterNativeAdFactory(flutterEngine, "skillCard")
        GoogleMobileAdsPlugin.unregisterNativeAdFactory(flutterEngine, "homeScreen")
        GoogleMobileAdsPlugin.unregisterNativeAdFactory(flutterEngine, "feedItem")



    }

    private fun createNotificationChannel(mapData: HashMap<String, String>): Boolean {
        val completed: Boolean
        if (VERSION.SDK_INT >= VERSION_CODES.O) {
            // Create the NotificationChannel
            val id = mapData["id"]
            val name = mapData["name"]
            val descriptionText = mapData["description"]
            // val sound = "your_sweet_sound"
            val importance = NotificationManager.IMPORTANCE_HIGH
            val mChannel = NotificationChannel(id, name, importance)
            mChannel.description = descriptionText

            // val soundUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getApplicationContext().getPackageName() + "/raw/your_sweet_sound");
            // val att = AudioAttributes.Builder()
            //         .setUsage(AudioAttributes.USAGE_NOTIFICATION)
            //         .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
            //         .build();

            //mChannel.setSound(soundUri, att)
            // Register the channel with the system; you can't change the importance
            // or other notification behaviors after this
            val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
            notificationManager.createNotificationChannel(mChannel)
            completed = true
        } else {
            completed = false
        }
        return completed
    }
}
`

I/flutter ( 1409): ----------------FIREBASE CRASHLYTICS---------------- I/flutter ( 1409): PlatformException(NativeAdError, Can’t find NativeAdFactory with id: homeScreen, null, null) I/flutter ( 1409): #0 StandardMethodCodec.decodeEnvelope package:flutter/…/services/message_codecs.dart:607 I/flutter ( 1409): #1 MethodChannel._invokeMethod package:flutter/…/services/platform_channel.dart:177 I/flutter ( 1409): <asynchronous suspension> I/flutter ( 1409): #2 NativeAd.load package:google_mobile_ads/src/ad_containers.dart:1033 I/flutter ( 1409): <asynchronous suspension> I/flutter ( 1409): ---------------------------------------------------- D/ACodec ( 1409): dataspace changed to 0x10c40000 (R:2(Limited), P:4(BT601_6_525), M:3(BT601_6), T:3(SMPTE170M)) (

kamay@apple-MacBook-Pro ios % flutter doctor -v [✓] Flutter (Channel stable, 2.10.5, on macOS 12.3.1 21E258 darwin-x64, locale tr-TR) • Flutter version 2.10.5 at /Users/kamay/development/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 5464c5bac7 (7 hafta önce), 2022-04-18 09:55:37 -0700 • Engine revision 57d3bac3dd • Dart version 2.16.2 • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) • Android SDK at /Users/kamay/Library/Android/sdk • Platform android-32, build-tools 32.1.0-rc1 • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.3.1) • Xcode at /Applications/Xcode.app/Contents/Developer • CocoaPods version 1.11.3

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

[✓] Android Studio (version 2021.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 11.0.11+0-b60-7590822)

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

[✓] Connected device (3 available) • sdk gphone x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator) • iPhone 12 mini (mobile) • 2E59E91C-3A71-422D-9512-5748933F04B9 • ios • com.apple.CoreSimulator.SimRuntime.iOS-15-4 (simulator) • Chrome (web) • chrome • web-javascript • Google Chrome 102.0.5005.61

[✓] HTTP Host Availability • All required HTTP hosts are available

• No issues found!

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:5
  • Comments:7

github_iconTop GitHub Comments

3reactions
Xoshbincommented, Jul 18, 2022

Having the same issue, Is there any solution?

0reactions
PatelMilancommented, Oct 13, 2022

I have created android application it will be contain flutter module and load into App. But flutter module is loading native ad, when i am run android application it will be gives error PlatformException(NativeAdError, Can't find NativeAdFactory with id: listTile, null, null) Sample is :- https://github.com/PatelMilan/AndroidToFlutter

Read more comments on GitHub >

github_iconTop Results From Across the Web

PlatformException(NativeAdError, Can't find NativeAdFactory ...
I am facing this error on flutter native ads (android):. PlatformException(NativeAdError, Can't find NativeAdFactory with id: homeScreen, ...
Read more >
Adding an AdMob banner and native inline ads to a Flutter app
This codelab guides you through implementing an AdMob inline banner and AdMob native inline ads in a Flutter app using the Google Mobile...
Read more >
Native Ads | Android - Google Developers
Native ads are ad assets that are presented to users through UI components ... methods to deliver the native ad object or report...
Read more >
Monetizing Flutter apps with Google Native Ads - YouTube
In this video, we learn how to do integrate Google Admob Native Ads with Flutter with latest Flutter ... Your browser can't play...
Read more >
No ad to show" in AdMOb Native ads iOS - Google Groups
Problem: I am getting Error by using my AdUnitID: <GADAdLoader: 0x1799f250> failed with error: Request Error: No ad to show. But when i...
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