環境
- Android Studio: Arctic Fox 2021.3.1
- gradle 7.0.2
現象
プロジェクトのビルドや実行において、以下のようなエラーがでて失敗する。
Zip file '...\app\build\outputs\apk\debug\app-debug.apk' already contains entry 'AndroidManifest.xml', cannot overwrite
原因
- 依存ライブラリの中にAndroidManifest.xmlが含まれている場合、そのAndroidManifest.xmlが先にAPKにコピーされる
- その後、本プロジェクトのAndroidManifest.xmlをコピーしようとするが、既に存在するためエラーとなる
- [参考] Android Gradle プラグイン 7系で使用されているzipflingerというライブラリで上書きチェックが厳密にされるようになったため、問題が顕在化した模様
- https://android.googlesource.com/platform/tools/base/+/refs/heads/mirror-goog-studio-master-dev/zipflinger/src/com/android/zipflinger/ZipArchive.java#337
解消方法
-
build.gradle
の中から問題のある(AndroidManifest.xmlを含む)依存ライブラリを特定 - 依存の記載を削除(場合によって、代替ライブラリ等を検討)