Cordova Android duplicated uses-feature from two p

2019-01-26 06:11发布

问题:

I am using two different plugins into cordova, which both have the same uses-feature, one with android:required="false" and one without.

This results in an error upon build:

processDebugManifest
/path/to/project/platforms/android/AndroidManifest.xml:31:5 Error:
    Element uses-feature#android.hardware.camera at AndroidManifest.xml:31:5 duplicated with element declared at AndroidManifest.xml:27:5
/path/to/project/platforms/android/AndroidManifest.xml:32:5 Error:
    Element uses-feature#android.hardware.camera.autofocus at AndroidManifest.xml:32:5 duplicated with element declared at AndroidManifest.xml:28:5
/path/to/project/platforms/android/AndroidManifest.xml:0:0 Error:
    Validation failed, exiting
:processDebugManifest FAILED
.....
ERROR building one of the platforms: Error: /path/to/project/platforms/android/cordova/build: Command failed with exit code 1
You may not have the required environment or OS to build this project

The compiled manifest has the following when built:

...
    <uses-feature android:name="android.hardware.camera" android:required="false" />
    <uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
    <uses-feature android:name="android.hardware.camera.flash" android:required="false" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
...

Is there anything I can do to fix this?


cordova version 5.4.1

回答1:

1.Open plugins/[your plugin name]/plugin.xml

2.remove this line:

`<uses-feature android:name="android.hardware.camera" android:required="false" />`

3. rebuild your project



回答2:

  1. In addition to removing duplicate lines in plugins.xml file, go to [your project]/platforms/android/android.json and remove duplicate lines in the file as well.

  2. Reopen your command terminal before compiling the project again.



回答3:

I had the sane issue with cordova-plugin-camera and phonegap-plugin-barcodescanner. My fix:

ionic cordova platform rm android
ionic cordova platform rm ios    
ionic cordova plugin rm phonegap-plugin-barcodescanner
rm -r plugins
rm -r node_modules
rm package-lock.json

Next remove the phonegap-plugin-barcodescanner of the package.json. Run:

npm install
ionic cordova platform add android

Next do a new build:

ionic cordova run android

Next add the plugin again:

ionic cordova plugin add phonegap-plugin-barcodescanner


回答4:

The following steps helped me solve this problem:

  1. Remove duplicate elements from your config.xml

  2. Remove duplicate objects from platform/android/android.json file.

  3. Remove duplicate elements from platform/android/app/src/main/AndroidManifest.xml file.

  4. Close your IDE/Text Editor (Specially if you are using VS Code).

  5. Now run 'cordova build android'.



回答5:

simple cmd for your problem:

cordova clean 
cordova build


回答6:

This is how it finally worked for us in our Ionic 3 project. You should remove one of the duplicate entries from platforms/android/AndroidManifest.xml:

<manifest ...>
    ...
    <uses-feature android:name="android.hardware.camera"/>
    ...
    <uses-feature android:name="android.hardware.camera" android:required="true" />
</manifest>

And also from platforms/android/android.json:

{
  "xml": "<uses-feature android:name=\"android.hardware.camera\" />",
  "count": 1
},
...
{
  "xml": "<uses-feature android:name=\"android.hardware.camera\" android:required=\"true\" />",
  "count": 1
}

PS: We do this tweak only when adding the Android platform, not at every build.