如何使用非翻译字符串在Android Studio上签署APK ?

时间:2021-08-20 20:51:29

Background

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

我最近将我的应用程序迁移到Android-Studio。我这样做有些问题,但我最终克服了。

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:

出于某种原因,在Android Studio上,当我尝试签署一个APK时,我得到了很多这样的错误:

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

(where "..." is a string)

(where“…”是字符串)

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

我不知道哪里出了问题,也不知道该如何解决。在Eclipse中,我做得很轻松。错过翻译不应该阻止我签署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?

在我看来Lint似乎阻止了APK的导出,原因是我没有翻译所有的字符串。这是真的吗?

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?

谁能帮帮我吗?如何修复这个,让Lint只显示警告?或者确认对话框如果我确定我想这么做?

5 个解决方案

#1


110  

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

解决这个问题的最干净的方法是禁用Lint检查,只检查版本构建中丢失的翻译。

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

为此,在构建中添加“禁用‘MissingTranslation’”。分级文件如下所示:

android {
    buildTypes {
        release {
            lintOptions {
                disable 'MissingTranslation'
            }
        }
    }
}

#2


29  

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?

在我看来Lint似乎阻止了APK的导出,原因是我没有翻译所有的字符串。这是真的吗?

Yes. Default option is lintOptions.abortOnError = true

是的。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.

一些Lint警告在默认情况下变成了studio错误,我不知道为什么,但是就翻译而言,我想这是一种“停止”你发布一个应用程序的方式,这个翻译是不完整的,因为在最后一分钟添加了一些文本。

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.

在lintOptions checkreleasebuild abortOnError中,您设置了对Lint的检查,而不是为发布版本运行,并且在发现“错误”时也不会停止。下面我将解释在哪里可以找到Lint错误设置,因此如果您想更进一步,您可以向前走一步,逐个读取它们。其中一些为代码优化提供了有用的指导。

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?

如何修复这个,让Lint只显示警告?或者确认对话框如果我确定我想这么做?

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.

在Android Studio设置中还有一个选项,可以将任何Lint错误更改为Lint警告,但我从来没有测试过。我通常会求助于gradle解决方案。

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.

该选项位于设置>检查> Android Lint。为了方便地找到打开的设置和搜索(位于顶部)类型的Lint转换,您可以将左边出现的翻译选项从错误更改为警告。

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.

如果您的错误字符串永远不会被翻译,另一个选项是添加到您的XML字符串文件工具:ignore=“MissingTranslation”,要么在根项上,要么在每个不可翻译的字符串中。

#3


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'
                }
            }
        }
    }

#4


1  

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

您可以尝试打开“翻译编辑器”,并将字符串“…”设置为“un搁浅”。您还必须删除这个字符串的所有翻译。

#5


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:

FWIW:如果您不打算支持其他语言,那么您根本不需要禁用lint检查。有时,您的项目设置(或您正在导入的库)可能无意中(或有意地)包含了一个配置,通过声明一个值来支持其他语言——例如,该语言的文件夹:

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

<您的项目源文件夹> /主/ 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

这是我的情况,所以我只是删除了文件夹。但是,如果您无法控制出错的库,那么一个选择是禁用lint abortOnError,如所接受的答案所示,或者找到一种方法以某种方式排除“库导入”文件夹。对于后者,您可以从这里开始

#1


110  

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

解决这个问题的最干净的方法是禁用Lint检查,只检查版本构建中丢失的翻译。

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

为此,在构建中添加“禁用‘MissingTranslation’”。分级文件如下所示:

android {
    buildTypes {
        release {
            lintOptions {
                disable 'MissingTranslation'
            }
        }
    }
}

#2


29  

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?

在我看来Lint似乎阻止了APK的导出,原因是我没有翻译所有的字符串。这是真的吗?

Yes. Default option is lintOptions.abortOnError = true

是的。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.

一些Lint警告在默认情况下变成了studio错误,我不知道为什么,但是就翻译而言,我想这是一种“停止”你发布一个应用程序的方式,这个翻译是不完整的,因为在最后一分钟添加了一些文本。

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.

在lintOptions checkreleasebuild abortOnError中,您设置了对Lint的检查,而不是为发布版本运行,并且在发现“错误”时也不会停止。下面我将解释在哪里可以找到Lint错误设置,因此如果您想更进一步,您可以向前走一步,逐个读取它们。其中一些为代码优化提供了有用的指导。

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?

如何修复这个,让Lint只显示警告?或者确认对话框如果我确定我想这么做?

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.

在Android Studio设置中还有一个选项,可以将任何Lint错误更改为Lint警告,但我从来没有测试过。我通常会求助于gradle解决方案。

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.

该选项位于设置>检查> Android Lint。为了方便地找到打开的设置和搜索(位于顶部)类型的Lint转换,您可以将左边出现的翻译选项从错误更改为警告。

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.

如果您的错误字符串永远不会被翻译,另一个选项是添加到您的XML字符串文件工具:ignore=“MissingTranslation”,要么在根项上,要么在每个不可翻译的字符串中。

#3


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'
                }
            }
        }
    }

#4


1  

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

您可以尝试打开“翻译编辑器”,并将字符串“…”设置为“un搁浅”。您还必须删除这个字符串的所有翻译。

#5


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:

FWIW:如果您不打算支持其他语言,那么您根本不需要禁用lint检查。有时,您的项目设置(或您正在导入的库)可能无意中(或有意地)包含了一个配置,通过声明一个值来支持其他语言——例如,该语言的文件夹:

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

<您的项目源文件夹> /主/ 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

这是我的情况,所以我只是删除了文件夹。但是,如果您无法控制出错的库,那么一个选择是禁用lint abortOnError,如所接受的答案所示,或者找到一种方法以某种方式排除“库导入”文件夹。对于后者,您可以从这里开始