Issue
I'm implementing a flutter package, I'm trying to retrieve values from the Android BuildConfig file of the parent application, is this possible?
I tried code like this:
val packageName = flutterActivity?.packageName
if (packageName != null) {
val value = Class.forName(packageName + ".BuildConfig").getField("FLAVOR").get(null) as String
print(value)
}
But file is not found...
Solution
I resolve my problem by using :
private var flutterActivity: Activity? = null
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
this.flutterActivity = binding.activity
}
/// Get The Build Flavor config.
private fun getFlavor(result: Result) {
flutterActivity?.let {
val pack = it.localClassName.split(".").dropLast(1).joinToString(".")
val flavor =
Class.forName(pack.plus(".BuildConfig")).getField("FLAVOR").get(null) as String
result.success(flavor)
} ?: run {
result.success(null)
}
}
Answered By - Dev Loots
Answer Checked By - Pedro (JavaFixing Volunteer)