52

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

Benjamin
  • 15
  • 1
  • 6
Xianwei
  • 2,381
  • 2
  • 22
  • 26

23 Answers23

23

I had encountered the same and fixed by clear the build cache .

Kalu Khan Luhar
  • 1,044
  • 1
  • 22
  • 35
18

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.

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

Hope this helps :)

PGMacDesign
  • 6,092
  • 8
  • 41
  • 78
ILMTL
  • 211
  • 3
  • 5
15

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):

// 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"
Veener
  • 4,771
  • 2
  • 29
  • 37
  • 1
    This is the best way how to figure out which string is too long! Thank you. – Vit Veres Jun 25 '19 at 09:42
  • 5
    Nothing appears when I use this command line. Does it mean, it does not come from a string? – Safety Jun 26 '19 at 12:58
  • I get nothing as well – Csa77 Jan 26 '20 at 18:29
  • 4
    This is a great solution, however this command didn't work for me, so I just decompiled my apk (use any online decompiler) and then ran: `grep -r "STRING_TOO_LARGE" /decompiled_apk_folder`. In my case it pointed me directly to the problematic SVG file. – Makks129 Mar 03 '20 at 09:35
13

For the time being, you can downgrade Gradle version to resolve this issue. Use gradle 3.1 version like 3.1.3 below.

  classpath 'com.android.tools.build:gradle:3.1.3'
