在将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.
我们通过强制安装版本1.1.0解决了此问题。
这是我们从CLI运行的命令:
cordova plugin remove cordova-plugin-compat --force
cordova plugin add [email protected]
我今天遇到了同样的问题。我通过重新安装插件cordova-plugin-compat
来解决此问题。由于依赖,我使用--force。
cordova plugin remove cordova-plugin-compat --force
cordova plugin add cordova-plugin-compat
您应该将cordova-plugin-camera升级到1.1版
我也在相机插件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();
我遇到了完全相同的错误。这实际上是由cordova-plugin-compat插件的旧版本(1.0)引起的,通过升级到1.1版(最新),它可以工作。
这是我所做的,
删除所有平台
cordova平台删除android
cordova平台删除ios
删除旧插件并添加新插件
cordova插件删除cordova-plugin-compat
cordova插件添加cordova-plugin-compat
重新添加所有平台
cordova平台添加android
cordova平台添加ios
重新编译,一切正常!
我对以下方法进行了更改。
// 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;
}