【问题标题】:Cannot make MoPub deliver Native Ads to my Android App无法让 MoPub 向我的 Android 应用程序提供原生广告
【发布时间】:2019-01-21 09:13:11
【问题描述】:

我按照 Mopub 的说明在我的 Android 应用中实施了他们的原生广告。

我用其他来源检查了代码,显然,一切似乎都很好,但实际上我无法让 Mopub 加载任何广告。我的代码是:

 SdkConfiguration sdkConfiguration = new SdkConfiguration
            .Builder("11a17b188668469fb0412708c3d16813") // trial #
            .build();
    MoPub.initializeSdk(this, sdkConfiguration, initSdkListener());

    MoPubNative moPubNative = new MoPubNative(this, "11a17b188668469fb0412708c3d16813", this); // 11a17b188668469fb0412708c3d16813

    ViewBinder viewBinder = new ViewBinder.Builder(R.layout.mopub_native_ad_list_item)
            .mainImageId(R.id.native_main_image)
            .iconImageId(R.id.native_icon_image)
            .titleId(R.id.native_title)
            .textId(R.id.native_text)
            .privacyInformationIconImageId(R.id.native_privacy_information_icon_image)
            .build();
    MoPubStaticNativeAdRenderer moPubStaticNativeAdRenderer = new MoPubStaticNativeAdRenderer(viewBinder);
    moPubNative.registerAdRenderer(moPubStaticNativeAdRenderer);

    EnumSet<RequestParameters.NativeAdAsset> desiredAssets = EnumSet.of( // Optional
            RequestParameters.NativeAdAsset.TITLE,
            RequestParameters.NativeAdAsset.TEXT,
            RequestParameters.NativeAdAsset.CALL_TO_ACTION_TEXT,
            RequestParameters.NativeAdAsset.MAIN_IMAGE,
            RequestParameters.NativeAdAsset.ICON_IMAGE,
            RequestParameters.NativeAdAsset.STAR_RATING
    );
    // RequestParameters mRequestParameters = new RequestParameters.Builder().desiredAssets(desiredAssets).build();

    moPubNative.makeRequest();

以及回调的代码:

private SdkInitializationListener initSdkListener() {
    return new SdkInitializationListener() {
        @Override
        public void onInitializationFinished() {
       /* MoPub SDK initialized.
       Check if you should show the consent dialog here, and make your ad requests. */
        }
    };
}

@Override
public void onNativeLoad(final com.mopub.nativeads.NativeAd nativeAd) {
    FrameLayout mopubGloFrameLayout = (FrameLayout) findViewById(R.id.flurrymainframe); // Parent where to attach the Native Ad
    View adView = nativeAd.createAdView(getBaseContext(), mopubGloFrameLayout);
    nativeAd.prepare(adView);
    nativeAd.renderAdView(adView);
    mopubGloFrameLayout.addView(adView);
}

@Override
public void onNativeFail(final NativeErrorCode errorCode) {
    Log.w(this.getClass().getSimpleName(), errorCode.toString());
}

@Override
public void onImpression(final View view) {
    // Ad impression has been recorded on MoPub and the corresponding ad network
}

@Override
public void onClick(final View view) {
    // Ad click has been recorded on MoPub and the corresponding ad network
}

以及 moPubNative.makeRequest() 之后 MoPub Native 变量的快照:

