Utilize both Play Services and AdMob SDK

橙三吉。 提交于 2020-01-09 09:02:24

问题


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.

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".

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.


回答1:


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

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:

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!




回答2:


You can use Google Play Services v12 which does not include the overlapping namespaces. It can be downloaded using the Android's SDK Manager under "Extras" -> "Google Play Services for Froyo". This version will co-exist with AdMob stand alone SDK.

Over time Google will probably deprecate both.

Update: Google has announced the deprecation of the stand alone AdMob SDK, you must move to Google Play SDK:

On August 1, 2014, Google Play will stop accepting new or updated apps that use the old standalone Google Mobile Ads SDK v6.4.1 or lower. You must upgrade to the Google Play version of the Mobile Ads SDK by then.




回答3:


Detailed Google Play Services Migration for AdMob is available here: https://developers.google.com/mobile-ads-sdk/docs/admob/play-migration




回答4:


I think i got the attention of Google/Android for the issue,

https://code.google.com/p/android/issues/detail?id=63007



来源:https://stackoverflow.com/questions/19721158/utilize-both-play-services-and-admob-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!