使用 phonegap-plugin-barcodescanner 的 Ionic 版本构建失败

Ionic release build with phonegap-plugin-barcodescanner failed

因为我安装了插件 phonegap-plugin-barcodescanner 我无法构建 android 发布版本

ionic build android --release

可以正常开发构建而不会出现一些问题。

ionic build android

如果没有条形码扫描器插件,我在构建版本时也不会遇到一些麻烦。但是,如果我添加插件并构建版本,我会收到以下错误:

\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>
          ~~~~~~~~~~~~~~~~~~~~
    D:\Git\mobile\platforms\android\res\values-bg\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-ca\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-cs\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-da\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-de\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-el\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-es\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-eu\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-fi\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-fr\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-he\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-hi\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-hu\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-id\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-it\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-iw\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-ja\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-ko\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-nl\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-pl\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-pt\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-ru\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-sk\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-sl\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-sv\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-tr\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-zh-rCN\strings.xml:64: Also translated here
    D:\Git\mobile\platforms\android\res\values-zh-rTW\strings.xml:64: Also translated here

   Explanation for issues of type "ExtraTranslation":
   If a string appears in a specific language translation file, but there is
   no corresponding string in the default locale, then this string is probably
   unused. (It's technically possible that your application is only intended
   to run in a specific locale, but it's still a good idea to provide a
   fallback.).

   Note that these strings can lead to crashes if the string is looked up on
   any locale not providing a translation, so it's important to clean them
   up.

5 errors, 0 warnings
 FAILED

BUILD FAILED

Total time: 9.482 secs

FAILURE: Build failed with an exception.

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

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

D:\Git\mobile\platforms\android\cordova\node_modules\q\q.js:126
                    throw e;
                          ^
Error code 1 for command: cmd with args: /s /c "D:\Git\mobile\platforms\android\gradlew cdvBuildRelease -b D:\Git\mobile\platforms\android\build.gradle -Dorg.gradle.daemon=true"
ERROR building one of the platforms: Error: cmd: Command failed with exit code 1
You may not have the required environment or OS to build this project
Error: cmd: Command failed with exit code 1
    at ChildProcess.whenDone (C:\Users\ss\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\cordova\superspawn.js:139:23)
    at ChildProcess.emit (events.js:110:17)
    at maybeClose (child_process.js:1015:16)
    at Process.ChildProcess._handle.onexit (child_process.js:1087:5)

我找到了解决方案。您必须覆盖 build.gradle。只需 运行 这个命令就可以了

echo 'android { lintOptions { checkReleaseBuilds false } }' >> platforms/android/build-extras.gradle