AMY QUISPE: Hello world.
My name is Amy Quispe.
ERIC LEICHTENSCHLAG: And I'm Eric Leichtenschlag.
AMY QUISPE: And we're here with you
today from the Mobile Ads Developer Relations Team.
Today we'll talk about migrating to Google Play Services.
What Google Play Services is, why you should migrate,
and the nitty gritty of actually changing your code
from the old AdMob app to your new Google Play Services app.
ERIC LEICHTENSCHLAG: So first I'm
going to talk about what is Google Play Services
and why you should upgrade your AdMob
apps to use Google Play Services.
So Google Play Services is an APK
that's distributed through the Google Play Store.
It gives you access to the latest and greatest Google
Android APIs.
And now the APIs are part of Google Play Services.
And the great advantage of using the Google Play Services APIs
is that devices with the Google Play Store
can get updates to the library without you
having to re-release your app.
So if you push your app with version one of Google Play
services with AdMob in it, and AdMob makes changes and pushes
out a v2 onto those devices, your app will start running v2
and take advantage of the latest fixes to the library.
AMY QUISPE: So you should update to Google Play Services
because you will get these automatic platform
updates, which will be a huge advantage.
We'll also just give you better APIs.
We've totally revamped a lot of the APIs
to do things the Android way.
Hopefully you'll find them better and more intuitive.
And then this will also be the platform
of choice going forward.
So we won't continue to iterate on the standalone AdMob SDK.
But all of our new changes will go to the Google Play Services
library.
So we hope that you can upgrade so you can keep with the latest
updates that we have.
ERIC LEICHTENSCHLAG: So now we're
going to talk about how to migrate from the old library
to the new Google Play Services APIs.
So previously, when integrating a library,
you just had a jar and you would put that jar into the libs/
folder for AdMob 6.4.1 and below.
In Google Play Services you actually
have to integrate the Google Play Services library project
and then reference that project into your application.
So there's a difference there.
And then you'll also be using the com.google.android.gms.ads
namespace when referencing on the classes instead
of the com.google.ads namespace.
AMY QUISPE: When you declare an AdActivity
in your manifest XML, then you'll
also have to make a few minor changes.
First you'll be changing the namespace
from com.google.ads.AdActivity to
com.google.android.gms.ads.AdActivity.
Again, we'll be changing that namespace all across your app.
The other thing is you'll have to add this metadata
tag for the Android Play Services version.
So you'll use com.google.android.gms.version
and import the Play Services version.
Also, it's important to note that all
of your permissions and everything else
will stay the same.
So you don't have to worry about that when updating your app.
ERIC LEICHTENSCHLAG: So now I'm going
to talk about creating an AdView.
So in AdMob 6.4.1, when you created the AdView
in the constructor, you'd pass the activity context,
the AdSize, and your AddUnitID.
In Google Play Services, we're doing it
the Android way, where a view object only
needs to take the activity context.
So you just create a new AdView with your activity context.
And then there are setAdUnitID and setAdSize methods
to set the ad size and pass your AdUnitID.
Note that these should only be called once.
If you do it again you'll get an illegal state exception.
But there should be no reason you'd
have to call it more than once.
AMY QUISPE: When you create an AdRequest,
you will no longer be creating this AdRequest
and then adding a test device or doing these other changes
directly to the AdRequest.
Instead we've moved to the builder paradigm,
so you'll create an AdRequest builder.
Everything you'll do will be done to this builder.
The builder is an immutable object,
so everything you do to it will actually
be creating a new builder.
So you won't be able to mess things
up in the middle of running your application.
And then once you've actually made all of your changes
to the builder, for example adding a test device,
then you actually build a builder
to create the AdRequest.
ERIC LEICHTENSCHLAG: You should also note that the identifier
to get test ads on emulators changed from
AdRequest.TEST_EMULATOR to AdRequest.DEVICE_ID_EMULATOR.
AMY QUISPE: So next we'll talk about creating a new AdListener
object.
So we changed the AdListener object.
Previously in the standalone SDK the AdListener object
was an interface so you would extend your ad activity
with this AdListener object and implement all of these methods
in order to track what's going on.
Now in the new Google Play services version,
we have an abstract class.
And you'll be able to actually just create an AdListener
object on the fly, override the methods that you need,
and leave all the rest alone.
One thing to note is that we've changed the error code.
So now the error code is just an integer,
and you'll have to create a new method in order
to extract meaning from that integer.
The other thing is that we've changed
all of the names of the methods.
So onReceiveAd is now onAdLoaded,
onFailedToReceiveAd is now onAdFailedToLoad.
And all of these changes are just one to one.
It shouldn't be difficult to change from one to the other.
And then all of the methods name will
be more consistent with the Android way of doing things.
ERIC LEICHTENSCHLAG: So now I'm going
to talk about the implementation of an AdListener
and setting it on the adView.
So when we had the interface, your class
that implemented the AdListener would
have to implement all of the ad event methods
in that interface.
And then finally call adView.SetAdListener
with the object that implemented the AdListener.
In Google Play Services, we use an abstract class.
And so you can actually just call adView.SetAdListener
and create a new AdListener in line like a subclass
and just override the ad events that you care about.
So in this example, we have onAdLoaded and onAdFailedToLoad
implemented, but we don't have to implement
the rest of the methods here.
AMY QUISPE: Next, we'll talk about creating
an adView in XML.
Previously you were able to do everything
in XML if you wanted to have a very simple adView.
Now we'll have to actually write a little bit of code.
But first, let's talk about the changes in the XML.
So the main changes in the XML are
that you won't be able to use ad testDevices and ad load
on create in your XML.
So you'll have to add a test device in the code.
And you also won't be able to just load
an ad on create in the XML.
You'll have to remove those attributes.
The other thing to notice is that you'll have to change
your namespace from apk/lib/com.google.ads
to apk/res-auto.
That's all going to be auto imported.
Eric's going to talk to you about the changes in the code.
ERIC LEICHTENSCHLAG: Yep, so the change in the code for the XML
AdView in Google Play Services is you'll have to grab
the AdView from the XML, create a new AdRequest via the builder
pattern, and call loadAd with that AdRequest .
As Amy mentioned, in 6.4.1, there
is actually no code required if you had used the LoadAdOnCreate
attribute to be true.
But also note that if you want to do anything more complicated
like set an AdListener, you'll still
need to write some code in both either 6.4.1 or Google Play
services, and that hasn't changed.
AMY QUISPE: Now we'll talk about the adView lifecycle methods.
So previously in the standalone SDK,
we only had adView.destroy().
Now we have adView.destroy(), adView.pause()
and adView.resume().
These methods all allow you to destroy, pause, or resume
web view.
So this gives you a little bit more control
over what's actually going on in your lifecycle.
ERIC LEICHTENSCHLAG: So now I'm going
to talk about passing Extras to AdMob.
You can do things like set the background color
and text of your ad.
And that would be done through Extras.
So in 6.4.1, you would create the new AdRequest,
you'd create a new AdMobAdapterExtras object,
and pass the call addExtra and pass key value pairs,
for like background color and text for example.
And then call setNetworkExtras with that object.
In Google Play Services, it's done a little bit differently.
You have an AdMobExtras instead of an AdMobAdapterExtras.
And it accepts a bundle, which have
to create before you create the AdMobExtras class.
So you create a new bundle, put string on your key value pairs,
create the AdMobExtras object, and then finally when
you're creating the AdRequest using the builder pattern,
you just call addNetworkExtras with those Extras and build it.
AMY QUISPE: So we know we've made a lot of changes
to the SDK.
So there's been a couple questions.
We're going to address three of the most frequently asked
questions.
The first one is, does Google Play Services
support existing mediation adapters?
The answer is yes.
We've made sure that none of your mediation should break.
So if you upgrade to Google Play Services today,
all of your mediation should work as expected.
The mediation adapters will be the same
for a long time in the future if we do it right on mediation
and expect to mediation adapters to update.
We still plan on supporting legacy mediation
for quite a while in the future.
ERIC LEICHTENSCHLAG: The next question guys have had
is, will Google Play Services APIs work on devices
without Google Play Services installed?
And it does.
The only difference is that you won't
get to take advantage of the auto updates.
So if you push your app onto a Kindle that's
using the ads APIs in Google Play Services,
that app won't get any updates if Google Play pushes
a new version of the AdMob lib APIs in the Google Play
Services library.
But for devices that do have Google Play Services installed,
it will automatically get those updates
and be running against the latest version of our library.
AMY QUISPE: The last question is if Google Play services
is compatible with the old standalone AdMob SDK.
The answer is no, unfortunately.
This was a side effect of trying to keep mediation
compatible with the new SDK.
However, you should expect DFP and search
ads for apps and everything else now
in new Google Play Services SDK.
So you shouldn't lose any of that functionality
and should be able to upgrade everything
to Google Play Services.
The other thing is if you are working with a library that's
dependent on the old SDK, then we
hope that you can merge those library developers to upgrade
to the new Google Play Services, since that's
where we'll be pushing all updates from now on.
ERIC LEICHTENSCHLAG: So we've given you a lot of information,
and it might take some time for it to sink in.
Here are some more resources that you
can use if you have more questions.
So first you should check out the Google Play Services
set up, because that explains how to get Google Play Services
library into your app so you can reference it.
And then if you want to reference anything else that we
talked about today, you can check out the Google Play
Services migration guide.
It has a lot of the same information.
AMY QUISPE: And if you have any trouble upgrading,
you can always hit up me and Eric on the forums.
You can also talk to other AdMob developers
there and see if they've had the same troubles that you have.
We hope that this has been helpful,
and we hope that you can enjoy the new version of the AdMob
SDK.
Thank you.
ERIC LEICHTENSCHLAG: Thanks guys.