如何获取包含库的版本信息?

时间:2021-02-17 03:13:48

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:

我有一个带有两个包含的库项目的eclipse项目。这些项目有自己的包含版本信息的清单文件。现在我想从主项目中的这些库项目中读取版本号。通过调用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:

例如:我已将zxing Android项目作为库项目包含在内。这些项目的清单文件中包含以下版本信息:

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

我想读取versionCode和versionName。如果我在上面的编码中使用packageManager,我会得到versionCode“93”和versionName“4.5”。

1 个解决方案

#1


0  

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:

实际上它现在是可能的(可能是由于新的API更改,使用API​​ 17(调用项目),API 14(库项目)测试):如果您专门调用正确的包名称,它将从该包Manifest文件中检索版本信息:

eg:

String versionName = getPackageManager().
        getPackageInfo("PACKAGE_FROM_WHICH_TO_RETRIEVE_MANIFEST", 0).versionName;

#1


0  

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:

实际上它现在是可能的(可能是由于新的API更改,使用API​​ 17(调用项目),API 14(库项目)测试):如果您专门调用正确的包名称,它将从该包Manifest文件中检索版本信息:

eg:

String versionName = getPackageManager().
        getPackageInfo("PACKAGE_FROM_WHICH_TO_RETRIEVE_MANIFEST", 0).versionName;