google / play-services-plugins

Plugins to help with using Google Play services SDK.
https://developers.google.com/android/guides/overview
Apache License 2.0
471 stars 138 forks source link

feature request: Enhance Search Locations for GoogleServicesPluginConfig #303

Open baksha97 opened 1 month ago

baksha97 commented 1 month ago

When using multiple layers of product flavors, the default search locations for the JSONs are unable to find the service JSON; even if AGP recognizes these directories and automatically adds them to the sources. This disconnect between behaviors forces engineers to go against project resource conventions and create directories to satisfy this plugins expectations.

Here's a minimal example:

// app/build.gradle.kts
flavorDimensions += listOf(
  "market",
  "environment"
)

productFlavors {
  create("amazon") {
      dimension = "market"
  }
  create("google") {
      dimension = "market"
  }
  create("npd") {
      dimension = "environment"
  }
  create("prod") {
      dimension = "environment"
  }
}

We want to store the NPD json in project/app/src/npd (this is a recognized source location for the variant in Android Studio, and probably should be in the default search locations).

Unfortunately, this results in an error:

* What went wrong:
Execution failed for task ':app:processAmazonNpdDebugGoogleServices'.
> File google-services.json is missing. The Google Services Plugin cannot function without it. 
   Searched Location: 

project/app/src/amazon/npd/debug/google-services.json
project/app/src/amazonNpd/debug/google-services.json
project/app/src/debug/amazonNpd/google-services.json
project/app/src/amazon/debug/google-services.json
project/app/src/amazon/npd/google-services.json
project/app/src/amazon/npdDebug/google-services.json
project/app/src/amazonNpd/google-services.json
project/app/src/debug/google-services.json
project/app/src/amazonNpdDebug/google-services.json
project/app/src/amazon/google-services.json
project/app/src/amazonDebug/google-services.json
project/app/google-services.json

Suggested Solutions

  1. Modify the default search locations to include a root directory for all flavors, regardless of priority.
  2. Allow clients using the plugin to specify the location of the services JSON in the plugin's GoogleServicesPluginConfig. e.g.
    create("npd") {
        dimension = "environment"
        googleServices {
           servicesJsonFile = File("src/npd/google-services.json")
        }
    }