11@tool
2- class_name FirebaseEditorPlugin extends EditorPlugin
2+ extends EditorPlugin
33
44var export_plugin : AndroidExportPlugin
55
@@ -30,11 +30,11 @@ func _disable_plugin() -> void:
3030 remove_autoload_singleton ("Firebase" )
3131 _cleanup_gradle_files ()
3232
33- static func _cleanup_gradle_files () -> void :
33+ func _cleanup_gradle_files () -> void :
3434 _clean_line_from_file ("res://android/build/build.gradle" , BUILD_GRADLE_PLUGIN_LINE )
3535 _clean_line_from_file ("res://android/build/settings.gradle" , SETTINGS_GRADLE_PLUGIN_LINE )
3636
37- static func _clean_line_from_file (file_path : String , line_to_remove : String ) -> void :
37+ func _clean_line_from_file (file_path : String , line_to_remove : String ) -> void :
3838 if FileAccess .file_exists (file_path ):
3939 var text := FileAccess .open (file_path , FileAccess .READ ).get_as_text ()
4040 text = text .replace (line_to_remove , "" )
@@ -51,12 +51,12 @@ class AndroidExportPlugin extends EditorExportPlugin:
5151 return
5252
5353 if (not get_option ("gradle_build/use_gradle_build" )) or (not FileAccess .file_exists ("res://android/build/google-services.json" )):
54- FirebaseEditorPlugin ._cleanup_gradle_files ()
54+ _clean_line_from_file ("res://android/build/build.gradle" , BUILD_GRADLE_PLUGIN_LINE )
55+ _clean_line_from_file ("res://android/build/settings.gradle" , SETTINGS_GRADLE_PLUGIN_LINE )
5556 return
5657
57- # Modify build.gradle
58+ # Modify build.gradle and settings.gradle
5859 _insert_line_if_missing ("res://android/build/build.gradle" , "id 'org.jetbrains.kotlin.android'" , BUILD_GRADLE_PLUGIN_LINE )
59- # Modify settings.gradle
6060 _insert_line_if_missing ("res://android/build/settings.gradle" , "id 'org.jetbrains.kotlin.android' version versions.kotlinVersion" , SETTINGS_GRADLE_PLUGIN_LINE )
6161
6262 func _insert_line_if_missing (file_path : String , after_line : String , insert_line : String ) -> void :
@@ -67,7 +67,7 @@ class AndroidExportPlugin extends EditorExportPlugin:
6767 var lines := text .split ("\n " )
6868 var result := PackedStringArray ()
6969 var inserted := false
70-
70+
7171 for line in lines :
7272 result .append (line )
7373 if not inserted and line .strip_edges () == after_line .strip_edges ():
@@ -79,11 +79,19 @@ class AndroidExportPlugin extends EditorExportPlugin:
7979 break
8080 result .append (indent + insert_line )
8181 inserted = true
82-
82+
8383 var file := FileAccess .open (file_path , FileAccess .WRITE )
8484 file .store_string ("\n " .join (result ))
8585 file .close ()
8686
87+ func _clean_line_from_file (file_path : String , line_to_remove : String ) -> void :
88+ if FileAccess .file_exists (file_path ):
89+ var text := FileAccess .open (file_path , FileAccess .READ ).get_as_text ()
90+ text = text .replace (line_to_remove , "" )
91+ var file := FileAccess .open (file_path , FileAccess .WRITE )
92+ file .store_string (text )
93+ file .close ()
94+
8795 func _supports_platform (platform ):
8896 if platform is EditorExportPlatformAndroid :
8997 return true
0 commit comments