I have created 2 project 1 is Lib and 2nd in Test. From test app I pass context to Lib project.
As 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 version name of test app and not lib. How should i get application version name and code for Lib?
Reference link: How to get version information of an included library?
Or from the command line, you can first search for the name of the associated package using dpkg -S /usr/lib/libnuma. so. 1 , which probably returns libnuma1 as the package name. Then run apt-cache showpkg libnuma1 to find the package version.
As far as ELF is concerned, there is no version information of Shared object stored in the file. So unless the file name itself is saying something like "libXXX.VERSION.so" , there is no other way to find out the version number of the shared object. This technique is generally used in Linux.
We explained how to find and display the OS version on Linux. The safest option is to query /etc/os-release file using grep or cat command. Systemd based Linux distro users can use the hostnamectl command.
BuildConfig.VERSION_NAME
Just make sure that you import the BuildConfig for your library (as literally every android library/app has it's own BuildConfig on it's package path). The Android Studio's Gradle Build system indicates that this is always generated as of version 0.7.0 (see changelog).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With