同时使用 Play 服务和 AdMob SDK

Utilize both Play Services and AdMob SDK(同时使用 Play 服务和 AdMob SDK)
本文介绍了同时使用 Play 服务和 AdMob SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为 MH.在 this question 中指出,如果他们包含 Google Play Services,则不再需要在其 Android 项目中包含 GoogleAdMobAdsSdk-xxxjar(请参阅迁移指南).但是,我想这样做,但我遇到了麻烦.

As MH. pointed out in this question, one no longer needs to include GoogleAdMobAdsSdk-x.x.x.jar in their Android project if they include Google Play Services (see the migration guide). However, I want to, and I'm having trouble.

问题:google-play-services_lib 项目包含一个已弃用的 com.google.ads.AdRequest 定义,并且有一个私有构造函数.它最终出现在 AdMob jar 前面的类路径中(在Android Private Libraries"条目中),所以当我尝试在我的代码中使用它时,它最终会尝试使用已弃用的,导致错误:构造函数 AdRequest() 不可见.我看不到重新排序Android Private Libraries"中的条目的方法.

The problem: the google-play-services_lib project includes a definition for com.google.ads.AdRequest that is deprecated, and has a private constructor. It ends up in the classpath in front of the AdMob jar (within the "Android Private Libraries" entry), so when I try to use it in my code it end up trying to use the deprecated one, resulting in the error: The constructor AdRequest() is not visible. I see no way to re-order the entries inside "Android Private Libraries".

你问我为什么要同时使用这两个?我有一个包含许多有用类的库项目,包括一些用于处理 Play 服务和 AdMob 的实用程序类.我的一些使用该库项目的应用使用 AdMob 实用程序类,但不使用 Play Services.

Why do I want to use both, you ask? I have a single library project with many useful classes, including some utility classes for dealing both Play Services and AdMob. Some of my apps that use that library project use the AdMob utility classes, but not Play Services.

推荐答案

我一直在对此进行测试,需要进行一些更改才能通过 Google Play 服务运行.

I've been testing this, and some changes are required in order to get this working through Google Play Services.

首先,您应该删除所有引用旧 com.google.ads.* 的导入,因为它们现在位于 com.google.android.gms.ads.*.

In first place you should remove all imports referencing to old com.google.ads.* , since they are now located on com.google.android.gms.ads.*.

正如您所提到的,还需要进行一些更改:

As you mentioned, some more changes need to be done:

您不能像以前那样实例化 AdRequest,而是使用 AdRequest.Builder,如下所示:

You cannot instantiate an AdRequest the way it used to be done, but using an AdRequest.Builder as follows:

AdRequest adRequest = new AdRequest.Builder().build();

另外,请确保在所有布局上替换包的名称,以便它们调用 而不是 .

Also, make sure you replace the name of the package on all layouts, so they call <com.google.android.gms.ads.AdView instead of <com.google.ads.AdView.

我想就是这样.祝你好运!

I think that's all. Good luck!

这篇关于同时使用 Play 服务和 AdMob SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)