Error in strings.xml file in Android

前端 未结 9 582
[愿得一人]
[愿得一人] 2020-11-28 04:37

I have declared a long string in string.xml of an application.

Declared like this

PLEASE READ THESE TERMS          


        
相关标签:
9条回答
  • 2020-11-28 05:34

    You have to put \ before an apostrophe. Like this \' , Also check that you are editing strings.xml and not values.xml (android studio directs you to this file when shows the error). Because if you edit values.xml and try to compile again, the error persists. This was happening to me recently.

    0 讨论(0)
  • 2020-11-28 05:35

    1. for error: unescaped apostrophe in string

    what I found is that AAPT2 tool points to wrong row in xml, sometimes. So you should correct whole strings.xml file

    In Android Studio, in problem file use :

    Edit->find->replace

    Then write in first field \' (or \&,>,\<,\")
    in second put '(or &,>,<,")
    then replace each if needed.(or "reptlace all" in case with ')
    Then in first field again put '(or &,>,<,")
    and in second write \'
    then replace each if needed.(or "replace all" in case with ')

    2. for other problematic symbols
    I use to comment each next half part +rebuild until i won't find the wrong sign.

    E.g. an escaped word "\update" unexpectedly drops such error :)

    0 讨论(0)
  • 2020-11-28 05:39

    Solution

    Apostrophes in the strings.xml should be written as

    \'
    


    Example

    In my case I had an error with this string in my strings.xml and I fixed it.

    <item>Most arguments can be ended with three words, "I don\'t care".</item>
    

    Here you see my app builds properly with that code.

    enter image description here

    Here is the actual string in my app.

    enter image description here

    0 讨论(0)
提交回复
热议问题