API for Retrieving Packaged Version

122 views
Skip to first unread message

Nick Imrich

unread,
Mar 23, 2016, 4:35:53 PM3/23/16
to Google Mobile Ads SDK Developers
Is there an API for getting the packaged AdMob SDK version (e.g. "8.4.0") within the Android SDK?  I was expecting maybe a static getVersion method on MobileAds or some way to access the VERSSION_NAME off the BuildConfig, but have not found anything.  Much thanks for the help!

Vu Chau (Mobile Ads SDK Team)

unread,
Mar 23, 2016, 9:24:16 PM3/23/16
to Google Mobile Ads SDK Developers
Hi Nick,

The SDK comes bundled with the newest Play services.  So if you are compiling your app against the latest Play services library (that you specified in your Gradle dependency), you can simply check for its version, and there goes your SDK version.

I'm using the GoogleApiAvailability class from the Play services library to retrieve the version code, so I removed the "ads" portion from my dependency to make it more inclusive (i.e. compile 'com.google.android.gms:play-services:8.4.0'):

int playServicesVersion = GoogleApiAvailability.GOOGLE_PLAY_SERVICES_VERSION_CODE;
 
returns 
8487000 
since I'm compiling against v.8.4.0. 

Other than that, we currently don't expose an explicit API call for the SDK itself.

Vu Chau
Mobile Ads SDK Team

Nick Imrich

unread,
Mar 24, 2016, 8:28:38 AM3/24/16
to Google Mobile Ads SDK Developers
Vu,

Thanks for the quick and thorough response.  I had previously found GOOGLE_PLAY_SERVICES_VERSION_CODE, but I was not sure how that number translates to version name (i.e. "8.4.0").  I assume this version code is just an ever incrementing number that reflects the current Google Play Services build number.  I was hoping there was a similar GOOGLE_PLAY_SERVICES_VERSION_NAME, but it sounds like this is not the case.

Thanks!
Nick

Vu Chau (Mobile Ads SDK Team)

unread,
Mar 24, 2016, 10:23:13 AM3/24/16
to Google Mobile Ads SDK Developers
Hi Nick,

You are correct - GOOGLE_PLAY_SERVICES_VERSION_CODE returns the incremental number of the Play services library that Gradle will grab based on the short form (8.4.0) you specify in your dependency.  So, if you specify compile 'com.google.android.gms:play-services:8.4.0', 8487000 (or whatever the latest build is) will be fetched.  The GOOGLE_PLAY_SERVICES_VERSION_CODE is exactly the integer that's shown in your @integer/google_play_services_version and is just one of the latest that is available server-side.  If you take a look at our release history, we specify the SDK's version number as X.Y, which are the first two digits of the version code, so you can easily translate the version code to the build number.

There is a way to get the version name, but that one checks your local Play services on the device, rather than the version the app is compiled against.

Vu Chau
Mobile Ads SDK Team

Nick Imrich

unread,
Mar 24, 2016, 10:24:04 AM3/24/16
to Google Mobile Ads SDK Developers
Vu,

Based on previous version codes, it looks like the version code of 8487000 can be translated to 8.4.0.  The major and minor version always appear to be the first two digits of the version code.  Is the last digit of the version code always the patch version?

Much thanks!
Nick


On Thursday, March 24, 2016 at 8:28:38 AM UTC-4, Nick Imrich wrote:

Nick Imrich

unread,
Mar 24, 2016, 10:30:06 AM3/24/16
to Google Mobile Ads SDK Developers
Sorry, I posted my latest reply before I saw your last message.  Perfect.  Is the third number usually the last number in the version code?

I am aware that you can pull the version name of the service that is installed on device, but I am specifically looking for the compiled version.

Thanks!
Nick

Vu Chau (Mobile Ads SDK Team)

unread,
Mar 24, 2016, 10:56:13 AM3/24/16
to Google Mobile Ads SDK Developers
Hi Nick,

From what I have seen, the third digit of the version number (8.4.0) is always zero, and it is also the last digit in the version code.  Unless there is some sort of emergency when we need to bump the version, the third digit will remain 0.

Cheers,

Vu Chau
Mobile Ads SDK Team

Nick Imrich

unread,
Mar 24, 2016, 11:28:38 AM3/24/16
to Google Mobile Ads SDK Developers
Vu,

You have been most helpful.  I really appreciate your thorough explanations.

Thanks!
Nick
Reply all
Reply to author
Forward
0 new messages