Get version information of the included library?

I created 2 projects 1 - Lib and 2nd in Test. From the test application, I pass the context to the Lib project.

Since I have context in Lib, I used below code inside Lib

String version = this.mContext.getPackageManager (). getPackageInfo (this.mContext.getPackageName (), 0) .versionName; Log.e ("versionName", version);

But this gives me the name of the test application version, not lib. How do I get the name and version code for Lib?

Link Link: How to get information about the version of the built-in library?

+4
source share
1 answer
BuildConfig.VERSION_NAME 

Just make sure you import BuildConfig for your library (since literally every Android library / application has its own BuildConfig on the way to the package). The Android Studio Gradle Build system indicates that it has always been created since version 0.7.0 (see the changelog ).

+9
source

Source: https://habr.com/ru/post/956069/


All Articles