18

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.

2
  • Can you not use an alternate constructor that is available in both libraries? Otherwise split it into 2 libraries or remove the Admob only stuff and implement it direct in your apps (I can't imagine there is really much common code as the Admob code is so simple). Commented Nov 2, 2013 at 1:33
  • As far as I can tell, the sole purpose of the new, deprecated class in the Play Services library is to cause the error I received. The class that should be used in the Services lib is in a different package. It seems odd to me that they would intentionally break compatibility between two of their products. My only guess is that they will be phasing out the standalone AdMob jar. I would like to find a workaround at least for now, though. Commented Nov 2, 2013 at 17:09

4 Answers 4

17

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!

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for the pointers, but these are instructions to use the new Play Services package. I'm asking how to use the old .jar in a project that also includes Play Services.
Don't use the old jar. Use GPS and use the new com.google.android.gms.ads.AdRequest class. If you have a project that doesn't need to include the other parts of GPS then pare those APIs away using Proguard.
@William Indeed; "you cannot" seems to be answer to my question, from everything I can see. In response to the other part of your comment, Proguard does not seem to do a very good job stripping down the services library. In one project I'm only using it for AdMob now, and I still get a number of classes from .games, .maps, .plus, and .wallet in the final product. But now I'm on a tangent, I suppose.
You should not use the old Admob jar unless you have a very good reason to because all bug fixes etc will only be reported on GPS.
Note: Google Mobile Ads in Google Play services currently does not support DoubleClick For Publishers (DFP), Ad Exchange, or Search Ads for Apps. So using these will require the old sdk.
10

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 Comments

That's interesting (and expected). I have an app that I deploy on both Google Play and other stores for those devices without access to Google Play. Deprecating the old ASK forces me into Google Play because I cannot show ads any more outside Google Play. Nice trick, Google.
@Michael: Actually, the Google Play services works fine outside of the Google Play store. The only thing is that if the player device does not have GPS, it will not get the automatic updates to the library unless you push a new version.
@Michael_A: But is the GPS APK redistributable?
6

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

3 Comments

I'm not looking for help migrating to use the new AdMob classes. You may even notice I included this same link in my original question. I'm looking to use the separate .jar in a project that also uses Google Play Services. I've basically given up at this point, assuming it is not possible.
@EricSimonton Have you ever found a solution to your original question? I am also facing the same issue...
@IgorGanapolsky No, I have not. The "solution" is: don't do it. Either use Play Service -or- the .jar. You can't use both. (Except perhaps as sagis points out, as a temporary solution if needed.)
6

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

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

1 Comment

There's a work-around version of the GPS jar available in that issue now.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.