问题描述
作为 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!