Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
like image 433
user2934433 Avatar asked Jan 03 '17 19:01

user2934433


Video Answer


2 Answers

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]
like image 197
Cody Watkins Avatar answered Sep 20 '22 15:09

Cody Watkins


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

like image 33
Avijit Avatar answered Sep 20 '22 15:09

Avijit