【问题标题】:Android build error upon upgrading Cordova's camera plugin升级 Cordova 的相机插件时 Android 构建错误
【发布时间】:2017-05-17 23:50:18
【问题描述】:

将 cordova 相机插件从 2.1.1 更新到 2.3.1 后,我遇到了构建错误。

版本详情:

cordova version: 6.3.1,
cordova-plugin-camera 2.1.1 "Camera"

我在做什么:

cordova plugin remove cordova-plugin-camera --save
cordova plugin add cordova-plugin-camera --save

我看到 config.xml 文件已更新为:

<plugin name="cordova-plugin-camera" spec="~2.3.1" />

当我构建 cordova android build 时出现以下错误:

Error: cmd: Command failed with exit code 1 Error output:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
warning: string 'menu_settings' has no default translation.

platforms\android\src\org\apache\cordova\camera\CameraLauncher.java:32:
    error: cannot find symbol

import org.apache.cordova.BuildHelper;
symbol:   class BuildHelper
location: package org.apache.cordova
platforms\android\src\org\apache\cordova\camera\CameraLauncher.java:140:
    error: cannot find symbol
this.applicationId = (String)
BuildHelper.getBuildConfigValue(cordova.getActivity(), "APPLICATION_ID");
                                  ^
symbol:   variable BuildHelper
location: class CameraLauncher
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

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

【问题讨论】:

  • 在构建它之前,您是否尝试过删除并重新添加 Android 平台一次?希望这能解决问题

标签: android cordova ionic-framework cordova-plugins


【解决方案1】:

您应该将 cordova-plugin-camera 升级到 1.1 版

【讨论】:

  • 我正在尝试获取最新版本的插件不想降级版本
【解决方案2】:

我今天遇到了同样的问题。我通过重新安装插件cordova-plugin-compat 修复了它。 由于依赖关系,我使用了 --force。

cordova plugin remove cordova-plugin-compat --force
cordova plugin add cordova-plugin-compat

【讨论】:

  • 能否提供您正在使用的插件版本。
  • 让所有插件和SKD工具保持最新是一个好习惯
  • 我安装了相机插件 v2.4.0,然后我的构建失败了。可悲的是,上述过程对我来说失败了(当我执行上述操作时,之后我被提示安装科尔多瓦更新)。当我删除相机 2.4.0 插件时,我的构建将再次工作。我会四处寻找是否有其他建议/修复。
【解决方案3】:

我得到了完全相同的错误。这其实是cordova-plugin-compat插件(1.0)的老版本造成的,升级到1.1(最新)就可以了。

这就是我所做的,

  1. 删除所有平台

    cordova 平台移除 android

    cordova 平台移除 ios

  2. 删除旧插件并添加新插件

    cordova 插件删除 cordova-plugin-compat

    cordova 插件添加cordova-plugin-compat

  3. 重新添加所有平台

    cordova平台添加android

    cordova平台添加ios

  4. 重新编译,一切正常!

【讨论】:

    【解决方案4】:

    我们通过强制安装 1.1.0 版解决了这个问题。

    这是我们从 CLI 运行的命令:

    cordova plugin remove cordova-plugin-compat --force
    cordova plugin add cordova-plugin-compat@1.1.0
    

    【讨论】:

    • 这个也对我有用。但我正在使用 Visual Studio 2015 Cordova 工具。我不得不经历艰难的过程来删除和添加这些插件。我在我的博客上写了一篇关于此的博客文章。请点击以下链接。 guntucomputerhacks.blogspot.com.au/2017/04/…
    • 如果您使用“Visual Studio Tools for Apache Cordova”,您可能需要在“包管理器控制台”中运行上述命令,并且如果您收到“当前工作目录不是 Cordova”的错误消息-based project”,那么您只需要使用 DOS 命令更改当前工作目录。在我的例子中,我运行 DIR 来确定哪个是我当前的工作目录,然后我运行 CD App 来移动到基于 Cordova 的项目目录。在此之后,此答案中列出的解决方案运行良好,没有错误。
    • 为我工作,谢谢!
    • 也为我工作。我已经安装了 1.2.0 版本的 compat 插件,它似乎给出了同样的错误。然后我卸载并安装了 1.1.0 并且错误消失了。谢谢。
    【解决方案5】:

    我已对以下方法进行了更改。

    // intiatiate you action accordingly
    if (action.equals("takePicture")) {
                this.srcType = CAMERA;
                this.destType = FILE_URI;
                this.saveToPhotoAlbum = false;
                this.targetHeight = 0;
                this.targetWidth = 0;
                this.encodingType = JPEG;
                this.mediaType = PICTURE;
                this.mQuality = 50;
    
                //
                this.destType = args.getInt(1);
                this.srcType = args.getInt(2);
                this.mQuality = args.getInt(0);
                this.targetWidth = args.getInt(3);
                this.targetHeight = args.getInt(4);
                this.encodingType = args.getInt(5);
                this.mediaType = args.getInt(6);
                this.allowEdit = args.getBoolean(7);
                this.correctOrientation = args.getBoolean(8);
                this.saveToPhotoAlbum = args.getBoolean(9);
    
                // If the user specifies a 0 or smaller width/height
                // make it -1 so later comparisons succeed
                if (this.targetWidth < 1) {
                    this.targetWidth = -1;
                }
                if (this.targetHeight < 1) {
                    this.targetHeight = -1;
                }
    
                  if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 &&
                        !this.correctOrientation && this.encodingType == PNG && this.srcType == CAMERA) {
                    this.encodingType = JPEG;
                }
    
                try {
                    if (this.srcType == CAMERA) {
                        this.callTakePicture(destType, encodingType);
                    }
                    else if ((this.srcType == PHOTOLIBRARY) || (this.srcType == SAVEDPHOTOALBUM)) {
                        // FIXME: Stop always requesting the permission
                        if(!PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
                            PermissionHelper.requestPermission(this, SAVE_TO_ALBUM_SEC, Manifest.permission.READ_EXTERNAL_STORAGE);
                        } else {
                            this.getImage(this.srcType, destType, encodingType);
                        }
                    }
                }
                catch (IllegalArgumentException e)
                {
                    callbackContext.error("Illegal Argument Exception");
                    PluginResult r = new PluginResult(PluginResult.Status.ERROR);
                    callbackContext.sendPluginResult(r);
                    return true;
                }
    
                PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
                r.setKeepCallback(true);
                callbackContext.sendPluginResult(r);
    
                return true;
            }
            return false;
        }
    

    【讨论】:

      【解决方案6】:

      我也收到了来自相机插件 2.3.1 的错误。这是因为依赖于 cordova-plugin-compat 来获取应用程序 ID。删除 cordova-plugin-compat 并安装 1.1.0,对我不起作用。

      要解决此问题,请从“src/android/CameraLauncher.java”中删除此代码:

      140      -     this.applicationId = (String) BuildHelper.getBuildConfigValue(cordova.getActivity(), "APPLICATION_ID");
      141      -     this.applicationId = preferences.getString("applicationId", this.applicationId);
      

      并添加:

      140      +     this.applicationId = cordova.getActivity().getPackageName();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-12-17
        • 1970-01-01
        • 1970-01-01
        • 2021-12-19
        • 1970-01-01
        • 2019-08-09
        • 2014-05-17
        • 2015-11-12
        相关资源
        最近更新 更多