Cordova构建错误:相机插件缺少android.support.v4库依赖项

时间:2022-03-03 15:17:48

Unable to build an IBM MobileFirst 7.1 based Cordova Android App. Recently upgraded the mobilefirst cli version to 7.1.0.00.20180302-0537

无法构建基于IBM MobileFirst 7.1的Cordova Android应用程序。最近将mobilefirst cli版本升级到7.1.0.00.20180302-0537

Upon adding the camera plugin(org.apache.cordova.camera), android build fails with the following error mention in log below. Looking at the error it looks like the plugin now required the support library but doesn't have it indicated as a dependency. Not quite sure of what needs to be done to resolve this.

添加相机插件(org.apache.cordova.camera)后,android构建失败,并在下面的日志中提到以下错误。看看错误,看起来插件现在需要支持库,但没有将其指示为依赖项。不太确定要解决这个问题需要做些什么。

-compile:
[javac] Compiling 47 source files to /Users/dev/MFPApp/platforms/android/ant-build/classes
[javac] warning: [options] source value 1.5 is obsolete and will be removed in a future release
[javac] warning: [options] target value 1.5 is obsolete and will be removed in a future release
[javac] warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
[javac] /Users/dev/MFPApp/platforms/android/src/org/apache/cordova/camera/CameraLauncher.java:56: error: package android.support.v4.content does not exist
[javac] import android.support.v4.content.FileProvider;
[javac]                                  ^
[javac] /Users/dev/MFPApp/platforms/android/src/org/apache/cordova/camera/CordovaUri.java:25: error: package android.support.v4.content does not exist
[javac] import android.support.v4.content.FileProvider;
[javac]                                  ^
[javac] /Users/dev/MFPApp/platforms/android/src/org/apache/cordova/camera/CameraLauncher.java:278: error: cannot find symbol
[javac]         this.imageUri = new CordovaUri(FileProvider.getUriForFile(cordova.getActivity(),
[javac]                                        ^
[javac]   symbol:   variable FileProvider
[javac]   location: class CameraLauncher
[javac] /Users/dev/MFPApp/platforms/android/src/org/apache/cordova/camera/CameraLauncher.java:732: error: cannot find symbol
[javac]                         Uri tmpFile = FileProvider.getUriForFile(cordova.getActivity(),
[javac]                                       ^
[javac]   symbol:   variable FileProvider
[javac]   location: class CameraLauncher
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 4 errors
[javac] 3 warnings

Environment Information

环境信息

OS: darwin x64
Release: 17.7.0
System Memory: 5112 MB free out of 16384 MB
Node: v0.10.36
MobileFirst CLI: 7.1.0.00.20180302-0537
Cordova:6.3.0

Plugin Information

插件信息

cordova-plugin-mfp 7.1.0 "IBM MobileFirst Platform Foundation"
cordova-plugin-mfp-jsonstore 7.1.0 "IBM MobileFirst Platform Foundation - JSONStore"
cordova-plugin-mfp-push 7.1.0 "IBM MobileFirst Platform Foundation - Push Notifications"
org.apache.cordova.battery-status 0.2.12 "Battery"
org.apache.cordova.camera 0.3.4 "Camera"
org.apache.cordova.console 0.2.12 "Console"
org.apache.cordova.device 0.2.13 "Device"
org.apache.cordova.device-motion 0.2.11 "Device Motion"
org.apache.cordova.dialogs 0.2.11 "Notification"
org.apache.cordova.geolocation 0.3.11 "Geolocation"
org.apache.cordova.globalization 0.3.3 "Globalization"
org.apache.cordova.inappbrowser 0.5.4 "InAppBrowser"
org.apache.cordova.network-information 0.2.14 "Network Information"
org.apache.cordova.splashscreen 0.3.5 "Splashscreen"
org.apache.cordova.statusbar 0.1.9 "StatusBar"
org.apache.cordova.vibration 0.3.12 "Vibration"

2 个解决方案

#1


6  

You may be facing a known issue that starts from Android N. This has been fixed in iFix 7.1.0.0-MFPF-IF201802160539

您可能面临从Android N开始的已知问题。这在iFix 7.1.0.0-MFPF-IF201802160539中已得到修复

Alternatively, try the steps mentioned in this link:

或者,尝试此链接中提到的步骤:

Preparing a project that uses the Cordova camera plug-in with the Android platform

准备一个使用Android平台的Cordova相机插件的项目

The steps are:

步骤是:

  • Add the android-support-v4.jar file to your project.

    将android-support-v4.jar文件添加到您的项目中。

    • In a file explorer, browse to your Android SDK directory, which is where your Android SDK Manager downloads the updates.

      在文件资源管理器中,浏览到您的Android SDK目录,Android SDK管理器目录是您下载更新的位置。

    • If it is not already installed, install the Android Support Repository in your Android environment.

      如果尚未安装,请在Android环境中安装Android支持存储库。

    • Browse to extras/android/m2repository/com/android/support/support-core-utils.
    • 浏览到extras / android / m2repository / com / android / support / support-core-utils。
    • Select version 24.2.0, or higher, of the support-core-utils repository.
    • 选择support-core-utils存储库的版本24.2.0或更高版本。
    • Extract the classes.jar file from the support-core-utils-24.2.0.aar package.If you do not have a file archive tool, you can change the .aar file extension to .zip to extract the classes.jar file.

      从support-core-utils-24.2.0.aar包中提取classes.jar文件。如果没有文件存档工具,可以将.aar文件扩展名更改为.zip以提取classes.jar文件。

    • Add the classes.jar file to the libs directory of your Android platform.

      将classes.jar文件添加到Android平台的libs目录中。

  • Update the AndroidManifest.xml file.

    更新AndroidManifest.xml文件。

    • Open the AndroidManifest.xml file that is in the platforms/android folder.

      打开platforms / android文件夹中的AndroidManifest.xml文件。

    • Add the following lines inside of the ending tag:

      在结束标记内添加以下行:

  <provider android:authorities="{PACKAGE_ID}.provider" android:exported="false" 
   android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider"> 
   <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" /> 
  </provider>

Where {PACKAGE_ID} is replaced with the Android Package ID of your project.

其中{PACKAGE_ID}替换为项目的Android Package ID。

  • Save the AndroidManifest.xml file.
  • 保存AndroidManifest.xml文件。

Update the config.xml file.

更新config.xml文件。

  • Open the config.xml file that is in your project folder.
  • 打开项目文件夹中的config.xml文件。
  • Inside the tag, add the following tag:

    在标记内,添加以下标记:

     <preference name="applicationId" value="{PACKAGE_ID}"/>
    

Where {PACKAGE_ID} is replaced by the Android Package ID of your project.

其中{PACKAGE_ID}被项目的Android Package ID替换。

  • Save the config.xml file.
  • 保存config.xml文件。

#2


2  

This issue is fixed in iFix level 7.1.0.0-MFPF-IF201802160539

此问题已在iFix级别7.1.0.0-MFPF-IF201802160539中修复

Follow this link if you see any error related android.support.v4 library dependency : Preparing a project that uses the Cordova camera plug-in with the Android platform

如果您看到任何与android.support.v4库相关的错误,请点击此链接:准备一个使用Android平台的Cordova相机插件的项目

I have uploaded sample app here, which may help you: sample app

我在这里上传了示例应用,这可能对您有所帮助:示例应用

#1


6  

You may be facing a known issue that starts from Android N. This has been fixed in iFix 7.1.0.0-MFPF-IF201802160539

您可能面临从Android N开始的已知问题。这在iFix 7.1.0.0-MFPF-IF201802160539中已得到修复

Alternatively, try the steps mentioned in this link:

或者,尝试此链接中提到的步骤:

Preparing a project that uses the Cordova camera plug-in with the Android platform

准备一个使用Android平台的Cordova相机插件的项目

The steps are:

步骤是:

  • Add the android-support-v4.jar file to your project.

    将android-support-v4.jar文件添加到您的项目中。

    • In a file explorer, browse to your Android SDK directory, which is where your Android SDK Manager downloads the updates.

      在文件资源管理器中,浏览到您的Android SDK目录,Android SDK管理器目录是您下载更新的位置。

    • If it is not already installed, install the Android Support Repository in your Android environment.

      如果尚未安装,请在Android环境中安装Android支持存储库。

    • Browse to extras/android/m2repository/com/android/support/support-core-utils.
    • 浏览到extras / android / m2repository / com / android / support / support-core-utils。
    • Select version 24.2.0, or higher, of the support-core-utils repository.
    • 选择support-core-utils存储库的版本24.2.0或更高版本。
    • Extract the classes.jar file from the support-core-utils-24.2.0.aar package.If you do not have a file archive tool, you can change the .aar file extension to .zip to extract the classes.jar file.

      从support-core-utils-24.2.0.aar包中提取classes.jar文件。如果没有文件存档工具,可以将.aar文件扩展名更改为.zip以提取classes.jar文件。

    • Add the classes.jar file to the libs directory of your Android platform.

      将classes.jar文件添加到Android平台的libs目录中。

  • Update the AndroidManifest.xml file.

    更新AndroidManifest.xml文件。

    • Open the AndroidManifest.xml file that is in the platforms/android folder.

      打开platforms / android文件夹中的AndroidManifest.xml文件。

    • Add the following lines inside of the ending tag:

      在结束标记内添加以下行:

  <provider android:authorities="{PACKAGE_ID}.provider" android:exported="false" 
   android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider"> 
   <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" /> 
  </provider>

Where {PACKAGE_ID} is replaced with the Android Package ID of your project.

其中{PACKAGE_ID}替换为项目的Android Package ID。

  • Save the AndroidManifest.xml file.
  • 保存AndroidManifest.xml文件。

Update the config.xml file.

更新config.xml文件。

  • Open the config.xml file that is in your project folder.
  • 打开项目文件夹中的config.xml文件。
  • Inside the tag, add the following tag:

    在标记内,添加以下标记:

     <preference name="applicationId" value="{PACKAGE_ID}"/>
    

Where {PACKAGE_ID} is replaced by the Android Package ID of your project.

其中{PACKAGE_ID}被项目的Android Package ID替换。

  • Save the config.xml file.
  • 保存config.xml文件。

#2


2  

This issue is fixed in iFix level 7.1.0.0-MFPF-IF201802160539

此问题已在iFix级别7.1.0.0-MFPF-IF201802160539中修复

Follow this link if you see any error related android.support.v4 library dependency : Preparing a project that uses the Cordova camera plug-in with the Android platform

如果您看到任何与android.support.v4库相关的错误,请点击此链接:准备一个使用Android平台的Cordova相机插件的项目

I have uploaded sample app here, which may help you: sample app

我在这里上传了示例应用,这可能对您有所帮助:示例应用