@@ -37,9 +37,9 @@ import org.gradle.kotlin.dsl.register
3737 */
3838abstract class CopyGoogleServicesPlugin : Plugin <Project > {
3939 override fun apply (project : Project ) {
40- val copyRootGoogleServices = registerCopyRootGoogleServicesTask(project)
4140 val sourcePath =
4241 System .getenv(" FIREBASE_GOOGLE_SERVICES_PATH" ) ? : " ${project.rootDir} /google-services.json"
42+ val copyRootGoogleServices = registerCopyRootGoogleServicesTask(project, sourcePath)
4343 if (! File (project.projectDir, " google-services.json" ).exists() && ! File (sourcePath).exists()) {
4444 val createDummyGoogleServices = registerDummyGoogleServicesTask(project, sourcePath)
4545 copyRootGoogleServices.dependsOn(createDummyGoogleServices)
@@ -48,7 +48,7 @@ abstract class CopyGoogleServicesPlugin : Plugin<Project> {
4848 project.allprojects {
4949 // fixes dependencies with gradle tasks that do not properly dependOn `preBuild`
5050 tasks.configureEach {
51- if (name != = " copyRootGoogleServices" && name != = " createRootGoogleServices " ) {
51+ if (name != = " copyRootGoogleServices" && name != = " copyDummyGoogleServices " ) {
5252 dependsOn(copyRootGoogleServices)
5353 }
5454 }
@@ -67,56 +67,28 @@ abstract class CopyGoogleServicesPlugin : Plugin<Project> {
6767 }
6868
6969 private fun registerDummyGoogleServicesTask (project : Project , path : String ) =
70- project.tasks.register(" createRootGoogleServices" ) {
71- println (" Google services file not found, using fallback" )
72- File (path)
73- .writeText(
74- """
75- {
76- "project_info": {
77- "project_number": "1234567",
78- "firebase_url": "https://project-12345.firebaseio.com",
79- "project_id": "project-12345",
80- "storage_bucket": "project-12345.firebasestorage.app"
81- },
82- "client": [
83- {
84- "client_info": {
85- "mobilesdk_app_id": "1:1234567:android:12345ffff54321",
86- "android_client_info": {
87- "package_name": "com.example.myapplication"
88- }
89- },
90- "api_key": [
91- {
92- "current_key": "RaNdoMLett3r5aNdNuMb3rS"
93- }
94- ]
95- }
96- ],
97- "configuration_version": "1"
98- }
99- """
100- .trimIndent()
101- )
70+ project.tasks.register<Copy >(" copyDummyGoogleServices" ) {
71+ logger.warn(" Google services file not found, using fallback" )
72+
73+ from(" ${project.rootDir} /plugins/resources/dummy-google-services.json" )
74+ into(path)
75+ rename { " google-services.json" }
10276 }
10377
104- private fun registerCopyRootGoogleServicesTask (project : Project ) =
78+ private fun registerCopyRootGoogleServicesTask (project : Project , path : String ) =
10579 project.tasks.register<Copy >(" copyRootGoogleServices" ) {
106- val sourcePath =
107- System .getenv(" FIREBASE_GOOGLE_SERVICES_PATH" ) ? : " ${project.rootDir} /google-services.json"
10880
10981 val library = project.extensions.getByType<BaseExtension >()
11082
11183 val targetPackageLine = " \" package_name\" : \" ${library.namespace} \" "
11284 val packageLineRegex = Regex (" \" package_name\" :\\ s+\" .*\" " )
11385
114- from(sourcePath )
86+ from(path )
11587 into(project.projectDir)
11688
11789 rename { " google-services.json" }
11890
119- if (fileIsMissingPackageName(sourcePath , targetPackageLine)) {
91+ if (fileIsMissingPackageName(path , targetPackageLine)) {
12092 /* *
12193 * Modifies `google-services.json` such that all declared `package_name` entries are
12294 * replaced with the project's namespace. This tricks the google services plugin into
0 commit comments