Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions google-services-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,36 @@ Apply the plugin in your app's build.gradle.kts:

```kotlin
plugins {
id("com.google.gms.google-services") version "4.4.4"
id("com.google.gms.google-services") version "4.6.0"
}
```

Or in build.gradle:
```gradle
plugins {
id 'com.google.gms.google-services' version '4.4.4'
id 'com.google.gms.google-services' version '4.6.0'
}
```

### New in version 4.4.0

#### `google-services.json` location
### `google-services.json` location

Place the `google-services.json` file for your project in the `app/` directory.

Alternatively, you can use variant specific source-sets, for example:
`debug/google-services.json`.

#### Compatible Android plugins
### Compatible Android plugins

The `com.google.gms.google-services` plugin can be applied to projects using
`com.android.application`, `com.android.library`, or `com.android.dynamic-feature`.

The `com.google.gms.google-services` plugin can only be applied to projects with
`com.android.application` or `com.android.dynamic-feature`, as it requires an `applicationId`
to function.
The plugin selects the `client` entry in `google-services.json` whose `package_name` matches the
module:

The plugin is not compatible with plugins such as `com.android.library` that do not
contain an `applicationId`.
- For `com.android.application` and `com.android.dynamic-feature`, the variant's `applicationId`.
- For `com.android.library`, the library's `namespace`.

#### Plugin configuration
### Plugin configuration

Configure the plugin's behavior through the `googleServices` block in build.gradle.kts:

Expand All @@ -72,7 +72,7 @@ googleServices {
You can use `missingGoogleServicesStrategy` when some variants in your project
do not require Google Play Services and are missing the `google-services.json` file.

#### Android Gradle plugin compatibility
### Android Gradle plugin compatibility

The Google Services plugin requires AGP 7.3.0 or newer to work.

Expand All @@ -82,7 +82,7 @@ Add the following to your buildscript classpath, obtained from Google’s
[Maven repository](//developer.android.com/studio/build/dependencies#google-maven):

```gradle
classpath 'com.google.gms:google-services:4.4.4'
classpath 'com.google.gms:google-services:4.6.0'
```

Apply the plugin in your app's build.gradle:
Expand Down
5 changes: 4 additions & 1 deletion google-services-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
}

group = "com.google.gms"
version = "4.5.0"
version = "4.6.0"

dependencies {
compileOnly("com.android.tools.build:gradle-api:7.3.0")
Expand Down Expand Up @@ -71,6 +71,9 @@ tasks.withType<Test>().configureEach {
// See GoogleServicesPluginTest.kt -> testResGeneration
dependsOn("publishAllPublicationsToMavenRepository")
systemProperties["plugin_version"] = project.version // value used by GoogleServicesPluginTest.kt
inputs.dir("src/test/testData")
.withPropertyName("testData")
.withPathSensitivity(PathSensitivity.RELATIVE)
}

tasks.withType<Jar>().configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ package com.google.gms.googleservices

import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import com.android.build.api.variant.DynamicFeatureAndroidComponentsExtension
import com.android.build.api.variant.GeneratesApk
import com.android.build.api.variant.LibraryAndroidComponentsExtension
import com.android.build.api.variant.Variant
import com.google.android.gms.dependencies.DependencyAnalyzer
import com.google.android.gms.dependencies.DependencyInspector
import java.io.File
import java.util.*
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.provider.Provider

class GoogleServicesPlugin : Plugin<Project> {

Expand Down Expand Up @@ -56,14 +57,21 @@ class GoogleServicesPlugin : Plugin<Project> {
pluginApplied = true
project.extensions.configure(ApplicationAndroidComponentsExtension::class.java) {
it.registerSourceType(SOURCE_TYPE)
it.onVariants { variant -> handleVariant(variant, project) }
it.onVariants { variant -> handleVariant(variant, variant.applicationId, project) }
}
}
project.pluginManager.withPlugin("com.android.library") {
pluginApplied = true
project.extensions.configure(LibraryAndroidComponentsExtension::class.java) {
it.registerSourceType(SOURCE_TYPE)
it.onVariants { variant -> handleVariant(variant, variant.namespace, project) }
}
}
project.pluginManager.withPlugin("com.android.dynamic-feature") {
pluginApplied = true
project.extensions.configure(DynamicFeatureAndroidComponentsExtension::class.java) {
it.registerSourceType(SOURCE_TYPE)
it.onVariants { variant -> handleVariant(variant, project) }
it.onVariants { variant -> handleVariant(variant, variant.applicationId, project) }
}
}

Expand All @@ -73,11 +81,11 @@ class GoogleServicesPlugin : Plugin<Project> {
}
project.logger.error(
"The google-services Gradle plugin needs to be applied on a project with " +
"com.android.application or com.android.dynamic-feature.")
"com.android.application, com.android.library, or com.android.dynamic-feature.")
Comment thread
mrober marked this conversation as resolved.
}
}

