从演示应用程序内部获取Android库模块版本号 [英] Get Android library module version number from inside demo app
问题描述
我可以通过编程方式获取应用的版本名称,例如此:
I can programmatically get my app's version name like this:
String versionName = BuildConfig.VERSION_NAME; // 1.0
但是,我有一个演示应用程序,用于我正在制作的库.在我的项目中(因为库和演示应用程序在同一个项目中),我使用
However, I have a demo app for a library I am making. In my project (since the library and the demo app are in the same project) I use
dependencies {
implementation project(":mongol-library")
}
在其他应用中,人们会使用
In other apps people would import it with
dependencies {
implementation 'net.studymongolian:mongol-library:0.9.16'
}
在演示应用程序中,我想包含库的版本名称,而不是演示应用程序的版本名称.当然,我可以对字符串进行硬编码,并在每次更新库时对其进行更新,但这很容易出错.有没有办法以编程方式访问库模块的版本名称?
In the demo app I would like to include the library's version name rather than the demo app version name. I could hard code the string, of course and update it every time that I updated the library, but that would be error prone. Is there a way to programmatically access a library module's version name?
相关问题
- Get the version number from an app from within a library
- Android.Gradle: Is it possible to get current module name programmatically?
推荐答案
使用
String libVersionName = your.lib.package.name.BuildConfig.VERSION_NAME;
或在您的库中,只需使用BuildConfig.VERSION_NAME
即可获取它.
or in your library, just use BuildConfig.VERSION_NAME
to get it.
NB:
应用模块中的BuildConfig.VERSION_NAME
是your.app.package.name.BuildConfig.VERSION_NAME
NB:
BuildConfig.VERSION_NAME
in app module is your.app.package.name.BuildConfig.VERSION_NAME
这篇关于从演示应用程序内部获取Android库模块版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!