52

Background

I've recently migrated my app to Android-Studio. I had some issues doing so, but I got over them eventually.

The problem

For some reason, on Android Studio, when I try to sign an APK, I get a lot of errors that look like this:

Error:(16) Error: "..." is not translated in "de" (German), "el" (Greek), "iw" (Hebrew) [MissingTranslation]

(where "..." is a string)

At the bottom, after a lot of errors of this kind, I see this:

Error:Execution failed for task ':app:lintVitalRelease'.
> Lint found fatal errors while assembling a release target.
To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
}
...

The question

I'm not sure what's wrong and how I can fix it. On Eclipse I did it very easily. Missing translations shouldn't stop me from signing an APK...

To me it seems as if Lint is preventing the exporting of the APK, and that the reason is that I didn't translate all of the strings. Is that true?

Can anyone please help me? How can I fix this, so that Lint will show me just warnings instead? or a confirmation dialog if I'm sure I want to do it?

android developer
  • 114,585
  • 152
  • 739
  • 1,270

7 Answers7

114

The cleanest way to solve the problem is to disable Lint checks of missing translations for release builds only.

To do so add "disable 'MissingTranslation'" to your build.gradle file as shown below:

android {
    buildTypes {
        release {
            lintOptions {
                disable 'MissingTranslation'
            }
        }
    }
}
yvolk
  • 2,391
  • 3
  • 21
  • 26
  • In the hope for a better solution. There must be an option to keep non-translated strings. – Rahul Rastogi Jan 22 '17 at 11:27
  • @RahulRastogi That better "solution" would need Android platform support for "language-neutral" strings. Currently I have "strings-international.xml" file with such strings in my project. But I cannot tell Android that this file contains strings that should not be translated. – yvolk Jan 23 '17 at 08:34
  • @yvolk Agree with your point! I made a keys.xml to keep such strings like facebook and google's api keys. – Rahul Rastogi Jan 24 '17 at 07:13
  • @RahulRastogi It appears that there is a way to tell Android that the whole file shouldn't be translated: "If you have a lot of resources that should not be translated, you can place them in a file named donottranslate.xml and lint will consider all of them non-translatable resources" (from http://tools.android.com/recent/non-translatablestrings ). – yvolk Jan 24 '17 at 17:31
  • @yvolk Yeh! I'll try to play with build system (gradle) and Lint to facilitate such feature in my free time. – Rahul Rastogi Jan 25 '17 at 06:38
30

To me it seems as if Lint is preventing the exporting of the APK, and that the reason is that I didn't translate all of the strings. Is that true?

Yes. Default option is lintOptions.abortOnError = true

Can anyone please help me?

You should open the build.gradle file located at the main project module, or the generic folder if you do not have a module. Then add the suggested lines:

android {
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
}

Some Lint warnings are by default turned to studio as errors, I don't actually know why, but in terms of translations I guess that is a way to "stop" you publishing an app that the translation is incomplete due to a last minute additions of some texts.

With the lintOptions checkReleaseBuilds abortOnError you set the checking of Lint not to run for release versions and also not stopping if an "error" is found. Below I explain where the Lint errors settings can be found, so if you want to go further you can go one step forward and read them one by one. Some of them provide helpful instructions for code optimizations.

How can I fix this, so that Lint will show me just warnings instead? or a confirmation dialog if I'm sure I want to do it?

There is also an option at the Android Studio settings to change any Lint error to Lint warning, but I never test that. I usually turn to the gradle solution.

The option is located at Settings > Inspections > Android Lint. For easy find open Settings and at the search (located at the top) type Lint translation there you can change the translation options appear at the left from errors to warnings.

An other option if your error strings never going to be translated is to add at your XML string files tools:ignore="MissingTranslation" either at the root item or at each non-translatable string.

madlymad
  • 6,367
  • 6
  • 37
  • 68
  • Can you please show me where I can change the Lint settings so that it will stay as warnings? Also, what does the fix you've suggested do exactly? Also, I think you mean a different file. "gradle.build" doesn't exist. For some reason, BTW, the messages windows disappear sometimes. – android developer Dec 14 '14 at 19:20
  • He means your module's `build.gradle` – Emmanuel Dec 14 '14 at 20:32
  • @Emmanuel Yes, I've tried it. It works. However, I want to know what are the consequences and what does the solution really do. – android developer Dec 14 '14 at 21:06
  • Regarding the file it was a typo, sorry. I think that I managed to include all the info that related to your extra questions at my answer. – madlymad Dec 14 '14 at 21:29
  • 1
    @madlymad So I could just set "Incomplete translation" in the "Android Lint" list (inside "settings"->"inspections") to be "warning" instead, right? – android developer Dec 17 '14 at 09:09
  • Yes! (Although I have never test it it seems to me that is going to treated as warning and not break the builds. As at the builds it is mentioned "FailOnError" not FailOnWarning") – madlymad Dec 17 '14 at 09:20
  • Simply setting "Incomplete translation" in the "Android Lint" list (inside "settings"->"inspections") to be "warning" didn't solved this, had to resort to the abortOnError. – Henrique de Sousa Jul 20 '15 at 00:13
  • Also the tools:ignore="MissingTranslation" didn't work, I tried ` ` – Henrique de Sousa Jul 20 '15 at 00:21
5

Simple way to solve this Error

Just add following Code To do add "disable 'MissingTranslation'" to your build.gradle file as shown below:

...
  android {
      lintOptions {
          checkReleaseBuilds false
          // Or, if you prefer, you can continue to check for errors in release builds,
          // but continue the build even when errors are found:
          abortOnError false
      }
  }
  ...

OR You can also Add this:

android {
        buildTypes {
            release {
                lintOptions {
                    disable 'MissingTranslation'
                }
            }
        }
    }
Snoopy
  • 71
  • 1
  • 8
1

You could try to open "Translations Editor" and set the string "..." as "Unstranlatable". You also must remove all translations of this string.

valenta
  • 139
  • 1
  • 4
0

FWIW: If you don't plan on supporting other languages, then you don't need to disable the lint checks at all. Sometimes your project setup (or a library you're importing) may have accidentally - or intentionally - included a config to support additional languages by declaring a values- folder for that language like this for instance:

<your project source folder>/main/res/values-ar

This was the case for me so I simply removed the folder. But if you have no control over the offending library then one choice is to disable lint abortOnError as indicated in the accepted answer, or find a way to exclude 'library-imported' folders somehow. For the latter option you can start here

Community
  • 1
  • 1
kip2
  • 6,473
  • 4
  • 55
  • 72
0

there is many solution but i tried

<string name="hello" translatable="false">hello</string>

It's the ignore attribute of the tools namespace in your strings file, as follows:

<?xml version="1.0" encoding="utf-8"?>
<resources
  xmlns:tools="http://schemas.android.com/tools"
  tools:ignore="MissingTranslation" >

  <!-- your strings here; no need now for the translatable attribute -->

</resources>

and from the Gradle

 release {
            lintOptions {
                disable 'MissingTranslation'
            }
        }

and

android {
     lintOptions {
        disable 'MissingTranslation'
    }
}
  • the `tools:ignore="MissingTranslation"` still puts it in the translation editor, though, so `translatable="false"` is still a good thing to put there... – android developer Jul 05 '18 at 06:37
0

Working

             buildTypes {
                        release {
                            lintOptions {
                                checkReleaseBuilds false
                                abortOnError false
                            }
                            minifyEnabled false
                            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                        }
                    }
Keshav Gera
  • 10,807
  • 1
  • 75
  • 53