2

Possible Duplicate:
How to retrieve the android sdk version?

How does one retrieve the version info of an Android library programmatically?

I've written an application where I put some of the logic in a library. In my help-about box, I'd like to show the version number of the actual app, and the underlying library it is using.

This post indicates that it is not possible as the library manifest info is lost upon compilation. However, the post (towards the end) also hints at the idea that it might soon become possible (post is from 2010).

Community
  • 1
  • 1
Dave
  • 6,585
  • 11
  • 51
  • 92

1 Answers1

4

While some amount of manifest merging is apparently possible today, it won't help you a bit, because there is no place in the system where the version number of library projects would be recorded in the manifest, let alone in the OS some place that you could reach via the SDK.

I'd just put a string resource in the library and use that (R.string.my_super_library_version or some such).

Robert Harvey
  • 168,684
  • 43
  • 314
  • 475
CommonsWare
  • 910,778
  • 176
  • 2,215
  • 2,253
  • Robert, Thanks for the quick answer. I was afraid that was going to be the news. It really seems like a problem. If I understand your suggestion, I have to remember to change the version number in the actual manifest AND in the string table. I hate to be one of those folks who says, "Why can't Android do this, Platform X (insert favorite platform for 'X') can do it!", but in this case, it is true. I'm sure I'm not the only one who sometimes changes the app, sometimes changes the library, and sometimes changes both. It would be nice to see both versions reflected in the 'about' box. – Dave Oct 16 '12 at 00:10
  • @Dave: "Robert" -- actually my name is Mark. :-) "If I understand your suggestion, I have to remember to change the version number in the actual manifest AND in the string table" -- customize your Ant script, then. "It would be nice to see both versions reflected in the 'about' box" -- bear in mind that there is approximately one person on the planet who cares about the content of your about box: you. Few if any users will look at it, fewer still will pay much attention to its contents, and fewer still will know what a "library" even is. – CommonsWare Oct 16 '12 at 12:31
  • Thanks Mark (and sorry about the name mix-up). Marked as answer. P.S. Is Ant script a standard part of Android? Any reference to get me started editing it to automatically enforce changing the version number? That sounds like a very slick solution. – Dave Oct 17 '12 at 00:29
  • @Dave: "Is Ant script a standard part of Android?" -- yes, insofar as the command line tools create and use them (e.g., `android create project`, `android update project`). "Any reference to get me started editing it to automatically enforce changing the version number?" -- ah, if by "standard" you mean "documented and designed for tinkering", that it is not. However, plenty have done it, so I would assume that there are blog posts and the like that describe how that tinkering works. Aim for 2011-12 posts, though, as the scripts changed a lot. – CommonsWare Oct 17 '12 at 10:56
  • @Dave: Also, FWIW, they are working on a complete revamp of the build system to one that is Gradle-based and designed/documented to be extended for stuff like this. v0.2 is available if you would prefer to tinker with it. See http://tools.android.com/tech-docs/new-build-system – CommonsWare Oct 17 '12 at 10:58