The last day starting a new project I was creating some variables in the build config as a good practice to handle them separately between release and debug builds like this:
...
buildTypes {
release {
minifyEnabled false
buildConfigField("String", "PARSE_APP_ID", "xxxxxxxxxxxxxxxxxxxxxxxxxxx")
buildConfigField("String", "PARSE_CLIENT_ID", "xxxxxxxxxxxxxxxxxxxxxxxxxx")
buildConfigField("String", "FACEBOOK_APP_ID", "999999999999999")
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug{
minifyEnabled false
buildConfigField("String", "PARSE_APP_ID", "xxxxxxxxxxxxxxxxxxxxxxxxxxx")
buildConfigField("String", "PARSE_CLIENT_ID", "xxxxxxxxxxxxxxxxxxxxxxxxxx")
buildConfigField("String", "FACEBOOK_APP_ID", "999999999999999")
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
...
The problem is that it was not creating the Strings correctly it was printing the strings directly without the quotation marks like this:
public final class BuildConfig {
.....
// Fields from build type: debug
public static final String FACEBOOK_APP_ID = 99999999999999999;
public static final String PARSE_APP_ID = xxxxxxxxxxxxxxxxxxxxxxxx;
public static final String PARSE_CLIENT_ID = xxxxxxxxxxxxxxxxxxxxxxxxx;
}
Obviously this will give you compile errors, I tried to find here in stackoverflow how to fix this since this was causing erros in my build, haven't found anything about this. How to make gradle print the Strings correctly with the quotation marks?
in app build.gradle
then in BuildConfig file
After writing this I have found the way, it seems that the values are printed in the same way they are defined so if you add escaped quotation marks to this it will work, example:
After that, Rebuild and it will print the Strings values correctly: