110 lines
4.1 KiB
Python
110 lines
4.1 KiB
Python
"""
|
|
안드로이드 앱 빌드 스크립트
|
|
고장코드 검색기 앱을 안드로이드 APK로 패키징합니다.
|
|
"""
|
|
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
from pathlib import Path
|
|
import flet_app_config as config
|
|
|
|
def build_android_app():
|
|
"""Flet 앱을 안드로이드 APK로 빌드합니다."""
|
|
print("고장코드 검색기 안드로이드 앱 빌드를 시작합니다...")
|
|
|
|
# 1. assets 디렉토리가 없으면 생성
|
|
if not os.path.exists("assets"):
|
|
os.makedirs("assets")
|
|
print("assets 디렉토리 생성 완료")
|
|
|
|
# 2. 아이콘이 없으면 기본 아이콘 생성 (실제 앱에서는 아이콘 파일을 준비해야 함)
|
|
icon_path = "assets/app_icon.png"
|
|
if not os.path.exists(icon_path):
|
|
print(f"앱 아이콘이 필요합니다. {icon_path}에 아이콘을 준비해주세요.")
|
|
return
|
|
|
|
# 3. 빌드 디렉토리 생성
|
|
build_dir = Path("build")
|
|
if build_dir.exists():
|
|
shutil.rmtree(build_dir)
|
|
build_dir.mkdir()
|
|
|
|
# 4. 필요한 파일 복사
|
|
files_to_copy = [
|
|
"main.py",
|
|
"fault_codes.db",
|
|
icon_path
|
|
]
|
|
|
|
# ui 및 database 모듈 복사
|
|
for dir_name in ["ui", "database"]:
|
|
src_dir = Path(dir_name)
|
|
if src_dir.exists():
|
|
shutil.copytree(src_dir, build_dir / dir_name)
|
|
|
|
for file in files_to_copy:
|
|
if os.path.exists(file):
|
|
shutil.copy2(file, build_dir)
|
|
|
|
# 5. flet build 명령어 실행
|
|
try:
|
|
# flet 0.21.2 버전에 맞는 명령어 형식으로 수정
|
|
cmd = [
|
|
"flet", "build", "apk",
|
|
"--project", config.APP_NAME,
|
|
"--org", config.APP_PACKAGE_NAME.rsplit(".", 1)[0], # "com.shinpyung"
|
|
"--build-version", config.APP_VERSION,
|
|
"--build-number", config.APP_BUILD,
|
|
str(build_dir) # 마지막 인수로 Python 앱 경로 지정
|
|
]
|
|
|
|
print("명령어 실행:", " ".join(cmd))
|
|
subprocess.run(cmd, check=True)
|
|
print("앱 빌드 완료!")
|
|
|
|
# 빌드된 APK 파일 위치 찾기 (경로가 다를 수 있음)
|
|
possible_apk_paths = [
|
|
build_dir / "build" / "app" / "outputs" / "flutter-apk" / "app-release.apk",
|
|
Path("build/build/app/outputs/flutter-apk/app-release.apk"),
|
|
Path(f"build/{config.APP_NAME}/build/app/outputs/flutter-apk/app-release.apk"),
|
|
Path(f"build/build/{config.APP_NAME}/app/outputs/flutter-apk/app-release.apk")
|
|
]
|
|
|
|
found_apk = False
|
|
for apk_path in possible_apk_paths:
|
|
if apk_path.exists():
|
|
# 최종 위치로 APK 복사
|
|
final_apk = Path(f"{config.APP_NAME}_{config.APP_VERSION}.apk")
|
|
shutil.copy2(apk_path, final_apk)
|
|
print(f"APK 파일이 생성되었습니다: {final_apk}")
|
|
found_apk = True
|
|
break
|
|
|
|
if not found_apk:
|
|
print("APK 파일을 찾을 수 없습니다. 빌드 디렉토리를 검색합니다...")
|
|
# 빌드 디렉토리 검색
|
|
for root, dirs, files in os.walk("build"):
|
|
for file in files:
|
|
if file.endswith(".apk"):
|
|
apk_path = os.path.join(root, file)
|
|
final_apk = Path(f"{config.APP_NAME}_{config.APP_VERSION}.apk")
|
|
shutil.copy2(apk_path, final_apk)
|
|
print(f"APK 파일을 찾았습니다: {apk_path}")
|
|
print(f"APK 파일을 복사했습니다: {final_apk}")
|
|
found_apk = True
|
|
break
|
|
if found_apk:
|
|
break
|
|
|
|
if not found_apk:
|
|
print("어떤 APK 파일도 찾을 수 없습니다. 다음 경로에서 빌드 결과 확인이 필요합니다:")
|
|
print(f"- {os.path.abspath(build_dir)}")
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"빌드 중 오류 발생: {e}")
|
|
except Exception as e:
|
|
print(f"예상치 못한 오류 발생: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
build_android_app() |