首页 文章

升级Cordova相机插件时出现Android构建错误

提问于
浏览
10

将cordova相机插件从2.1.1更新到2.3.1后,我遇到了构建错误 . 以下是版本详细信息

cordova版本:6.3.1,cordova-plugin-camera 2.1.1“相机” . 以下是我遵循的步骤

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

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

当我构建cordova android构建时,我得到以下错误错误:cmd:命令失败,退出代码1错误输出:注意:某些输入文件使用或覆盖已弃用的API . 注意:使用-Xlint重新编译:弃用以获取详细信息 . 注意:某些输入文件使用或覆盖已弃用的API . 注意:使用-Xlint重新编译:弃用以获取详细信息 . 警告:字符串'menu_settings'没有默认翻译 .

platforms \ android \ src \ org \ apache \ cordova \ camera \ CameraLauncher.java:32:error:找不到符号导入org.apache.cordova.BuildHelper;符号:类BuildHelper位置:包org.apache.cordova平台\ android \ src \ org \ apache \ cordova \ camera \ CameraLauncher.java:140:错误:找不到符号this.applicationId =(String)BuildHelper.getBuildConfigValue(cordova . getActivity(),“APPLICATION_ID”); ^符号:变量BuildHelper位置:类CameraLauncher注意:某些输入文件使用或覆盖已弃用的API . 注意:使用-Xlint重新编译:弃用以获取详细信息 . 注意:某些输入文件使用未经检查或不安全的操作 . 注意:使用-Xlint重新编译:取消选中以获取详细信息 . 2个错误

FAILURE:构建因异常而失败 .

  • 出了什么问题:任务执行失败':compileDebugJavaWithJavac' .

编译失败;请参阅编译器错误输出以获取详细信

  • 尝试:使用--stacktrace选项运行以获取堆栈跟踪 . 使用--info或 - debug选项运行以获取更多日志输出 .

6 回答

  • 0

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

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

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

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

    cordova plugin remove cordova-plugin-compat --force
    cordova plugin add cordova-plugin-compat
    
  • 3

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

  • 20

    我也从相机插件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();
    

    enter image description here

  • 2

    我得到了完全相同的错误 . 这实际上是由旧版本的cordova-plugin-compat插件(1.0)引起的,通过升级到1.1版(最新版),它可以正常工作 .

    这是我做的,

    • 删除所有平台

    cordova平台删除android

    cordova平台删除ios

    • 删除旧插件并添加新插件

    cordova插件删除cordova-plugin-compat

    cordova插件添加cordova-plugin-compat

    • 添加所有平台

    cordova平台添加android

    cordova平台添加ios

    • 重新编译,一切正常!
  • 34

    我已经对下面的方法进行了更改 .

    // 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;
        }
    

相关问题