Earlier this week, Google Play services released a major update to many of its libraries to migrate all Android support library dependencies to Jetpack (using androidx.*
packages). This includes the play-services-ads
library from the Google Mobile Ads SDK, which has been updated to 18.0.0.
While the Google Mobile Ads SDK itself hasn’t changed between version 17.2.1 and 18.0.0, you’ll need to migrate your own app and all of your dependencies to AndroidX in order to pick up play-services-ads
18.0.0 or any future versions. This is particularly important if you use AdMob mediation , as several mediation partners have dependencies on Android support libraries that aren’t compatible with AndroidX.
To make the migration process as smooth as possible for you, Android Studio offers an easy way to convert your project and its dependencies to AndroidX using the Migrate to AndroidX option.
Migrate to AndroidX
Android Studio 3.2 or higher includes a Refactor > Migrate to AndroidX menu option to convert your project to use AndroidX. We’ll demonstrate what happens when converting our BannerExample to AndroidX.
Change the project’s compileSdkVersion
to 28 . This is a prerequisite for migrating to AndroidX.
Right click the app module, and select Refactor > Migrate to AndroidX . You’ll be given an option to save your project as a zip file before Android Studio converts it.
Select Do Refactor to complete the migration.
What changed?
Here is the project before the migration:
And here is the project afterwards:
First, you’ll notice that the package name for AppCompatActivity
has changed to androidx.appcompat.app
. The refactor has changed this project’s com.android.support:appcompat-v7:26.1.0
dependency to androidx.appcompat:appcompat:1.0.0
and fixed the associated imports.
Second, this migration added a gradle.properties file with these two lines:
android.useAndroidX=true
android.enableJetifier=true
These properties ensure your project and its dependencies use AndroidX, by rewriting any binaries that are using an Android support library. See Using AndroidX for more details on these flags.
Now that your project is converted to AndroidX, you can safely update your play-services-ads dependency to 18.0.0 in your project-level build.gradle file:
dependencies {
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.gms:play-services-ads:18.0.0'
}
As always, you can follow the release notes to learn what’s changed in the Google Mobile Ads SDK. We’d also love to hear about how your migration went! If you have any questions about the release or have trouble migrating, please reach out to us on the Google Mobile Ads SDK developer forum .
- Eric Leichtenschlag, Mobile Ads Developer Relations