@@ -37,9 +37,9 @@ import org.gradle.kotlin.dsl.register
37
37
*/
38
38
abstract class CopyGoogleServicesPlugin : Plugin <Project > {
39
39
override fun apply (project : Project ) {
40
- val copyRootGoogleServices = registerCopyRootGoogleServicesTask(project)
41
40
val sourcePath =
42
41
System .getenv(" FIREBASE_GOOGLE_SERVICES_PATH" ) ? : " ${project.rootDir} /google-services.json"
42
+ val copyRootGoogleServices = registerCopyRootGoogleServicesTask(project, sourcePath)
43
43
if (! File (project.projectDir, " google-services.json" ).exists() && ! File (sourcePath).exists()) {
44
44
val createDummyGoogleServices = registerDummyGoogleServicesTask(project, sourcePath)
45
45
copyRootGoogleServices.dependsOn(createDummyGoogleServices)
@@ -48,7 +48,7 @@ abstract class CopyGoogleServicesPlugin : Plugin<Project> {
48
48
project.allprojects {
49
49
// fixes dependencies with gradle tasks that do not properly dependOn `preBuild`
50
50
tasks.configureEach {
51
- if (name != = " copyRootGoogleServices" && name != = " createRootGoogleServices " ) {
51
+ if (name != = " copyRootGoogleServices" && name != = " copyDummyGoogleServices " ) {
52
52
dependsOn(copyRootGoogleServices)
53
53
}
54
54
}
@@ -67,56 +67,28 @@ abstract class CopyGoogleServicesPlugin : Plugin<Project> {
67
67
}
68
68
69
69
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" }
102
76
}
103
77
104
- private fun registerCopyRootGoogleServicesTask (project : Project ) =
78
+ private fun registerCopyRootGoogleServicesTask (project : Project , path : String ) =
105
79
project.tasks.register<Copy >(" copyRootGoogleServices" ) {
106
- val sourcePath =
107
- System .getenv(" FIREBASE_GOOGLE_SERVICES_PATH" ) ? : " ${project.rootDir} /google-services.json"
108
80
109
81
val library = project.extensions.getByType<BaseExtension >()
110
82
111
83
val targetPackageLine = " \" package_name\" : \" ${library.namespace} \" "
112
84
val packageLineRegex = Regex (" \" package_name\" :\\ s+\" .*\" " )
113
85
114
- from(sourcePath )
86
+ from(path )
115
87
into(project.projectDir)
116
88
117
89
rename { " google-services.json" }
118
90
119
- if (fileIsMissingPackageName(sourcePath , targetPackageLine)) {
91
+ if (fileIsMissingPackageName(path , targetPackageLine)) {
120
92
/* *
121
93
* Modifies `google-services.json` such that all declared `package_name` entries are
122
94
* replaced with the project's namespace. This tricks the google services plugin into
0 commit comments