Get Android library module version number from inside demo app

前端 未结 2 1510
说谎
说谎 2021-02-20 06:00

I can programmatically get my app\'s version name like this:

String versionName = BuildConfig.VERSION_NAME; // 1.0

However, I have a demo app f

2条回答
  •  借酒劲吻你
    2021-02-20 06:32

    Somehow the other options with BuildConfig didn't work out for me. I ended up with this code:

    context.getPackageManager().getPackageInfo("com.package.name", 0).versionName
    

    For my library "com.package.name" was only the first part of the dependency from build.gradle:

    implementation 'com.package.name:library:1.0.0'
    

提交回复
热议问题