AGP 8.3.0マニフェストマージエラーの解決方法
問題説明
Android Gradle Plugin (AGP) バージョン8.3.0へのアップグレード時に、次のマニフェストマージエラーが発生します:
Attribute property#android.adservices.AD_SERVICES_CONFIG@resource value=(@xml/ga_ad_services_config) from [com.google.android.gms:play-services-measurement-api:21.5.1] AndroidManifest.xml:32:13-58
is also present at [com.google.android.gms:play-services-ads-lite:22.6.0] AndroidManifest.xml:92:13-59 value=(@xml/gma_ad_services_config).
Suggestion: add 'tools:replace="android:resource"' to <property> element at AndroidManifest.xml to override.
このエラーはGoogle広告関連ライブラリ(play-services-ads)と計測ライブラリ(play-services-measurement-api)のマニフェスト属性が競合することで発生します。エラーメッセージの示唆通り、AndroidManifest.xml
に特定のプロパティを追加することで解決可能です。
注意
- このエラーはプロジェクト自身のマニフェストファイルではなく、依存ライブラリ内部のマニフェストの競合が原因です
- AGP 8.2.2以前では発生せず、AGP 8.3.0の挙動変更によって表面化しました
解決方法
方法1: マニフェストへのプロパティ追加 (推奨)
app/src/main/AndroidManifest.xml
を開く<application>
タグ内に次のプロパティを追加:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"> <!-- tools名前空間が必要 -->
<application>
<!-- 追加するコード -->
<property
android:name="android.adservices.AD_SERVICES_CONFIG"
android:resource="@xml/gma_ad_services_config"
tools:replace="android:resource" />
<!-- 他のコンポーネント -->
</application>
</manifest>
重要
<manifest>
タグにxmlns:tools="http://schemas.android.com/tools"
の宣言が必須です。不足していると別のパースエラーが発生します。
方法2: 広告ライブラリのバージョン調整
ライブラリの互換性問題を解消するため、Google広告ライブラリを特定バージョンに固定:
// app/build.gradle
dependencies {
implementation "com.google.android.gms:play-services-ads:22.6.0" // 明示的にバージョン指定
}
WARNING
Firebase BOMを使用している場合でも、広告ライブラリは個別にバージョン指定が必要です:
implementation(platform("com.google.firebase:firebase-bom:32.7.3"))
implementation("com.google.firebase:firebase-analytics")
implementation("com.google.android.gms:play-services-ads:22.6.0") // 明示的指定
追加設定 (オプション)
Google広告ライブラリを使用する場合、アプリ起動時に初期化を推奨:
// Applicationクラスで初期化
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
MobileAds.initialize(this); // 広告ライブラリの初期化
}
}
エラーの技術的背景
競合している属性はAndroidの広告サービス設定(AdServices)に関連します。二つのライブラリが異なる設定ファイルを参照:
play-services-measurement-api
:@xml/ga_ad_services_config
play-services-ads
:@xml/gma_ad_services_config
AGP 8.3.0はマニフェストマージ時の競合検出を強化したため、以前は無視されていたこの不一致がエラーとして報告されるようになりました。
最新状況 (2025年3月時点)
AGP 8.8.2 + play-services-ads:24.0.0以降では、この修正は不要になりました。最新バージョンへのアップグレードが可能な場合、根本的な解決となります。
最終的なマニフェスト例
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.app">
<application
android:name=".MyApp"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
<!-- 競合解決プロパティ -->
<property
android:name="android.adservices.AD_SERVICES_CONFIG"
android:resource="@xml/gma_ad_services_config"
tools:replace="android:resource" />
<!-- 他のコンポーネント -->
<activity android:name=".MainActivity">
<!-- ... -->
</activity>
</application>
</manifest>