Commit 010a5e62 authored by wanglei's avatar wanglei

...

parent 855fcbdb
Pipeline #1461 failed with stages
......@@ -100,6 +100,9 @@ def update_global_config(file_path, json_data):
print(f"更新文件时发生错误: {e}")
import os
import json
def update_google_services(json_data):
"""更新 google-services.json 文件内容"""
try:
......@@ -108,8 +111,10 @@ def update_google_services(json_data):
if os.path.exists(google_services_path):
print(f"找到 google-services.json 文件: {google_services_path}")
# 从 applicationid.json 中读取 googleServices 的值
# 从 applicationid.json 中读取数据
google_services_raw = json_data.get("googleServices")
package_name = json_data.get("PACKAGE_NAME")
if google_services_raw:
try:
# 反序列化 googleServices 的值
......@@ -127,12 +132,31 @@ def update_google_services(json_data):
except json.JSONDecodeError as e:
print(f"googleServices 值的反序列化失败: {e}")
else:
print("applicationid.json 中未找到 googleServices 的值。")
if package_name:
print("googleServices 的值为空,尝试更新 package_name。")
with open(google_services_path, "r", encoding="utf-8") as file:
google_services_data = json.load(file)
# 更新 package_name
if "client" in google_services_data:
for client in google_services_data["client"]:
if "client_info" in client and "android_client_info" in client["client_info"]:
client["client_info"]["android_client_info"]["package_name"] = package_name
print(f"已将 package_name 更新为: {package_name}")
# 写入更新后的数据
with open(google_services_path, "w", encoding="utf-8") as file:
json.dump(google_services_data, file, ensure_ascii=False, indent=4)
print("\ngoogle-services.json 文件已更新(更新 package_name)。")
else:
print("未找到 PACKAGE_NAME 值,无法更新 package_name。")
else:
print("未找到 google-services.json 文件。")
except Exception as e:
print(f"更新 google-services.json 文件时发生错误: {e}")
def update_build_gradle(json_data):
"""更新 build.gradle 或 build.gradle.kts 文件中的 applicationId 值"""
try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment