最新gradle 5.4.1的问题-字符串中未转义的撇号 [英] Issue with latest gradle 5.4.1 - unescaped apostrophe in string

查看:1133
本文介绍了最新gradle 5.4.1的问题-字符串中未转义的撇号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我们的老祖宗

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

通过上述方法,我们可以使用以下字符串资源

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

但是,如果我们升级到最新的gradle

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

我们将收到以下错误

> 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.

知道为什么会发生这种错误吗?

请注意,两个等级都可以处理字符串而无需单引号.

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

解决方案

在Android Studio将项目从Gradle 5.1.1升级到5.4.1之后,我也使用CDATA在字符串资源中使用未转义的撇号. >

有趣的是,在我通过用反斜杠转义撇号解决了这些AAPT错误之后,字符串资源中的CDATA文本在应用程序中显示时丢失了回车符,并且看起来就像一个巨大的文本块.

当我降级到Gradle 5.1.1时,问题消失了

基于此行为,我怀疑Gradle 5.4.1与Android Studio集成的方式存在错误,导致其忽略了CDATA令牌.因此,资源内容就像没有指定CDATA令牌一样被对待.该错误可能不在Gradle本身中,而是在其AAPT插件或两者之间的某些配置中.

我在 https://issuetracker.google.com/issues/上对此提交了Android Studio错误. 145430021

我说现在暂时将Gradle降级到5.1.1

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

这篇关于最新gradle 5.4.1的问题-字符串中未转义的撇号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