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

Custom Native Ad not showing Icon because MaxNativeAdViewBinder's setIconContentViewId is protected #675

Open
linversion opened this issue Jun 17, 2024 · 12 comments
Assignees
Labels
bug Something isn't working

Comments

@linversion
Copy link

linversion commented Jun 17, 2024

MAX SDK Version

12.5.0

Device/Platform Info

all device

Current Behavior

I'm trying to show my custom native ad template. But the icon will not show. Because in MaxNativeAdView's a() method, there's a logic assert this.h(which is the iconContentViewId cast to FrameLayout) not null, only if this.h != null will go in the setImageDrawable logic to this.g(the Icon ImageView) and the only way to set this
iconContentViewId is MaxNativeAdViewBinder's setIconContentViewId which is protected

// MaxNativeAdView.class
private void a(MaxNativeAd var1) {

        MaxNativeAd.MaxNativeAdImage var2 = var1.getIcon();
        View var3 = var1.getIconView();
        FrameLayout var4;
        if ((var4 = this.h) != null) {
            if (var2 != null && this.g != null) {
                if (var2.getDrawable() != null) {
                    this.g.setImageDrawable(var2.getDrawable());
                } else if (var2.getUri() != null && StringUtils.isValidString(var2.getUri().toString())) {
                    ImageViewUtils.setAndDownscaleImageUri(this.g, var2.getUri());
                } else {
                    this.h.setVisibility(8);
                }
            } else if (var3 != null) {
                var3.setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
                this.h.removeAllViews();
                this.h.addView(var3);
            } else {
                var4.setVisibility(8);
            }
        }

    }

Expected Behavior

can show icon image view without setting iconContentViewId or provide a method to set it

How to Reproduce

  1. create custom native template layout
  2. create a MaxNativeAdViewBinder by it' Builder, create a MaxNativeAdView(binder, activity)
    val binder = MaxNativeAdViewBinder.Builder(R.layout.applovin_native_banner)
    .setTitleTextViewId(R.id.title_text_view)
    .setBodyTextViewId(R.id.body_text_view)
    .setAdvertiserTextViewId(R.id.advertiser_textView)
    .setIconImageViewId(R.id.icon_image_view)
    .setOptionsContentViewGroupId(R.id.ad_options_view)
    .setCallToActionButtonId(R.id.cta_button)
    .build()
    val adView = MaxNativeAdView(binder, activity)
  3. render MaxAd by MaxNativeAdLoader.render(adView, maxAd)

Additional Info

No response

@linversion linversion added the bug Something isn't working label Jun 17, 2024
@NanaAmoah
Copy link
Contributor

Hi @linversion I tested the code snippet you shared and have not been able to reproduce the issue.

Could you reproduce the issue in our demo app and share a screenshot showing the issue you are seeing?

@linversion
Copy link
Author

Hi @linversion I tested the code snippet you shared and have not been able to reproduce the issue.

Could you reproduce the issue in our demo app and share a screenshot showing the issue you are seeing?

Hi @NanaAmoah , here is how I reproduce the issue in kotlin demo app.

  1. dependency
//app build.gradle
    if (isLocalAppLovinWorkspace) {
        implementation(project(":Android-SDK"))
    } else {
        implementation("com.applovin:applovin-sdk:12.5.0@aar")
    }
  1. create layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    >

    <ImageView
        android:id="@+id/icon_image_view"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_margin="6dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:contentDescription="icon" />
    <FrameLayout
        android:id="@+id/icon_content_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
    <FrameLayout
        android:layout_width="26dp"
        android:layout_height="15dp"
        android:id="@+id/options_view"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent">

    </FrameLayout>

    <ImageView
        android:id="@+id/ad_icon"
        android:layout_width="27dp"
        android:layout_height="18dp"
        app:layout_constraintStart_toEndOf="@id/icon_image_view"
        app:layout_constraintTop_toTopOf="@id/icon_image_view"
        android:layout_marginStart="7dp"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/title_text_view"
        tools:text="Test Ad: "
        app:layout_constraintStart_toEndOf="@id/ad_icon"
        app:layout_constraintTop_toTopOf="@id/ad_icon"
        app:layout_constraintBottom_toBottomOf="@id/ad_icon"
        android:layout_marginStart="8dp"
    />

<!--    <FrameLayout-->
<!--        android:layout_width="wrap_content"-->
<!--        android:layout_height="wrap_content"-->
<!--        android:id="@+id/star_rating_view"-->
<!--        android:visibility="gone"-->
<!--    />-->

    <TextView
        android:id="@+id/advertiser_textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toEndOf="@id/title_text_view"
        app:layout_constraintTop_toTopOf="@id/title_text_view"
        tools:text="Flood-it"
    />

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/body_text_view"
        app:layout_constraintStart_toStartOf="@id/ad_icon"
        app:layout_constraintEnd_toStartOf="@id/cta_button"
        app:layout_constraintTop_toBottomOf="@id/ad_icon"
        android:layout_marginTop="5dp"
        tools:text="Text text tesxt texge tegn  tejogne gegegn gegoentete tee nnn ted tedgn tete"
        android:maxLines="2"
        android:ellipsize="end"
        android:layout_marginEnd="5dp"
        android:textSize="11sp"
    />

