Issue with latest gradle 5.4.1 - unescaped apostrophe in string


This is our old gradle

classpath 'com.android.tools.build:gradle:3.4.2' ... distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

With the above gradle, we are able to use the following string resource

<string name="reminder_doesnt_work_description"><![CDATA[doesn't]]></string>

But, if we were upgraded to latest gradle

classpath 'com.android.tools.build:gradle:3.5.0' ... distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

We will get the following error

> Multiple task action failures occurred: > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade > Android resource compilation failed C:\yocto\noteplus\app\src\main\res\values\strings.xml:696:5-81: AAPT: error: unescaped apostrophe in string C:\yocto\noteplus\app\src\main\res\values\strings.xml:696:5-81: AAPT: error: not a valid string.

Any idea why such error happen?

Take note, both gradles able to handle string without single quote.

<string name="reminder_doesnt_work_description"><![CDATA[doesnt]]></string>

I had this problem too with unescaped apostrophes in a string resource also using CDATA after Android Studio upgrading my project from Gradle 5.1.1 to 5.4.1.

Funny thing is that after I fixed these AAPT errors by escaping the apostrophes with backslashes, the CDATA text in the string resource lost its carriage returns when being displayed in the app, and appeared just like one huge block of text.

Problem went away when I downgraded back to Gradle 5.1.1

Based on this behavior, I suspect that there is a bug with the way Gradle 5.4.1 is integrated with the Android Studio, causing it to ignore the CDATA token. And so the resource contents are being treated as if no CDATA token is specified. The bug may not be in Gradle itself but its AAPT plugin or some configuration in-between.

I filed an Android Studio bug on this at https://issuetracker.google.com/issues/145430021

I say for now just downgrade Gradle back to 5.1.1


Just Replace all ' in your string resource to \'


Why not just escape the string as AAPT2 demands it?

<string name="reminder_doesnt_work_description">doesn\'t</string>

CDATA sections in XML are meant to be skipped by the XML parser, but this obviously doesn't apply in this case, because that CDATA "section" is within the text-content of a node (and therefore this has zero effect, because it does not contain any node). And if you really would like to use CDATA, then at least encode the < and > to &lt; and &gt; (but this still requires escaping the apostrophes).



  • How to use GPU to accelerate the processing speed of ffmpeg filter?
  • How to do function composition in Sympy?
  • Groovy and Grail plugin is missing in Netbeans IDE 9
  • Camera2 Set Fixed Resolution
  • Continuous colorbar with contour levels
  • Prevent “Too many simultaneous invocations” on formSubmit
  • Why do I get a message saying 1.not.found.as.a.resource?
  • How to start camel even if the MQTT server is not reachable
  • emacs -nw issues with cscope and terminals
  • Can't resize canvas/scale using Fabric.js
  • spring-data-redis Jackson serialization
  • Python Django ImportError: No module named website
  • summarize data from csv using R
  • pyodbc fails without error
  • How to pass a parameter to an included page with JSF 1.2
  • Is there a function to calculate the difference between two times and display a relative result?
  • BREAK ON instruction in MySQL queries?
  • how to synchronize web site content while loading page
  • Joining across databases with dbplyr
  • ASP.NET: replacing UpdatePanel with Jquery?
  • autotest on ubuntu does nothing
  • WSO2 Identity Server + Rest STS Client (without ESB)
  • in Gwt, there are 2 different packages (or 2 options) for doing drag n Drop? Which one is better?
  • Spongycastle is missing many algorithms when loaded on android
  • Can someone explain how Yii minimizing assets is supposed to work on Heroku?
  • Windows: How do I get the mode/access rights of an already opened file?
  • How to close a WebView with double-click?
  • Simultaneous animation when entering editing mode of UITableViewCell
  • Authorize Attribute Authentication with Postman in Web Api
  • cSPADE data mining in R using arulesSequences - Error while converting to “transactions” format
  • PHP: Need to close STDIN in order to read STDOUT?
  • Windows biometric framework sample umdf driver: This device cannot start. (Code 10)
  • Keep rows with certain values always at the bottom while sorting in jquery tablesorter plugin
  • Copy and paste data from multiple workbooks to a worksheet in another Workbook
  • 'Edit' function for forum posts and such
  • Multiplying polynomials/simplifying like terms
  • using maven pom while creating jar:test-jar some times it says JAR will be empty - no content was ma
  • Codeigniniter insert data through models and controller
  • Sign a Pdf using custom digital signature in Java