As seen in oficial android documentation I can use build variants and build my application via different settings.
Therefore, I made my own variants:
android {
defaultConfig {
manifestPlaceholders = [hostName:"www.example.com"]
...
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix ".debug"
manifestPlaceholders = [hostName:"local.example.com"]
debuggable true
}
/**
* The `initWith` property allows you to copy configurations from other build types,
* then configure only the settings you want to change. This one copies the debug build
* type, and then changes the manifest placeholder and application ID.
*/
staging {
initWith debug
manifestPlaceholders = [hostName:"staging.example.com"]
applicationIdSuffix ".debugStaging"
}
}
}
And I have a class where I load all the settings:
class ApiUtils {
public function getApiUrl(String path){
// I want to populate it with appropriate url from build config
String url="";
return url+path;
}
}
How I can populate the url variable with the value from hostName as provided in manifestPlaceholders?
BuildConfig.and see if your variable shows upmanifestPlaceholdersis to inject values into AndroidManifest, if you want to use your values from build scripts in code, you need to use BuildConfig, so something like this basically