Class: Pindo::Command::Unity::Apk

Inherits:
Pindo::Command::Unity show all
Includes:
Appselect
Defined in:
lib/pindo/command/unity/apk.rb

Constant Summary

Constants inherited from Pindo::Command

DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS

Instance Attribute Summary

Attributes inherited from Pindo::Command

#args_help_flag

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Appselect

#all_deploy_bundle_name, #all_dev_bundle_name, #all_dev_bundleid, #all_itc_bundleid, #all_release_bundleid, #all_tool_bundleid, #deploy_build_setting_json, #dev_build_setting_json, #get_deploy_repo_with_modul_name, #get_deploy_setting_repo, #get_dev_setting_repo, #get_selected_deploy_bundle_name, #get_selected_deploy_bundleid, #get_selected_dev_bundle_name, #get_selected_dev_bundleid, #get_setting_bundleid_withdir, #load_setting, #select_main_app

Methods inherited from Pindo::Command

run, #validate!

Methods included from Funlog::Mixin

#pindo_log_instance

Methods included from Pindoconfig::Mixin

#pindo_single_config

Methods included from Githelper

#add_branch, #add_tag, #add_tag_with_check, #clone_clang_repo, #clone_devclang_repo, #clone_pindo_common_config_repo, #clone_pindo_env_config_repo, #clong_buildconfig_repo, #get_repo_base_name, #getcode_to_dir, #git_addpush_repo, #git_latest_commit_id, #git_root_directory, #is_git_directory?, #local_branch_exists?, #local_tag_exists?, #prepare_gitenv, #process_need_add_files, #remote_branch_exists?, #remote_tag_exists?, #remove_branch, #remove_tag

Methods included from Executable

capture_command, #executable, execute_command, which, which!

Constructor Details

#initialize(argv) ⇒ Apk

Returns a new instance of Apk.



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/pindo/command/unity/apk.rb', line 67

def initialize(argv)

    @args_proj_name = argv.option('proj')
    @args_bundle_name = argv.option('bundle_name')
    @args_upload_flag = argv.flag?('upload', false)
    @args_send_flag = argv.flag?('send', false)

    if @args_send_flag
        @args_upload_flag = true
    end

    super
end

Class Method Details

.optionsObject

命令的选项列表



58
59
60
61
62
63
64
65
# File 'lib/pindo/command/unity/apk.rb', line 58

def self.options
    [
        ['--proj=NAME',   '指定上传到测试平台的项目名称'],
        ['--bundle_name=NAME', '指定Android Package Name(如com.example.app,会拉取对应配置)'],
        ['--upload',      '编译后上传到测试平台(自动发送给自己)'],
        ['--send',        '发送通知到测试群组(同时发送给自己)']
    ].concat(super)
end

.use_cache?Boolean

启用缓存机制

Returns:

  • (Boolean)


19
20
21
# File 'lib/pindo/command/unity/apk.rb', line 19

def self.use_cache?
    true  # 此命令启用缓存
end

Instance Method Details

#runObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/pindo/command/unity/apk.rb', line 81

def run
    pindo_project_dir = Dir.pwd

    # 加载 JPS 配置(如果存在)
    context = Pindo::PindoContext.instance
    context.load_and_apply_jps_config(pindo_project_dir)

    # 确认并应用缓存(如果有)
    context.confirm_and_apply_cache

    @main_bundle_name = nil
    if @args_bundle_name
        @main_bundle_name = @args_bundle_name
    else
        @main_bundle_name = get_selected_dev_bundle_name()
    end


    # 检查是否是Unity工程
    unity_helper = Pindo::Client::UnityHelper.share_instance
    unless unity_helper.unity_project?(pindo_project_dir)
        raise Informative, "当前目录不是Unity工程,请在Unity工程根目录下执行此命令"
    end
    build_helper = Pindo::BuildHelper.share_instance
    if @args_upload_flag
      is_need_add_tag,tag_action_parms = build_helper.check_is_need_add_tag?(pindo_project_dir)
      if is_need_add_tag
          Pindo::Command::Utils::Tag::run(tag_action_parms)
      end
    end
    
    project_unity_version = unity_helper.get_unity_version(pindo_project_dir)
    puts
    puts "工程的Unity版本: #{project_unity_version}"
    unity_exe_path = unity_helper.find_unity_path(project_unity_version:project_unity_version, force_change_version: @force_select_unity)
    puts "选择的Unity路径: #{unity_exe_path}"
    puts

    app_info_obj = nil
    workflow_info = nil
    proj_name = @args_proj_name
    # 传入 package_type 获取 workflow_info
    app_info_obj, workflow_info = PgyerHelper.share_instace.prepare_upload(
      working_directory: Dir.pwd,
      proj_name: proj_name,
      package_type: 'apk'
    )

    isLibrary = @args_base_flag

    android_export_lib_dir = File.join(pindo_project_dir, "GoodPlatform/BaseAndroid")
    if File.directory?(android_export_lib_dir)
        isLibrary = true
    end

    pindo_android_project_dir = File.join(pindo_project_dir, "GoodPlatform/Android")
    if isLibrary
        pindo_android_project_dir = android_export_lib_dir
    end

    # 获取 apkCount 用于传递给 Unity 构建
    apk_count = app_info_obj&.dig("apkCount") || -1

    puts "开始构建Unity项目..."

    begin
        unity_helper.build_project(
            unity_exe_full_path: unity_exe_path,
            project_path: pindo_project_dir,
            platform: 'Android',
            isLibrary: isLibrary,
            indexNo: apk_count
        )
    rescue => e
        Funlog.instance.fancyinfo_error("调用GoodUnityBuild导出工程失败!")
        Funlog.instance.fancyinfo_error("错误信息: #{e.message}")
        raise e
    end

    puts "Unity项目构建完成,准备处理Android项目..."

    args_temp = []

    # 传递 bundle_name 参数
    if @main_bundle_name
        args_temp << "--bundle_name=#{@main_bundle_name}"
    end

    if @args_upload_flag
        args_temp << "--proj=#{app_info_obj["projectName"]}"
        args_temp << "--upload"
    end
    if @args_send_flag
        args_temp << "--send"
    end

    Dir.chdir(pindo_android_project_dir)

    Pindo::Command::Android::Autobuild::run(args_temp)
end