运行cordova build -release android时出错

时间:2015-05-20 09:36:54

标签: android cordova ionic-framework ionic

我正按照此处的说明尝试发布我的Android应用:

http://ionicframework.com/docs/guide/publishing.html

然而,当我运行cordova build --release android时,我收到以下错误:

:lintVitalArmv7Release
/Users/xxx/Documents/xxx/xxx/platforms/android/res/values/arrays.xml:3: Error: "country_codes" is not translated in "ar" (Arabic), "bg" (Bulgarian), "ca" (Catalan), "cs" (Czech), "da" (Danish), "de" (German), "el" (Greek), "es" (Spanish), "eu" (Basque), "fi" (Finnish), "fr" (French), "he" (Hebrew), "hi" (Hindi), "hu" (Hungarian), "id" (Indonesian), "it" (Italian), "iw" (Hebrew), "ja" (Japanese), "ko" (Korean), "nl" (Dutch), "pl" (Polish), "pt" (Portuguese), "ru" (Russian), "sk" (Slovak), "sl" (Slovene), "sv" (Swedish), "tr" (Turkish), "zh-rCN" (Chinese: China), "zh-rTW" (Chinese: Taiwan, Province of China) [MissingTranslation]
  <string-array name="country_codes">
                ~~~~~~~~~~~~~~~~~~~~
/Users/xxx/Documents/xxx/xxx/platforms/android/res/values/strings.xml:3: Error: "app_name" is not translated in "ar" (Arabic), "bg" (Bulgarian), "ca" (Catalan), "cs" (Czech), "da" (Danish), "de" (German), "el" (Greek), "es" (Spanish), "eu" (Basque), "fi" (Finnish), "fr" (French), "he" (Hebrew), "hi" (Hindi), "hu" (Hungarian), "id" (Indonesian), "it" (Italian), "iw" (Hebrew), "ja" (Japanese), "ko" (Korean), "nl" (Dutch), "pl" (Polish), "pt" (Portuguese), "ru" (Russian), "sk" (Slovak), "sl" (Slovene), "sv" (Swedish), "tr" (Turkish), "zh-rCN" (Chinese: China), "zh-rTW" (Chinese: Taiwan, Province of China) [MissingTranslation]
    <string name="app_name">myapp</string>
            ~~~~~~~~~~~~~~~
/Users/xxx/Documents/xxx/xxx/platforms/android/res/values/strings.xml:4: Error: "launcher_name" is not translated in "ar" (Arabic), "bg" (Bulgarian), "ca" (Catalan), "cs" (Czech), "da" (Danish), "de" (German), "el" (Greek), "es" (Spanish), "eu" (Basque), "fi" (Finnish), "fr" (French), "he" (Hebrew), "hi" (Hindi), "hu" (Hungarian), "id" (Indonesian), "it" (Italian), "iw" (Hebrew), "ja" (Japanese), "ko" (Korean), "nl" (Dutch), "pl" (Polish), "pt" (Portuguese), "ru" (Russian), "sk" (Slovak), "sl" (Slovene), "sv" (Swedish), "tr" (Turkish), "zh-rCN" (Chinese: China), "zh-rTW" (Chinese: Taiwan, Province of China) [MissingTranslation]
    <string name="launcher_name">@string/app_name</string>
            ~~~~~~~~~~~~~~~~~~~~
