本日はMetaQuest3の小ネタ枠です。
ライブラリで取り込んだAndroidManifestが衝突した場合の対処についてです。
発生事象
Quest3向けのUnityプロジェクトに幾つかのライブラリを取り込んだ際、ビルド時にAndroidManifestの衝突エラーが発生しました。
![](https://cdn-ak.f.st-hatena.com/images/fotolife/b/bluebirdofoz/20240723/20240723233958.jpg)
[:InteractionSdk:] C:\Users\User\.gradle\caches\transforms-3\6c06\transformed\InteractionSdk\AndroidManifest.xml Warning:
Package name 'com.oculus.Integration' used in: :InteractionSdk:, :SDKTelemetry:, :OVRPlugin:.
See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.
84 actionable tasks: 6 executed, 78 up-to-date
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
C:\Work\UnityProject\Library\Bee\Android\Prj\IL2CPP\Gradle\launcher\src\main\AndroidManifest.xml:49:9-36 Error:
Attribute application@allowBackup value=(false) from [:unityLibrary] AndroidManifest.xml:49:9-36
is also present at [:sqlite-android:] AndroidManifest.xml:12:9-35 value=(true).
Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at AndroidManifest.xml:3:3-83 to override.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':launcher:processReleaseMainManifest'.
> 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
BUILD FAILED in 12s
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
CommandInvokationFailure: Gradle build failed.
C:\Program Files\Unity\2022.3.16f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\bin\java.exe -classpath "C:\Program Files\Unity\2022.3.16f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-7.2.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"
原因
元のプロジェクトと取り込んだライブラリの両方にAndroidManifestが含まれており、application@allowBackupの設定がそれぞれtrueとfalseに設定されていたため競合が発生したことが原因でした。
対処方法
元のプロジェクトのAndroidManifest.xmlにtools:replace="android:allowBackupの設定を追加することで回避できます。
この場合、元のプロジェクトのAndroidManifest.xmlに書かれたapplication@allowBackupの設定が優先されるようになります。
・AndroidManifest.xml
xml version="1.0" encoding="utf-8" standalone="no"
<manifest xmlnsandroid="http://schemas.android.com/apk/res/android" xmlnstools="http://schemas.android.com/tools" androidinstallLocation="auto">
<application androidlabel="@string/app_name" androidicon="@mipmap/app_icon" androidallowBackup="false" toolsreplace="android:allowBackup">
(以下略)