15

i have the following remote config_default.xml file

<?xml version="1.0" encoding="utf-8"?>
<defaultsMap>
       <entry>
            <key>LOCAL_JSON</key>
            <value>[{"title":"TitleA","path":"pathA","image_url":" Some URL A"},{"title":"TitleB","path":"pathB","image_url":" Some URL B"}]</value>
        </entry>
</defaultsMap>

Now when i try to access it using Firebase remote config getString() method, i always get the string without quotes

"[{title:TitleA,path:pathA,image_url: Some URL A},{title:TitleB,path:pathB,image_url: Some URL B}]"§

as seen in the image below

enter image description here

I put the same String on Firebase remote config console and once the app fetches it from there it places the double quotes in the string like i expect it.

I double checked this and it seems to be working fine when i use the following project gradle file

    apply plugin: 'com.github.ben-manes.versions'
    buildscript {
        repositories {
            maven { url "http://dl.bintray.com/populov/maven" }
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.3.3'
            classpath 'me.tatarka:gradle-retrolambda:3.6.1'
            classpath 'com.github.ben-manes:gradle-versions-plugin:0.13.0'
            classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.2.1'
            classpath 'com.google.gms:google-services:3.1.0'
            classpath 'com.google.firebase:firebase-plugins:1.0.5'
        }
    }

    allprojects {
        repositories {
            maven { url "http://dl.bintray.com/populov/maven" }
            maven { url "http://oss.sonatype.org/content/repositories/snapshots" }
            maven { url "https://jitpack.io" }
            jcenter()
            flatDir {
                dirs 'libs'
            }
        }
    }

But when i update the gradle to use new versions for all libraries The quotes seemed to be ignored only then. My new project gradle file

apply plugin: 'com.github.ben-manes.versions'
buildscript {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.github.ben-manes:gradle-versions-plugin:0.13.0'
        classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.2.1'
        classpath 'com.google.gms:google-services:3.1.2'
        classpath ('com.google.firebase:firebase-plugins:1.0.5')
    }
}

allprojects {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        maven { url "http://oss.sonatype.org/content/repositories/snapshots" }
        maven { url "https://jitpack.io" }
        jcenter()
        google()
        flatDir {
            dirs 'libs'
        }
    }
}

I don't know which of the library is causing this to happen but it would be great if someone could point it out.

Sheraz Ahmad Khilji
  • 8,300
  • 9
  • 52
  • 84
  • Try escaping your quotes by saying " instead of ". – Doug Stevenson Dec 13 '17 at 19:33
  • 1
    @DougStevenson tried it, doesn't change the output still the same :( – Sheraz Ahmad Khilji Dec 13 '17 at 20:00
  • https://groups.google.com/forum/#!topic/firebase-talk/LIzdfsWm9bU – Doug Stevenson Dec 13 '17 at 20:17
  • I'd encourage you to file a bug report to add weight to the issue. https://firebase.google.com/support/contact/bugs-features/ – Doug Stevenson Dec 13 '17 at 20:18
  • The quotes in default Remote Config is a known issue and we are working on a fix. Quotes in parameters from the server work as expected the issue is limited to quotes in the default XML. – Arthur Thompson Dec 13 '17 at 22:32
  • @DougStevenson filed the bug report. Lets wait and see – Sheraz Ahmad Khilji Dec 14 '17 at 10:45
  • I have created a bug report a while ago and it is closed with probably a misunderstanding. https://issuetracker.google.com/issues/65039971 – Hadi Tok Jan 19 '18 at 12:27
  • a workaround i've resorted to, which is not ideal, is to use something other than quotation marks --- e.g., the pipe (|) --- then String.replace('|', '"') on the value returned from Remote Config. you of course must ensure the alternative char does not naturally occur in your JSON. also, both your defaults AND the ones in the console have to employ this alternative char. – Steve Yohanan Jan 26 '18 at 21:10

4 Answers4

2

Hi Sheraz Ahmad Khilji first of all, I apologize for the English, I don't know how to write english very well.

This problems occours because firebase has a bug when converting your xml in a Map, to contorn this problem, you can use a MAP instead of a xml.

sample:

firebaseConfig.setDefaults(Map<String, Object>);

This change will solve your problem with double quotes.

1

I sent this issue to the firebase help team and got the following response:

This is actually a known issue on our end and our engineers are already working to fix the issue. I can't share any details or timeline when the fix be available, but please check our release notes for future updates.

Looks like there is a problem with Gradle tools version 3.0.1. The temporary workaround would be to use Gradle tools version 2.3.3.

In the project level build.gradle file:

Replace classpath 'com.android.tools.build:gradle:3.0.1' with

classpath 'com.android.tools.build:gradle:2.3.3'

and

Relpace google() with

maven {
        url 'https://maven.google.com'
}
Nabin Bhandari
  • 15,949
  • 6
  • 45
  • 59
  • +1 for the official reply, but I think that downgrading gradle because of this is not worth it. I fortunately was able to rephrase the string value and remove all quotes. – gswierczynski Aug 19 '18 at 11:02
  • @gswierczynski I agree with you. Or you can use some encoding such as Base64. Also the problem exists only for local copy of the config, data received from the remote side is not affected. – Nabin Bhandari Aug 19 '18 at 11:03
0

There are multiple solutions for this problem

1. Use firebaseConfig.setDefaults(Map); for setting up the default configuration.

2. Use backslash (\) before Double Quotes(") in your String in .xml file.

3. Replace classpath 'com.android.tools.build:gradle:3.0.1' with

*classpath 'com.android.tools.build:gradle:2.3.3'* 

and Relpace google() with
maven { url 'https://maven.google.com' }

4. Add android.enableAapt2 = false in gradle.properties

Ankit Kumar
  • 276
  • 4
  • 6
0

If, at defaults xml file, you use triple-backslash as escape sequence, it works:

{\\\"someKey\\\": \\\"someValue\\\"}

Will produce {"someKey": "someValue"} as output of FirebaseRemoteConfig's getString() method.