private fun <T> handleVariant(variant: T, project: Project) where T : Variant, T : GeneratesApk {
private fun handleVariant(variant: Variant, packageName: Provider<String>, project: Project) {
val jsonToXmlTask =
project.tasks.register(
"process${variant.name.capitalize()}GoogleServices", GoogleServicesTask::class.java) {
Expand All @@ -90,7 +98,7 @@ class GoogleServicesPlugin : Plugin<Project> {
variant.buildType.orEmpty(),
variant.productFlavors.map { it.second },
project.projectDir))
it.applicationId.set(variant.applicationId)
it.applicationId.set(packageName)
it.gmpAppId.set(project.layout.buildDirectory.file("gmpAppId/${variant.name}.txt"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,22 @@ class GoogleServicesPluginTest {
compareResults(actualResults, expectedResults)
}

@Test
fun `res file generation for library module`() {
val projectName = "project4"

copyProjectToTemp(projectName)
val buildResult = runBuild(gradleVersion = "7.6", agpVersion = "7.4.1")

Assert.assertEquals(TaskOutcome.SUCCESS, buildResult.task(":lib:assembleDebug")?.outcome)
Assert.assertEquals(
TaskOutcome.SUCCESS, buildResult.task(":lib:processDebugGoogleServices")?.outcome)

val actualResults = tempFolder.root.resolve("lib/build/generated/res/")
val expectedResults = getExpectedResults(projectName)
compareResults(actualResults, expectedResults)
}

@Test
fun testNoFlavor() {
val output: List<String> = GoogleServicesPlugin.getJsonLocations("release", emptyList())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="default_web_client_id" translatable="false">123456789000-e4uksm38sne0bqrj6uvkbo4oiu4hvigl.apps.googleusercontent.com</string>
<string name="firebase_database_url" translatable="false">https://mockproject-1234.firebaseio.com</string>
<string name="gcm_defaultSenderId" translatable="false">123456789000</string>
<string name="google_api_key" translatable="false">AIzbSzCn1N6LWIe6wthYyrgUUSAlUsdqMb-wvTo</string>
<string name="google_app_id" translatable="false">1:123456789000:android:f1bf012572b04063</string>
<string name="google_crash_reporting_api_key" translatable="false">AIzbSzCn1N6LWIe6wthYyrgUUSAlUsdqMb-wvTo</string>
<string name="project_id" translatable="false">mockproject-1234</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.library") version System.getProperty("agpVersion") apply false
id("com.google.gms.google-services") version System.getProperty("pluginVersion") apply false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonFinalResIds=false
org.gradle.jvmargs=-Xmx2000m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
id("com.android.library")
id("com.google.gms.google-services")
}

import com.google.gms.googleservices.GoogleServicesPlugin.MissingGoogleServicesStrategy

android {
namespace = "com.example.mylibrary"
compileSdk = 33

defaultConfig {
minSdk = 24
}
}

googleServices {
missingGoogleServicesStrategy = MissingGoogleServicesStrategy.ERROR
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"project_info": {
"project_id": "mockproject-1234",
"project_number": "123456789000",
"name": "FirebaseQuickstarts",
"firebase_url": "https://mockproject-1234.firebaseio.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:123456789000:android:f1bf012572b04063",
"client_id": "android:com.example.mylibrary",
"client_type": 1,
"android_client_info": {
"package_name": "com.example.mylibrary",
"certificate_hash": []
}
},
"oauth_client": [
{
"client_id": "123456789000-hjugbg6ud799v4c49dim8ce2usclthar.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.example.mylibrary",
"certificate_hash": "4C20644DE36B8F89D25650C7D1FF9FBAE650FDF7"
}
},
{
"client_id": "123456789000-e4uksm38sne0bqrj6uvkbo4oiu4hvigl.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzbSzCn1N6LWIe6wthYyrgUUSAlUsdqMb-wvTo"
}
],
"services": {
"analytics_service": {
"status": 1
},
"cloud_messaging_service": {
"status": 2,
"apns_config": []
},
"appinvite_service": {
"status": 2,
"other_platform_oauth_client": [
{
"client_id": "123456789000-e4uksm38sne0bqrj6uvkbo4oiu4hvigl.apps.googleusercontent.com",
"client_type": 3
}
]
},
"google_signin_service": {
"status": 2
},
"ads_service": {
"status": 2,
"test_banner_ad_unit_id": "ca-app-pub-3940256099942544/6300978111",
"test_interstitial_ad_unit_id": "ca-app-pub-3940256099942544/1033173712"
}
}
}
],
"client_info": [],
"ARTIFACT_VERSION": "1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest>

<application />

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
pluginManagement {
repositories {
maven {
val pluginRepo: String by settings
url = uri(pluginRepo)
}
google()
mavenCentral()
}
}

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}

include(":lib")
Loading