is the the correct way to determine whether or not...
# android
b
is the the correct way to determine whether or not my library code is being executed in a debug build?
Copy code
val isDebuggable = 0 != applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE
I tried using
BuildConfig.DEBUG
but thats always false
😶 2
g
FLAG_DEBUGGABLE is the only way. BuildConfig is per module setting, you cannot resolve it for conuming application Personally, I wouldn’t like to use library which changes behaviour dynamically basing on FLAG_DEBUGGABLE or any other way, and would prefer to set it from outside explicitly
b
Thanks - and you’re right. What i want is to be able to determine is when the module in question was built as a debug build but there seems to be a bug in Gradle where that is always set to false when building a library.
g
What kind bug? Are you talking about BuildConfig?
b
g
Wow, it's a super long thread But my opinion that it's not a bug at all, it's just an implementation detail which I pretty sure will not be "fixed", rather BuildConfig will be removed by default from library modules, because build config is created for each module on compile time, as result it cannot know resulting app build type, even in theory, one module can be used by multiple apps with different build type The only way is to have some kind of runtime (not compile time) way to request build type, there is no standard way for this, and I hope it will not be one, there are projects with more complex build types configuration
b
yeah, doesn’t seem like its going to change since they marked it as fixed years ago
And just to be clear -
io.mylib.BuildConfig.Debug
should return
true
when the library was built as debug and
false
when it was built as a release. I don’t really want to know the application build type; i was just trying to use that as a work-around
g
Pretty sure it works if you build your library as a release build type
Though I didn't use it for years, so I may be wrong
Even if there is any bug with this particular property, you can always set your own field in debug/release for this, and this definitely works, it's pretty simple logic behind this, build types/flavors work fine In libraries
b
oh, cool. i’ll give that a shot. thx