stevyhacker
  • 1,847
  • 2
  • 23
  • 31
  • 4
    I got this error, when I upgraded gradle from 3.1.3 to 3.2.0, i don't want to use the version below 3.2.0 – Ghizlane Lotfi Nov 19 '18 at 11:11
  • 2
    I always get this error when attempting to add the stripe library "com.stripe:stripe-android:6.1.2" to any project including an empty one. I can sometimes get it go away by deleting the Gradle dirs and resyncing, but downgrading Gradle plugin seems to be the only reliable option to make it go away permanently [Gradle Plugin Versions](https://developer.android.com/studio/releases/gradle-plugin) – Elletlar Dec 07 '18 at 18:32
  • 11
    @Elletlar and anyone who had this problem because of Stripe SDK: Version 6.1.2 of the SDK includes a vector drawable with a very long path. That path is the one generating the error and that's what gets replaced with "STRING_TOO_LARGE". They fixed it in this commit https://github.com/stripe/stripe-android/pull/547 so any version including this fix (7.0.0 upwards) makes the error go away. I'm using 8.1.0 at the time of writing. – Cosmin Radu Dec 11 '18 at 10:30
  • Thanks that is a big help. I followed Stripe's integration guide: [Guide](https://stripe.com/docs/mobile/android). They still advocate to use "implementation 'com.stripe:stripe-android:6.1.2'". I suppose that no one is updating their guide...Regards. – Elletlar Dec 11 '18 at 14:33
  • 34
    This is not a solution! – Dawid Hyży Apr 30 '19 at 05:37
  • 3
    Downgrading seems a bit hacky to me. – Robin Hood May 05 '19 at 21:21
  • Doesn't work with Android Studio 3.5.2; get error 'ERROR: JAVA_LETTER_OR_DIGIT' – FractalBob Nov 18 '19 at 14:06
  • Of course this was not the solution, just a temporary workaround at the time. – stevyhacker May 06 '20 at 11:52
  • @CosminRadu Having this problem again on 20.15.2 but not sure if it's related – Tamim Attafi Nov 15 '22 at 12:43
  • Are we still going to use this method in 2023? – eric xu Jan 05 '23 at 06:47
13

It happens that I had an SVG too long (90Kb). So I've opened de SVG in Adobe illustrator, simplified the path to a significant number of vector less so the new icon weight 3Kb and, finally, imported again in Android Studio.

You can have a look at your Project in Android Studio and watch if your SVG drawables are larger than needed for an icon.

screenshot of project in Android Studio, showing the weight of drawables

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Xavier Caliz
  • 143
  • 2
  • 9
10

just use <?xml version="1.0" encoding="utf-8"?> before in your drawable file.

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>
Masum
  • 1,037
  • 15
  • 32
7

I've been hunting for the source of STRING_TOO_LARGE errors in our build for a long time and none of these solutions worked. The reason none of them worked was that I had progaurd turned on in debug builds so when the string was replaced it didn't end up in the apk. When i disabled progaurd for debug builds, built the apk and then decompiled with apktool as suggested elsewhere

java -jar apktool_2.4.1.jar d debug.apk 

and found the xml file that was in another library but progaurd stripped out before:

grep -r "STRING_TOO_LARGE" ./debug

Hope that helps someone

bsautner
  • 4,479
  • 1
  • 36
  • 50
6

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.xml file under the values directory, I had some SVG arrays that were used within my app and commenting them out solved the issue.

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.

Also, this solution may help others but was not linked to in this thread.

PGMacDesign
  • 6,092
  • 8
  • 41
  • 78
5

I found an SVG file that had a very long pathData. I commented it out and the error went away. That very same vector (when called) at runtime would cause a crash (before it was commented out).

seekingStillness
  • 4,833
  • 5
  • 38
  • 68
5

The issue is caused by the AAPT/AAPT2 (Android Asset Packaging Tool) which processes your app’s resources and replaces them with the STRING_TOO_LARGE value when it finds a large string.

Find out for which one cause this problem. To find out follow below steps:

A. Best Way:

  1. Generate build APK
  2. Decompile APK using any decompiler and download it.
  3. Open it in any editor(Ex. VS Code)
  4. Then search "STRING_TOO_LARGE" text globally and you will find affected files. enter image description here

B. Another Way

  1. The simplest way to find out, Builds an APK and analyze it. Select Build > Build Bundle(s) / APK(s) > Build APK(s). When the build completes, a confirmation notification appears, providing a link to the APK file and a link to analyze it in the APK Analyzer.

enter image description here

  1. If you take a look into the the vector drawable file affected by this issue, you will find something like this:

enter image description here

I found this solution from Here

Milan Maji
  • 363
  • 1
  • 5
  • 9
3

clear your gradle in windows

gradlew cleanBuildCache

in mac

./gradlew cleanBuildCache

then building you apk if your project has problem it will be show you in the 'Messages' view. location your problem and fix it. run agent.

enter image description here

Ven Ren
  • 1,584
  • 1
  • 13
  • 24
1

Just use gradlew cleanBuildCache in your Android studio terminal

parvez rafi
  • 464
  • 4
  • 20
1

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.

1

I found the answer from a duplicate question for Kotlin from here

Add <?xml version="1.0" encoding="utf-8"?> to the top of any resource .xml file that is missing it. (check your layout xml files, specially)

Emad Razavi
  • 1,903
  • 2
  • 17
  • 24
1

For me "gradlew cleanBuildCache" did not work, and running aapt dump --values resources MyAppName-regular-debug.apk | grep -B 1 'STRING_TOO_LARGE' did nothing either...

I ended up just deleting all my vector images since they were all pretty large and that fixed my build.. So I guess I'll have to add those back in a way that does not throw the error again..

Sarah Mica
  • 121
  • 1
  • 7
1

In my case, I had renamed the package and the output-metadata.json contained the old package name. Renamed the package name there, and it was fixed.

hardik parmar
  • 853
  • 8
  • 15
0

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.

FractalBob
  • 3,225
  • 4
  • 29
  • 40
0

In my case I declared a string variable in xml using data binding without assigning a value to it. by setting value to variable problem resolved

Vahid
  • 1,588
  • 4
  • 22
  • 34
0

Windows 10 Solution

Finding the file with the error: use a online decompiler if it's not a problem is some one else sees your code. Download .zip file. Open up notepad++ search -> Find in files -> STRING_TOO_LARGE -> Find all.

If the problem file is a vector asset:

Vikasdeep Singh has a great solution: avocado. Avocado will make the vector file smaller.

  • Yep!, in my case one of my vector asset file was "too big" and causing the app to crash. – Manu Nov 05 '20 at 01:37
0

I had this problem and clearing the cache or updating the Gradle plugin version was not a solution

To solve the problem I had to change the name of the longest XML file to make it a bit shorter, and right after doing that the problem was solved.

Eric Ampire
  • 289
  • 2
  • 6
-1

Add this to Gradle.properties

org.gradle.unsafe.configuration-cache=true
helvete
  • 2,455
  • 13
  • 33
  • 37
-2

In my case I use Invalidate cache and restore go to file/Invalidate cache and restore

-5

instead of this

org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8

Replaced it with this in the gradle.properties

org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=STRING_TOO_LARGE
Ole Pannier
  • 3,208
  • 9
  • 22
  • 33