15

Java compiler error: string too large to encode using UTF-8 written instead as 'STRING_TOO_LARGE'.

I want to note, that there I have no long string and no one vector drawable that bigger than 32kb (biggest is 3.7kb).

Gradle 3.2.0, build tool 28.0.3

What can take a problem?

Tigran Babajanyan
  • 1,967
  • 1
  • 22
  • 41
  • Are you having any **hardcoded string** which is too long? – Jeel Vankhede Oct 01 '18 at 10:30
  • Good question, but no have – Tigran Babajanyan Oct 01 '18 at 10:33
  • Without seeing any of your code it's hard to do anything other than taking a guess at what might be potentially a possible problem. Currently all that we can see is that there is in all likelihood a String that is too large to be encoded, else you would not get the error message. How that String is built and why it exists... that's a question that we can not really answer. You might want to elaborate your question a bit further so we can see a bit further down the rabbit hole and help finding a solution :) – Ben Oct 01 '18 at 10:36
  • There is a similar question on Russian SO. Proposed solution is to use **--debug** and **--stacktrace** build options to identify exact string – Maxim Oct 01 '18 at 10:38
  • @AbhinavGupta as I said in question I have now such a resource – Tigran Babajanyan Oct 01 '18 at 10:40
  • copy paste your longest string to find if converted UTF-8 length is greater than 32767 also, convert it using UTF-16 to find out if length is greater than 2147483647. You can use https://www.browserling.com/tools/utf8-encode and https://www.browserling.com/tools/utf16-encode – Rahul Oct 01 '18 at 10:47
  • @Maxim, can you give me link, I understand Russian – Tigran Babajanyan Oct 01 '18 at 10:59
  • 1
    @TigranBabajanyan [here the thread](https://ru.stackoverflow.com/questions/847239/string-too-large-%D0%BF%D1%80%D0%B8-%D0%BA%D0%BE%D0%BC%D0%BF%D0%B8%D0%BB%D1%8F%D1%86%D0%B8%D0%B8-%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B0-%D0%B2-android-studio) mentioned. As I understood the problem was in two different versions of a third-party library – Maxim Oct 01 '18 at 11:12
  • @Maxim after adding --debug and --stacktrace my error not appearing, don't know why – Tigran Babajanyan Oct 01 '18 at 11:44
  • 1
    I had encountered the same and fixed by clear the build cache. For more info: https://developer.android.com/studio/build/build-cache#clear_the_build_cache – Kalu Khan Luhar Oct 31 '18 at 10:48
  • 2
    If someone are lazy and doesn't have to look for @Kalu Khan Luhar link for clean build cache just use in terminal: `./gradlew cleanBuildCache` – wrozwad Nov 27 '18 at 10:07
  • @sosite if that helped you, its good, but problem there is case when that doesn't help – Tigran Babajanyan Nov 27 '18 at 11:12
  • is data binding enabled in your project – a0x2 Nov 02 '19 at 11:41
  • it will be helpful for others!! – a0x2 Nov 04 '19 at 10:09
  • @a2en, yes of course, but I don't remember – Tigran Babajanyan Nov 04 '19 at 11:43

3 Answers3

2

Run this in your terminal

./gradlew cleanBuildCache 

(in my case I need to do this several times until it helps)

Cube
  • 362
  • 4
  • 8
1

Check your vector drawables there may be a big path. I came across same issue and i solved it by deleting big vector drawable it.

Mirza Ahmed Baig
  • 5,605
  • 3
  • 22
  • 39
-3

Use gradle 3.2 version like 3.2.1 below.

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