我的相关日志:

  01-21 03:36:13.534 3936-3979/com.languagematerial.lmmovies E/FlurryAgent: GOOGLE PLAY SERVICES ERROR: java.util.concurrent.TimeoutException: Timed out waiting for the service connection
  01-21 03:36:13.535 3936-3979/com.languagematerial.lmmovies E/FlurryAgent: There is a problem with the Google Play Services library, which is required for Android Advertising ID support. The Google Play Services library should be integrated in any app shipping in the Play Store that uses analytics or advertising.
  01-21 03:36:23.539 3936-3979/com.languagematerial.lmmovies E/FlurryAgent: GOOGLE PLAY SERVICES ERROR: java.util.concurrent.TimeoutException: Timed out waiting for the service connection
  01-21 03:36:23.539 3936-3979/com.languagematerial.lmmovies E/FlurryAgent: There is a problem with the Google Play Services library, which is required for Android Advertising ID support. The Google Play Services library should be integrated in any app shipping in the Play Store that uses analytics or advertising.
  01-21 03:36:26.405 3936-3936/com.languagematerial.lmmovies D/MoPub: Initializing MoPub with ad unit: 11a17b188668469fb0412708c3d16813
  01-21 03:36:26.425 3936-3936/com.languagematerial.lmmovies D/MoPub: MoPubNative Loading ad from: https://ads.mopub.com/m/ad?id=11a17b188668469fb0412708c3d16813&nv=5.4.1&dn=unknown%2CAndroid%20SDK%20built%20for%20x86%      
  2Csdk_google_phone_x86&bundle=com.languagematerial.lmmovies&z=-0500&o=l&w=1024&h=600&sc=1.0&mcc=310&mnc=260&cn=Android&ct=6&av=1.0&udid=mp_tmpl_advertising_id&dnt=mp_tmpl_do_not_track&gdpr_applies=0&force_gdpr_applies=0&current_consent_status=unknown
  01-21 03:36:26.427 3936-3936/com.languagematerial.lmmovies E/MoPub: Make sure to call MoPub#initializeSdk before loading an ad.
  01-21 03:36:26.437 3936-4009/com.languagematerial.lmmovies E/Volley: [236] NetworkDispatcher.processRequest: Unhandled exception java.lang.RuntimeException: Bad URL 
      java.lang.RuntimeException: Bad URL 
          at com.mopub.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:171)
          at com.mopub.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:120)
          at com.mopub.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)
       Caused by: java.net.MalformedURLException: Protocol not found: 
          at java.net.URL.<init>(URL.java:176)
          at java.net.URL.<init>(URL.java:125)
          at com.mopub.volley.toolbox.HurlStack.executeRequest(HurlStack.java:92)
          at com.mopub.network.RequestQueueHttpStack.executeRequest(RequestQueueHttpStack.java:57)
          at com.mopub.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:131)
          at com.mopub.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:120) 
          at com.mopub.volley.NetworkDispatcher.run(NetworkDispatcher.java:87) 
  01-21 03:36:26.449 1263-1686/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
  01-21 03:36:26.449 3936-4015/com.languagematerial.lmmovies D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
  01-21 03:36:26.453 3936-3967/com.languagematerial.lmmovies W/chromium: [WARNING:data_reduction_proxy_config.cc(423)] SPDY proxy OFF at startup
  01-21 03:36:26.456 3936-3936/com.languagematerial.lmmovies W/TextToSpeech: speak failed: not bound to TTS engine
  01-21 03:36:26.456 3936-3936/com.languagematerial.lmmovies I/TextToSpeech: Connected to ComponentInfo{com.svox.pico/com.svox.pico.PicoService}
  01-21 03:36:26.461 3936-4016/com.languagematerial.lmmovies I/TextToSpeech: Set up connection to ComponentInfo{com.svox.pico/com.svox.pico.PicoService}
  01-21 03:36:26.488 3936-3936/com.languagematerial.lmmovies W/TextToSpeech: speak failed: TTS engine connection not fully set up
  01-21 03:36:26.488 3936-3936/com.languagematerial.lmmovies D/MoPub: Native ad request failed.
      com.mopub.network.MoPubNetworkError: java.lang.RuntimeException: Bad URL 
          at com.mopub.network.AdLoader.deliverError(AdLoader.java:275)
          at com.mopub.network.AdLoader.access$200(AdLoader.java:30)
          at com.mopub.network.AdLoader$1.onErrorResponse(AdLoader.java:85)
          at com.mopub.volley.Request.deliverError(Request.java:630)
          at com.mopub.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:108)
          at android.os.Handler.handleCallback(Handler.java:739)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:148)
          at android.app.ActivityThread.main(ActivityThread.java:5417)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
       Caused by: java.lang.RuntimeException: Bad URL 
          at com.mopub.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:171)
          at com.mopub.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:120)
          at com.mopub.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)
        Caused by: java.net.MalformedURLException: Protocol not found: 
          at java.net.URL.<init>(URL.java:176)
          at java.net.URL.<init>(URL.java:125)
          at com.mopub.volley.toolbox.HurlStack.executeRequest(HurlStack.java:92)
          at com.mopub.network.RequestQueueHttpStack.executeRequest(RequestQueueHttpStack.java:57)
          at com.mopub.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:131)
          at com.mopub.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:120) 
          at com.mopub.volley.NetworkDispatcher.run(NetworkDispatcher.java:87) 
  01-21 03:36:26.489 3936-3936/com.languagematerial.lmmovies W/LMMoviesMainActivity: Unspecified error occurred.
  01-21 03:36:26.490 3936-4006/com.languagematerial.lmmovies D/MoPub: MoPubIdentifier initialized.
  01-21 03:36:26.491 3936-4010/com.languagematerial.lmmovies D/MoPub: Posting AsyncTask to main thread for execution.

请注意我收到此警告:

确保在加载广告之前调用 MoPub#initializeSdk。

根据快照中的变量,我设法加载了一些东西,为什么它说它没有呢?

我只是不知道还能做什么。在 stackoverflow 中也有类似的 MoPub Native 失败案例,但实际上没有人提出任何解决方案,甚至没有更接近的替代方案。 MoPub 伪支持很糟糕。您是否偶然成功实施了 MoPub 原生广告?如果是这样,你能看出我的代码有什么问题吗?谢谢

【问题讨论】:

    标签: android ads mopub


    【解决方案1】:

    我遇到了同样的问题,并使用更新版本的 mopub-android-sdk library(5.5.0) 解决了它。

    你可以试试这个而不是mopubNative.makeRequest()吗? (这是 kotlin 代码。)

     MoPub.initializeSdk(this, sdkConfiguration, object : SdkInitializationListener {
                override fun onInitializationFinished() {
                    mopubNative.makeRequest()
                }
            })
    

    【讨论】:

      【解决方案2】:

      将此代码放在ocCreate方法中初始化sdk,也可以通过SdkInitializationListener接口的onInitializationFinished方法检查是否初始化

      SdkConfiguration sdkConfiguration = new SdkConfiguration.Builder("MOPUB_ID")
                  .withLogLevel(MoPubLog.LogLevel.DEBUG)
                  .withLegitimateInterestAllowed(false)
                  .build();
      
          MoPub.initializeSdk(this, sdkConfiguration, new SdkInitializationListener() {
              @Override
              public void onInitializationFinished() {
                  Log.d("Mopub", "SDK initialized");
              }
          });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-06
        • 2016-09-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多