Skip to content Skip to sidebar Skip to footer

Get The Version Of A Library In My Android App Programmatically

I have a library in my Android app like UnityAds. I want to get the version name and the version code of it in runtime. I wrote the below code, but always exception occurred. What

Solution 1:

That won’t work, PackageManager APIs help you check for any valid packages/apps installed using a package name lookup.

Since the library is in the class path for your own package the only way to reference these ids at runtime would be to have a workflow to record these during compilation and expose it to your application at runtime.

Following approaches are viable:

  1. Expose library metadata in build config/resources (https://developer.android.com/studio/build/gradle-tips#simplify-app-development)

  2. Custom gradle plugin to capture all libraries in classpath into assets which can be read at runtime, something similar to https://github.com/google/play-services-plugins

With (1) you can’t scale it for multiple libraries conveniently so it’s only useful for very specific needs.

(2) might require some customisations for your usecase (adding version info) but is definitely scalable.

Post a Comment for "Get The Version Of A Library In My Android App Programmatically"