6

I have an eclipse project with two included library projects. These projects have their own manifest files with version information. Now I want to read the version number from these library projects within my main project. The information can't be read by calling the PackageManager:

//Get the version name from the included library project String libVersion = getPackageManager().getPackageInfo("com.google.zxing.client.android", 0).versionName; 

Because the library is not an installed application. But what's the right way to get these information?

For instance: I have included zxing Android project as library project. These Project has following version information in its manifest file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.zxing.client.android" android:installLocation="auto" android:versionCode="88" android:versionName="4.3.2" > 

I want to read versionCode and versionName. If I use packageManager like in the coding above, I will get versionCode "93" and versionName "4.5".

3
  • You can see the version in the name itself.. Commented Oct 16, 2013 at 9:47
  • If you have the source code of library project,for a workaround, why not add an interface in that library which returns the version? Commented Jan 9, 2014 at 15:45
  • Both doesn't work. The AndroidManifest.xml of the library project isn't part of the apk, so I think the version information of the library project will get lost at compile time. Commented Jan 10, 2014 at 14:39

1 Answer 1

1

In fact it is possible now (maybe due to new API changes, tested with API 17 (calling project), API 14 (library project)): if you specifically call the correct package name it will retrieve version information from that packages Manifest file:

eg:

String versionName = getPackageManager(). getPackageInfo("PACKAGE_FROM_WHICH_TO_RETRIEVE_MANIFEST", 0).versionName; 
Sign up to request clarification or add additional context in comments.

3 Comments

This did not work for me, returning an exception since the library is not an installed package of reference.
JCricket: did you add the JAR file (library) to the buildpath of the main project and tick it in "order & export", then did a project->clean? i'm working with eclipse, not sure how it works in other IDEs
I was in Android Studio, so the order & export option was not available. I had posted an answer here, but a moderator deleted it....Not sure why. See here for what worked: stackoverflow.com/a/30584970/1544046

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.