/Users/xxx/Documents/xxx/xxx/platforms/android/res/values/strings.xml:5: Error: "activity_name" is not translated in "ar" (Arabic), "bg" (Bulgarian), "ca" (Catalan), "cs" (Czech), "da" (Danish), "de" (German), "el" (Greek), "es" (Spanish), "eu" (Basque), "fi" (Finnish), "fr" (French), "he" (Hebrew), "hi" (Hindi), "hu" (Hungarian), "id" (Indonesian), "it" (Italian), "iw" (Hebrew), "ja" (Japanese), "ko" (Korean), "nl" (Dutch), "pl" (Polish), "pt" (Portuguese), "ru" (Russian), "sk" (Slovak), "sl" (Slovene), "sv" (Swedish), "tr" (Turkish), "zh-rCN" (Chinese: China), "zh-rTW" (Chinese: Taiwan, Province of China) [MissingTranslation]
    <string name="activity_name">@string/launcher_name</string>
            ~~~~~~~~~~~~~~~~~~~~

   Explanation for issues of type "MissingTranslation":
   If an application has more than one locale, then all the strings declared
   in one language should also be translated in all other languages.

   If the string should not be translated, you can add the attribute
   translatable="false" on the <string> element, or you can define all your
   non-translatable strings in a resource file called donottranslate.xml. Or,
   you can ignore the issue with a tools:ignore="MissingTranslation"
   attribute.

   By default this detector allows regions of a language to just provide a
   subset of the strings and fall back to the standard language strings. You
   can require all regions to provide a full translation by setting the
   environment variable ANDROID_LINT_COMPLETE_REGIONS.

   You can tell lint (and other tools) which language is the default language
   in your res/values/ folder by specifying tools:locale="languageCode" for
   the root <resources> element in your resource file. (The tools prefix
   refers to the namespace declaration http://schemas.android.com/tools.)

/Users/xxx/Documents/xxx/xxx/platforms/android/res/values-ar/strings.xml:64: Error: "menu_settings" is translated here but not found in default locale [ExtraTranslation]
  <string name="menu_settings">???????</string>
    5 errors, 0 warnings
    :lintVitalArmv7Release FAILED

    FAILURE: Build failed with an exception.

    * What went wrong:
    Execution failed for task ':lintVitalArmv7Release'.
    > 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
          }
      }
      ...

    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

    BUILD FAILED

    Total time: 4.583 secs

    /Users/xxx/Documents/xxx/xxx/platforms/android/cordova/node_modules/q/q.js:126
                        throw e;
                              ^
    Error code 1 for command: /Users/xxx/Documents/xxx/xxx/platforms/android/gradlew with args: cdvBuildRelease,-b,/Users/xxx/Documents/xxx/xxx/platforms/android/build.gradle,-Dorg.gradle.daemon=true
    ERROR building one of the platforms: Error: /Users/xxx/Documents/xxx/xxx/platforms/android/cordova/build: Command failed with exit code 8
    You may not have the required environment or OS to build this project
    Error: /Users/xxx/Documents/xxx/xxx/platforms/android/cordova/build: Command failed with exit code 8
        at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:131:23)
        at ChildProcess.emit (events.js:98:17)
        at maybeClose (child_process.js:766:16)
        at Process.ChildProcess._handle.onexit (child_process.js:833:5)

我可以运行离子构建android并且可以毫无问题地部署到模拟器。

我已经尝试过搜索lintOptions和build.gradle但我在项目的任何地方找不到它们......

有人可以帮忙吗?提前致谢

8 个答案:

答案 0 :(得分:39)

通过添加

解决了这个问题
lintOptions {
    abortOnError false
}

到/platforms/android/build.gradle中的android {}部分

答案 1 :(得分:33)

将以下条目添加到Ionic项目中的/platforms/android/build.gradle文件中:

android {
   lintOptions { disable 'MissingTranslation', 'ExtraTranslation' }
}

的工作。

答案 2 :(得分:15)

对于那些喜欢将platforms目录保留在VCS(Git等)之外的人,
目前最好的解决方案是使用名为ignore-lint-translation的插件。

cordova plugin add cordova-plugin-ignore-lint-translation --save

有效的结果是添加了一个gradle文件,该文件将禁用这些lint选项(doh!)。

答案 3 :(得分:7)

只需添加

即可更具体
lintOptions {
    disable MissingTranslation
}

答案 4 :(得分:5)

要解决此错误,您应该添加

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
}

在/platforms/android/build.gradle中的android {}部分

答案 5 :(得分:2)

@echo off
setlocal EnableDelayedExpansion

rem Import first line into "var1" variable (you did this already)
set /P "var1=" < test.txt

rem Set maximum number of columns
set maxColnum=10

rem Count the number of fields separated by semicolon;
rem the fields may include other separators and wild-cards
set "str=%var1%;"
set colnum=0
for /L %%i in (1,1,%maxColnum%) do if defined str (
   set /A colnum+=1
   set "str=!str:*;=!"
)
echo colnum = %colnum%

答案 6 :(得分:0)

无需使用cordova插件,按照here的说明使用after_platform_add钩子,然后将以下内容放入build-extras.gradle文件中:

android {
    lintOptions {
        disable 'MissingTranslation'
        disable 'ExtraTranslation'
    }
}

答案 7 :(得分:0)

如果由于MissingTranslation问题导致构建失败,并且不应该翻译字符串,则可以在translatable="false"文件中的<string>元素上添加属性/platforms/android/app/src/main/res/values/strings.xml

因此,如果strings.xml文件中的字符串是这样的:

<string name="app_name">Your App Name</string>
<string name="launcher_name">@string/app_name</string>
<string name="activity_name">@string/launcher_name</string>

编辑它们,使其看起来像这样:

<string name="app_name" translatable="false">Your App Name</string>
<string name="launcher_name" translatable="false">@string/app_name</string>
<string name="activity_name" translatable="false">@string/launcher_name</string>

此解决方案对我有用。