0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Cordova】"duplicated with element declared at AndroidManifest.xml"の対処方法

Posted at

事象

CordovaプロジェクトをAndroid用にビルドしようとしたところ、以下のようなエラーに遭遇。

$ cordova build android
...
> Task :app:processDebugMainManifest FAILED
<my-app-dir>/platforms/android/app/src/main/AndroidManifest.xml:17:5-90 Error:
        Element uses-permission#android.permission.CAMERA at AndroidManifest.xml:17:5-90 duplicated with element declared at AndroidManifest.xml:16:5-65
<my-app-dir>/platforms/android/app/src/main/AndroidManifest.xml Error:
        Validation failed, exiting

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed with multiple errors, see logs

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org`
...

上記エラー文で大事なのはこの部分

Element uses-permission#android.permission.CAMERA at AndroidManifest.xml:17:5-90 duplicated with element declared at AndroidManifest.xml:16:5-65

つまりは "AndroidManifest.xml 内で uses-permission#android.permission.CAMERA の要素が重複してますよ" ってこと。

原因

調べてみたところ、自分のプロジェクトで使用する以下2つのプラグイン内でそれぞれカメラアクセスを求めており、その記述方法が微妙に異なっていたため、両方が AndroidManifest.xml に書き込まれてしまいエラーの原因になっていた。

  • cordova-plugin-qrscanner
plugins/cordova-plugin-qrscanner/plugin.xml
<uses-permission android:name="android.permission.CAMERA" android:required="false" />
  • cordova-plugin-flashlight
plugins/cordova-plugin-flashlight/plugin.xml
<uses-permission android:name="android.permission.CAMERA" />

このくらいCordova側でうまく調整してほしいが無理みたい。

解決方法

まずは各プラグインのplugin.xmlの記述方法を統一。今回は cordova-plugin-qrscanner を修正。

plugins/cordova-plugin-qrscanner/plugin.xml
<!-- <uses-permission android:name="android.permission.CAMERA" android:required="false" /> -->
<uses-permission android:name="android.permission.CAMERA" />

次に変更を反映させるためにAndroidプラットフォームを一度削除してから再追加。

$ cordova platforms remove android
$ cordova platforms add android

これで改めてビルドすればうまくいくはず。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?