sdk 版本号
This commit is contained in:
parent
8a2ebc472e
commit
ced5e1b4bf
|
@ -1,4 +1,10 @@
|
|||
certifi==2025.6.15
|
||||
charset-normalizer==3.4.2
|
||||
gitdb==4.0.12
|
||||
GitPython==3.1.44
|
||||
idna==3.10
|
||||
javaproperties==0.8.2
|
||||
lxml==6.0.0
|
||||
requests==2.32.4
|
||||
smmap==5.0.2
|
||||
urllib3==2.5.0
|
||||
|
|
|
@ -28,6 +28,9 @@ class Context:
|
|||
|
||||
config: any = None
|
||||
|
||||
sdk_version: str = ""
|
||||
sdk_prolink_version: str = ""
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str):
|
||||
data = json.loads(json_str)
|
||||
|
|
|
@ -3,6 +3,8 @@ from pathlib import Path
|
|||
import re
|
||||
|
||||
import javaproperties
|
||||
import requests
|
||||
from lxml import etree
|
||||
|
||||
from scripts.context import Context
|
||||
from scripts.task import Task
|
||||
|
@ -10,6 +12,35 @@ from utils import FileUtils
|
|||
from utils.logger_utils import app_logger
|
||||
|
||||
|
||||
def update_dependency_version(content, dependency_name, new_version):
|
||||
"""
|
||||
更新 Gradle 依赖的版本号
|
||||
|
||||
:param content: Gradle 文件内容
|
||||
:param dependency_name: 依赖名称(可以是完整字符串或部分匹配)
|
||||
:param new_version: 新版本号
|
||||
:return: 更新后的内容
|
||||
"""
|
||||
# 匹配 implementation 声明,捕获组用于保留前缀和后缀
|
||||
pattern = rf"(implementation\s*\(\s*['\"]{re.escape(dependency_name)}:)([^'\"]+)(['\"]\s*\))"
|
||||
|
||||
# 替换版本号部分
|
||||
updated_content = re.sub(pattern, rf"\g<1>{new_version}\g<3>", content)
|
||||
|
||||
return updated_content
|
||||
|
||||
|
||||
def get_latest_version(url):
|
||||
try:
|
||||
response = requests.get(url)
|
||||
root = etree.fromstring(response.content)
|
||||
latest = root.xpath("//latest/text()") or root.xpath("//version[last()]/text()")
|
||||
return latest[0] if latest else None
|
||||
except Exception as e:
|
||||
app_logger().error(f"Error: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def uncomment_line(content, line_pattern):
|
||||
"""
|
||||
取消指定行的注释
|
||||
|
@ -217,7 +248,8 @@ storePassword=123456
|
|||
text = text.replace("WebActivity", "com.unity3d.player.UnityPlayerActivity")
|
||||
open(os.path.join(self.context.temp_project_path, GAME_ACTIVITY_PATH), "w", encoding="utf-8").write(text)
|
||||
|
||||
text = open(os.path.join(self.context.temp_project_path, ANDROID_MANIFEST_PATH), "r", encoding="utf-8").read()
|
||||
text = open(os.path.join(self.context.temp_project_path, ANDROID_MANIFEST_PATH), "r",
|
||||
encoding="utf-8").read()
|
||||
# text = text.replace("WebActivity", "com.unity3d.player.UnityPlayerActivity")
|
||||
open(os.path.join(self.context.temp_project_path, ANDROID_MANIFEST_PATH), "w", encoding="utf-8").write(text)
|
||||
|
||||
|
@ -275,12 +307,16 @@ storePassword=123456
|
|||
text = update_gradle_property(text, "derived_app_name", self.context.get_app_name())
|
||||
text = update_gradle_variable(text, "versionDisplayName", self.context.version_display_name)
|
||||
text = update_gradle_variable(text, "version_code", self.context.version_code)
|
||||
# text = text.
|
||||
text = update_dependency_version(text, f"straw:hachisdk_unity_{self.context.package_name}",
|
||||
self.context.sdk_prolink_version)
|
||||
text = update_dependency_version(text, f"com.game:hachisdk_unity_{self.context.package_name}",
|
||||
self.context.sdk_version)
|
||||
open(build_gradle_path, "w", encoding="UTF-8").write(text)
|
||||
pass
|
||||
|
||||
def execute(self):
|
||||
self.build_gradle_path = os.path.join(self.context.temp_project_path, "build.gradle")
|
||||
self.init_sdk_version()
|
||||
self.update_package_name()
|
||||
self.update_keystore()
|
||||
self.update_config()
|
||||
|
@ -289,3 +325,31 @@ storePassword=123456
|
|||
self.update_game_result()
|
||||
self.update_gradle_config()
|
||||
pass
|
||||
|
||||
def get_sdk_version(self) -> str:
|
||||
for i in range(3):
|
||||
try:
|
||||
url = f"https://repo.dgtverse.cn/repository/tk_my/com/game/hachisdk_unity_{self.context.package_name}/maven-metadata.xml"
|
||||
version = get_latest_version(url)
|
||||
if version:
|
||||
return version
|
||||
pass
|
||||
except Exception as e:
|
||||
pass
|
||||
raise Exception("sdk error.")
|
||||
|
||||
def get_prolink_version(self) -> str:
|
||||
for i in range(3):
|
||||
try:
|
||||
url = f"https://repo.dgtverse.cn/repository/tk_my/straw/hachisdk_unity_{self.context.package_name}/maven-metadata.xml"
|
||||
version = get_latest_version(url)
|
||||
if version:
|
||||
return version
|
||||
except Exception as e:
|
||||
pass
|
||||
raise Exception("sdk prolink error.")
|
||||
|
||||
def init_sdk_version(self):
|
||||
self.context.sdk_version = self.get_sdk_version()
|
||||
self.context.sdk_prolink_version = self.get_prolink_version()
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue