morya
morya

Reputation: 855

Get version information of an included library?

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?

Upvotes: 6

Views: 5845

Answers (1)

JCricket
JCricket

Reputation: 1329

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).

Upvotes: 14

Related Questions