I'm building an application that uses an Android library as the primary source of code. Then I have multiple apps using that library; these apps will have the same code, but different configuration fields, such as endpoints and so.
To accomplish this, I thought I could have a buildConfigField in my library's build.gradle file, and then override that value in my app's build.gradle by using the same name, like this:
build.gradle in library:
buildConfigField "String", "API_BASE_URL", "\"http://arandomapibaseurl.com\""
build.gradle in app:
buildConfigField "String", "API_BASE_URL", "\"http://myrealapi.com\""
Any ideas on how to accomplish this?
Thanks!
You can't override build configs unfortunately. You can override resource values specified with resValue. The app can override the library, not the other way around. You just need a context to pull them out, and you can do that at app launch to stick them into a java object that you can share as a singleton or whatever.
I have used this trick a lot in the past to let apps pull in a library and override its defaults. You can read about it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With