user2934433
user2934433

Reputation: 453

Android build error upon upgrading Cordova's camera plugin

I am getting build error after updating cordova camera plugin from 2.1.1 to 2.3.1.

Version details:

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

What I'm doing:

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

I see the config.xml file has been updated to:

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

When I build cordova android build I get the following error:

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.

Upvotes: 13

Views: 12232

Answers (6)

Avijit
Avijit

Reputation: 1313

I was also getting error from camera plugin 2.3.1. It is because of the dependency on the cordova-plugin-compat to get the application id. Removing cordova-plugin-compat and installing 1.1.0, didn't work for me.

To fix this remove this code from "src/android/CameraLauncher.java":

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

and add:

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

enter image description here

Upvotes: 3

jaleel_quest
jaleel_quest

Reputation: 41

I have made changes to the method below.

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

Upvotes: 0

Cody Watkins
Cody Watkins

Reputation: 456

We solved this by forcing the install of version 1.1.0.

Here's the commands we ran from the CLI:

cordova plugin remove cordova-plugin-compat --force
cordova plugin add [email protected]

Upvotes: 34

Bob Huang
Bob Huang

Reputation: 21

I got the exact same error. This is actually caused by an old version of the cordova-plugin-compat plugin (1.0), by upgrading to version 1.1 (latest), it will work.

Here is what I did,

  1. Remove all platforms

    cordova platform remove android

    cordova platform remove ios

  2. Remove old plugin and add new

    cordova plugin remove cordova-plugin-compat

    cordova plugin add cordova-plugin-compat

  3. Add all platforms back

    cordova platform add android

    cordova platform add ios

  4. Re-compile and everything works!

Upvotes: 2

Toontoet
Toontoet

Reputation: 201

I ran into the same problem today. I got it fixed by re-installing the plugin cordova-plugin-compat. Due to the dependencies I used --force.

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

Upvotes: 20

martin mo
martin mo

Reputation: 327

You should upgrade cordova-plugin-camera to version 1.1

Upvotes: 3

Related Questions