How can I access a BuildConfig value in my AndroidManifest.xml file? –

Development issue/problem:

Is it possible to access the BuildConfig value of AndroidManifest.xml?

I have it in my build.gradle file:

defaultConfig {
applicationId com.compagny.product
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName 1.0

// Facebook app id

FACEBOOK_APP_ID is defined in my files

# Facebook ID (Application ID)

To use Facebook to connect in my application, I need to add this line to AndroidManifest.xml :

I want to replace @string/applicationId with the BuildConfig FACEBOOK_APP_ID field, which is defined in degrees, like this

Is this possible with BuildConfig? How else can I do it?

How can this problem be solved?

Decision No 1:





then rebuild your project (Android Studio -> Build -> Rebuild Project)

Both commands generate values that are generated when creating a project – consisting of Java constants in the first case and Android sources in the second case – but the second method generates a string value of the source, which can be accessed with the @string/FACEBOOK_APP_ID syntax. This means that it can be used in the manifest as well as in the code.

Decision No 2:

Another way to access the Gradle Build configuration values of AndroidManifest.xml is to use playlists such as these

android {defaultConfiguration {manifestPitchholder = [ facebookAppId:someId…]}productFlavorizers {flavorizer1 {}flavor2 {manifestPitchholder = [ facebookAppId:anotherId…]}}productFlavorizers {flavorizer1 {}flavor2 {manifestPitchholder = [ facebookAppId:anotherId…]}}}}}

and then in your manifesto:

More information is available at

(Old link for reference only:

Decision No 3:

Hint: When using resValue, the value can be overwritten by a string file in the source (e.g. for another language).

For example, to get the real value of the constant that can be used in the manifest and the Java code, use both manifest holder and buildConfigField:.

android {
defaultConfig {
def addConstant = {constantName, constantValue ->
manifestPost += [ (constantName):constantValue]
buildConfigField String, ${constantName}, ${constantValue}

addConstant(FACEBOOK_APP_ID, xxxxx)

Access to the manifest file :

of Java:


For example, if the value of the constant buildType must be specific, the addConstant help must be configured (to work with the semantics of closing the field),

buildTypes {
def addConstantTo = {Target, ConstantName, ConstantValue ->
Target.manifestPlaceholder += [ (ConstantName):ConstantValue]
Target.buildConfigField string, ${constantName}, ${constantValue}
Debugging {
addConstantTo(owner,FACEBOOK_APP_ID, xxxx-debug)
} Release
addConstantTo(owner,FACEBOOK_APP_ID, xxxxxxx-release)

Decision No 4:

Go to the build.gradle properties in your manifest as in the following example :

For example, you have an applicationId property in your build.gradle and want to access it in your Android manifest:

ApplicationAccess to the application in AndroidManifest :

In the same way, we can create string sources for other constants and access them in code files as easily as we can access them:

context.getString(R.string.GCM_SENDER_ID) ;

Decision No 5:

@stkent is good, but he forgets to add that he has to rebuild the project afterwards.






Android Studio -> Create -> Create a new project

This allows Android to create a string source that can be accessed via


Decision No 6:

Another possibility is to use a different string resource file for all flavor-dependent :

Step one:
Create a new folder in the src folder with the name of your taste, in my case the scene.

Step two:
Create source files for all files that depend on the taste of for example

Step three:
I also use different icons, so you can see the mipmap folders. Only strings.xml is important for this queue. You can now overwrite all important string sources. You only have to enable the one you want to overwrite, all the others are used by the most important .xml strings, it is so shown in Android Studio :

Step four:
Use the resources of the channel in your project and relax:

Decision No 7:

You can use a long value as shown below

buildConfigField ‘long’, ‘FLAVOR_LONG’, ‘11500L

Good luck!

Related Tags:

cbd oil and driving uk,cbd oil and driving ireland,cbd driving laws california,cbd oil and driving australia,cbd for driving anxiety,effects of cbd,cbd soda drug test,green roads cbd oil failed drug test,charlotte's web cbd failed drug test,hemp oil driving,cbd oil can you drink alcohol,is cbd oil impairing,does cbd affect reaction time,cbd oil sleep,cbd for pain,cbd oil vape,cbd gummies,cbd online,cbd oil for anxiety,cbd oil and driving queensland,travelling with cbd oil australia,cbd oil roadside test,cbd oil benefits,is ananda hemp cbd oil,does cbd help anxiety,is it legal to drive on cbd,can you drive on cbd oil,can you drive on cbd oil canada,can you drive after smoking cbd,cbd driving laws,cbd oil side effects