android studio 与 Java 编译器错误:字符串太大而无法使用 UTF-8 编码,而不是编写为“STRING_TOO_LARGE”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52229987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
android studio with Java compiler error: string too large to encode using UTF-8 written instead as 'STRING_TOO_LARGE'
提问by Xianwei
When I clean the android project in android studio, the error happen, I have backed to previous commit or different branch, which works find couple days ago, but has this error now. I have checked this question and there is not large image or strings added for my project. STRING_TOO_LARGE String in Kothlin
当我在 android studio 中清理 android 项目时,错误发生了,我已经回到以前的提交或不同的分支,这几天前找到了,但现在有这个错误。我已经检查了这个问题,并且没有为我的项目添加大图像或字符串。Kothlin 中的 STRING_TOO_LARGE 字符串
采纳答案by stevyhacker
For the time being, you can downgrade Gradle version to resolve this issue. Use gradle 3.1 version like 3.1.3 below.
目前,您可以降级 Gradle 版本来解决此问题。使用 gradle 3.1 版本,如下面的 3.1.3。
classpath 'com.android.tools.build:gradle:3.1.3'
回答by Veener
You can use AAPT (from the android sdk/build-tools) to examine the APK and look for the offending string with the following command line (Linux):
您可以使用 AAPT(来自 android sdk/build-tools)来检查 APK 并使用以下命令行(Linux)查找有问题的字符串:
// Linux/Mac
./aapt dump --values resources MyAppName-regular-debug.apk | grep -B 1 'STRING_TOO_LARGE'
// Windows
aapt dump --values resources MyAppName-regular-debug.apk | grep -B 1 'STRING_TOO_LARGE'
Which should point you to the culprit. In my case it was:
这应该指向你的罪魁祸首。就我而言,它是:
resource 0x7f0f015a com.example.app:string/eula: t=0x03 d=0x00000f10 (s=0x0008 r=0x00)
(string8) "STRING_TOO_LARGE"
回答by Kalu Khan Luhar
I had encountered the same and fixed by clear the build cache.
我遇到了同样的问题,并通过清除构建缓存来修复。
回答by ILMTL
I was stuck on this problem and read through this topic and no one provided a future solution. I did NOT want to revert back my Gradle. Therefore, here is the link to the updated dependencies https://github.com/stripe/stripe-android. Look for the "Android Studio (or Gradle)" section and you should see this "implementation 'com.stripe:stripe-android:8.1.0'"
also you might need to add "-keep class com.stripe.android.** { *; }"
if you are enabling minification in your build.gradle file.
我被困在这个问题上并通读了这个主题,没有人提供未来的解决方案。我不想恢复我的 Gradle。因此,这里是更新的依赖项https://github.com/stripe/stripe-android的链接。查找“Android Studio(或 Gradle)”部分,如果您在 build.gradle 文件中启用缩小,您应该"implementation 'com.stripe:stripe-android:8.1.0'"
也会看到您可能需要添加"-keep class com.stripe.android.** { *; }"
的部分。
Overall Stripe has stopped updating their own "Stripe docs" which can be found here. To give them credit their docs are helpful and should be read at least once, but be mindful that most of the docs are out date when I wrote this...
总体而言,Stripe 已停止更新他们自己的“Stripe 文档”,可在此处找到。为了给他们信用,他们的文档很有帮助,应该至少阅读一次,但请注意,当我写这篇文章时,大多数文档已经过时了......
Hope this helps :)
希望这可以帮助 :)
回答by PGMacDesign
None of the above solutions worked for me. What ended up being the cause of the problem was, as it states, a String that was too large. Specifically, in my arrays.xmlfile under the values directory, I had some SVG arrays that were used within my app and commenting them out solved the issue.
以上解决方案都不适合我。正如它所说,最终导致问题的原因是一个太大的字符串。具体来说,在values 目录下的arrays.xml文件中,我有一些在我的应用程序中使用的 SVG 数组并将它们注释掉解决了这个问题。
If you know for certain you have some longer Strings somewhere in your resource directories (/res), check for any large Strings that may be lurking.
如果您确定您的资源目录 ( /res) 中某处有一些更长的字符串,请检查可能潜伏的任何大字符串。
Also, this solutionmay help others but was not linked to in this thread.
此外,此解决方案可能会帮助其他人,但未在此线程中链接。
回答by Masum
just use <?xml version="1.0" encoding="utf-8"?>
before in your drawable file.
只需<?xml version="1.0" encoding="utf-8"?>
在可绘制文件中使用before 。
Example:
例子:
<?xml version="1.0" encoding="utf-8"?>
<vector
android:autoMirrored="true"
android:height="24dp"
android:viewportHeight="490.282"
android:viewportWidth="490.282"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="#fff"
android:pathData="M0.043,245.197c0.6,10.1 7.3,18.6 17,21.5l179.6,54.3l6.6,123.8c0.3,4.9 3.6,9.2 8.3,10.8c1.3,0.5 2.7,0.7 4,0.7c3.5,0 6.8,-1.4 9.2,-4.1l63.5,-70.3l90,62.3c4,2.8 8.7,4.3 13.6,4.3c11.3,0 21.1,-8 23.5,-19.2l74.7,-380.7c0.9,-4.4 -0.8,-9 -4.2,-11.8c-3.5,-2.9 -8.2,-3.6 -12.4,-1.9l-459,186.8C5.143,225.897 -0.557,235.097 0.043,245.197zM226.043,414.097l-4.1,-78.1l46,31.8L226.043,414.097zM391.443,423.597l-163.8,-113.4l229.7,-222.2L391.443,423.597zM432.143,78.197l-227.1,219.7l-179.4,-54.2L432.143,78.197z"/>
</vector>
回答by Ven Ren
回答by FractalBob
In my case, the problem was due to the following lines in the manifest:
就我而言,问题是由于清单中的以下几行:
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"/>
Once I deleted them, the build went fine.
一旦我删除了它们,构建就会顺利进行。
回答by parvez rafi
Just use gradlew cleanBuildCache in your Android studio terminal
只需在您的 Android Studio 终端中使用 gradlew cleanBuildCache
回答by Prashant Paliwal
In my case, i deleted a view from xml but forgot to remove its references in my kotlin code. Make sure to check this before doing anything fancy.
就我而言,我从 xml 中删除了一个视图,但忘记在我的 kotlin 代码中删除它的引用。在做任何花哨的事情之前,一定要检查一下。