<!--    <FrameLayout-->
<!--        android:layout_width="wrap_content"-->
<!--        android:layout_height="wrap_content"-->
<!--        android:id="@+id/media_view_container"-->
<!--        android:visibility="gone"-->
<!--    />-->

    <Button
        android:layout_width="76dp"
        android:layout_height="wrap_content"
        android:id="@+id/cta_button"
        android:text="GO"
        android:background="@color/colorAccent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginEnd="8dp"
    />
</androidx.constraintlayout.widget.ConstraintLayout>
  1. build the binder
    // ManualNativeLateBindingAdActivity
    private fun createNativeAdView(): MaxNativeAdView {
        val binder: MaxNativeAdViewBinder = MaxNativeAdViewBinder.Builder(R.layout.applovin_native_banner)
                .setTitleTextViewId(R.id.title_text_view)
                .setBodyTextViewId(R.id.body_text_view)
                .setAdvertiserTextViewId(R.id.advertiser_text_view)
                .setIconImageViewId(R.id.icon_image_view)
                .setOptionsContentViewGroupId(R.id.options_view)
                .setCallToActionButtonId(R.id.cta_button)
                .build()

        return MaxNativeAdView(binder, this)
    }
  1. load the native ad.

Screenshot_20240618_124518_AppLovin MAX Demo App

the icon view can not show

but if i set the iconContentViewId by reflection

    // ManualNativeLateBindingAdActivity
    private fun createNativeAdView(): MaxNativeAdView {
         val binder: MaxNativeAdViewBinder = MaxNativeAdViewBinder.Builder(R.layout.applovin_native_banner)
                .setTitleTextViewId(R.id.title_text_view)
                .setBodyTextViewId(R.id.body_text_view)
                .setAdvertiserTextViewId(R.id.advertiser_text_view)
                .setIconImageViewId(R.id.icon_image_view)
                .setOptionsContentViewGroupId(R.id.options_view)
                .setCallToActionButtonId(R.id.cta_button)
                .build()
        val iconContentViewId = binder.javaClass.getDeclaredField("iconContentViewId")
        iconContentViewId.isAccessible = true
        iconContentViewId.set(binder, R.id.icon_content_view)

        return MaxNativeAdView(binder, this)
    }

Screenshot_20240618_124432_AppLovin MAX Demo App

@NanaAmoah
Copy link
Contributor

NanaAmoah commented Jun 18, 2024

Thanks @linversion. Can you please share the project which reproduces the issue here?

@linversion
Copy link
Author

@NanaAmoah bro I already said the project I used was the Applovin Max Demo App-Kotlin,just add your sdk key and native ad unit ID,follow the step I mentioned before

@NanaAmoah NanaAmoah self-assigned this Jun 21, 2024
@NanaAmoah
Copy link
Contributor

NanaAmoah commented Jun 25, 2024

@linversion could you double check that you are setting the correct package name, SDK key and ad unit ID in the demo app?

A mismatch in your credentials will result in the issue you are seeing. To verify that you are using the correct package name and SDK key, tap "Launch Mediation Debugger". You should see your package name under "App Info" and all the ad unit IDs created for that app under "View Ad Units".

I am only able to reproduce your issue in our demo app with mismatched credentials so if after double checking, you are still reproducing the issue, please share the demo app project where the issue is reproducible here.

@lovestart
Copy link

I also encountered the same problem. When running the android kotlin demo, the icon image and media content were not displayed.

Page path: Native Ads -> Manual API -> Show AD
image
image
image

@NanaAmoah
Copy link
Contributor

Hi @lovestart, could you confirm that you are setting the correct package name, SDK key and ad unit ID in the demo app? If after this you are still encountering the issue, please send us the demo app project where this is reproducible.

@lovestart
Copy link

I set the correct package name, SDK key, and ad unit ID in the Applovin demo app, but still have the same problem. In addition, I think it has little to do with setting your own SDK key, because in the same environment, it works fine to display Native ads through the Templates API, but it doesn't work when you enter Native through the Manual API. Through code tracking, I came to the same conclusion as @linversion , that it can only be displayed if setIconContentViewId is set, but it is now protected.

2024-08-06.11.05.12.mov

@NanaAmoah
Copy link
Contributor

@lovestart can you send us the demo app project where this is reproducible?

@lovestart
Copy link

lovestart commented Aug 7, 2024

I am using max kotlin demo, without changing anything. Clicking Templates API works fine, but Manual API and Manual Late Binding API do not display correctly.
I understand that since I have already obtained native ads, it has nothing to do with me replacing my SDK key.
max kotlin demo

@linversion
Copy link
Author

linversion commented Aug 10, 2024

I am using max kotlin demo, without changing anything. Clicking Templates API works fine, but Manual API and Manual Late Binding API do not display correctly. I understand that since I have already obtained native ads, it has nothing to do with me replacing my SDK key. max kotlin demo

bro, just read the freaking source code(MaxNativeAdView's a() method), it's not about the demo, why you always stick on the demo project @NanaAmoah

@thomasmso
Copy link
Member

@lovestart or @linversion - what is your Ad Unit ID that you're having issues with?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants