Skip to content

':app:mapDebugSourceSetPaths' エラーの解決方法

Androidアプリ開発において、Googleサービス(Firebaseなど)を統合する際に遭遇する一般的な問題の1つが Execution failed for task ':app:mapDebugSourceSetPaths' エラーです。この記事では、このエラーの原因と効果的な解決策について詳しく説明します。

問題の概要

このエラーは通常、Android Studioのアップデート後や新しいバージョンのGradleプラグインを導入した際に発生します。主なエラーメッセージは以下の通りです:

Error while evaluating property 'extraGeneratedResDir' of task ':app:mapDebugSourceSetPaths'
Failed to calculate the value of task ':app:mapDebugSourceSetPaths' property 'extraGeneratedResDir'
Querying the mapped value of provider(java.util.Set) before task ':app:processDebugGoogleServices' has completed is not supported

この問題は、Google ServicesプラグインとAndroid Gradle Plugin(AGP)のバージョン間の互換性の問題によって引き起こされます。

根本原因

互換性の問題

このエラーの主な原因は、使用している com.google.gms:google-services プラグインのバージョンが、現在のAndroid Gradle Plugin(AGP)のバージョンと互換性がないことです。

解決策

方法1:Google Servicesプラグインのバージョンアップ(推奨)

最も効果的で一般的な解決策は、Google Servicesプラグインを最新の互換バージョンに更新することです。

android/build.gradle ファイルを開き、依存関係を更新します:

groovy
buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:4.4.1' // 最新バージョンに更新
        // 他の依存関係...
    }
}

最新バージョンの確認

常に Google Servicesプラグインの公式ドキュメント で最新バージョンを確認してください。

方法2:Android Gradle PluginとGoogle Servicesの互換バージョンを設定

以下の表は、Android Studioのバージョンごとの推奨設定です:

Android Studio バージョンAGP バージョンGoogle Services バージョン
Iguana (2023.2.1)8.3.24.4.1
Giraffe (2022.3.1)8.1.34.4.0
Electric Eel7.4.04.3.15
Dolphin7.3.14.3.14

プロジェクトレベルの build.gradle を以下のように設定します:

groovy
plugins {
    id 'com.android.application' version '8.3.2' apply false
    id 'com.android.library' version '8.3.2' apply false
    id 'com.google.gms.google-services' version '4.4.1' apply false
}

dependencies {
    classpath 'com.google.gms:google-services:4.4.1'
}

アプリレベルの build.gradle には以下を追加:

groovy
plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
    // 他のプラグイン...
}

方法3:Flutterプロジェクトの場合

Flutterプロジェクトでこの問題が発生した場合、android/build.gradle ファイルを以下のように更新します:

groovy
buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.0'
        classpath 'com.google.gms:google-services:4.3.14' // こちらを更新
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

方法4:Cordovaプロジェクトの場合

Cordovaを使用している場合は、config.xml に以下の設定を追加します:

xml
<preference name="GradlePluginGoogleServicesEnabled" value="true" />
<preference name="GradlePluginGoogleServicesVersion" value="4.3.15" />

追加のトラブルシューティング手順

  1. プロジェクトのクリーンとリビルド

    bash
    flutter clean  # Flutterプロジェクトの場合
    ./gradlew clean  # ネイティブAndroidプロジェクトの場合
  2. 依存関係の更新

    bash
    flutter pub get  # Flutterプロジェクトの場合
  3. キャッシュのクリア

    • Android Studioで:File > Invalidate Caches / Restart

重要

Google Servicesプラグインを完全に削除することは推奨されません。これによりFirebase機能が使用できなくなり、別のエラーが発生します。

予防策

  1. 定期的にAndroid Studioとプラグインを更新する
  2. 新しいバージョンのAndroid Studioをインストールする前に、互換性マトリックスを確認する
  3. バージョン管理システムを使用して変更点を追跡する

まとめ

:app:mapDebugSourceSetPaths エラーは主にバージョンの不一致によって発生します。Google Servicesプラグインを適切なバージョンに更新することで、ほとんどの場合この問題は解決します。常に互換性のあるバージョンの組み合わせを使用し、定期的なアップデートを行うことで、この種の問題を予防できます。

参考資料

この記事が問題解決の手助けとなれば幸いです。それでも問題が解決しない場合は、プロジェクトの設定を詳細に確認するか、追加の支援を求めてください。