i using library want extract app version of app using it, fine reflection
class.forname(context.getpackagename() + ".buildconfig");
but then... separated app flavors, library can't find buildconfig class, throws "class not found exception" ... debugging noticed version name want it's default project id or physical name classes are, not flavor app id.
here config of gradle.
productflavors { development { applicationid "com.dev.testit" buildconfigfield 'string', 'api', '"api"' minsdkversion 16 targetsdkversion 24 versioncode 1 versionname '1.n' } production { applicationid "com.testit" buildconfigfield 'string', 'api', '"prod"' minsdkversion 16 targetsdkversion 24 versioncode 1 versionname '1.s' } }
is there way?
thank you
public static string getappversionname(context context) { if (context == null) return null; packagemanager packagemanager = context.getpackagemanager(); try { packageinfo info = packagemanager.getpackageinfo(context.getpackagename(), 0); return info.versionname; } catch (packagemanager.namenotfoundexception e) { e.printstacktrace(); } return null; }
refer doc here.
Comments
Post a Comment