lib/cocoapods-flutter/native/archive/archive.rb in cocoapods-flutter-dt-0.2.6 vs lib/cocoapods-flutter/native/archive/archive.rb in cocoapods-flutter-dt-0.2.7

- old
+ new

@@ -2,10 +2,11 @@ require 'cocoapods' require 'zip' require 'cocoapods-flutter/native/archive/zip_tool' require 'cocoapods-flutter/native/archive/remote' require 'molinillo' +require 'plist' class Archiver class Plugins attr_reader :spec @@ -45,10 +46,15 @@ @pod_repo = repo @build_modes = build_modes end def archive + # open('http://127.0.0.1:8080/frameworks/download/Flutter/1.22.6/release/file.zip') do |u| + # File.open('/Users/dreamtracer/Desktop/flutter.zip', "w+") do |file| + # file.write u.read.force_encoding("UTF-8") + # end + # end @pub_upgrade ? pub_upgrade : pub_get if local_podfile_exists? use_local_podfile else @@ -297,13 +303,58 @@ end end end sdk_file = zip_file_dir + "/Flutter.zip" + home_dir = Dir.home + cache_dir = home_dir + "/.cocoapods/.cache" + flutter_sdk_dsym_dir = cache_dir + "/flutter_sdk_dsym" + #创建dsym缓存文件 + if Dir.exist?(flutter_sdk_dsym_dir) == false + Dir.mkdir flutter_sdk_dsym_dir + end + Zip::File.open sdk_file, Zip::File::CREATE do |zipfile| file = File.join(product_dir, "Flutter.framework") - zipfile.add_dir "Flutter.framework", file + zipfile.add_dir "Flutter/Flutter.framework", file + #读取Flutter.framework中的info.plist文件中的FlutterEngine的值 + info_plist_path = File.join(file, "Info.plist") + info_plist = Plist.parse_xml(info_plist_path) + engine_hash = info_plist["FlutterEngine"] + dsym_dir = File.join(flutter_sdk_dsym_dir, engine_hash) + dsym_zip_file_path = File.join(dsym_dir, 'Flutter.framework.dSYM.zip') + dsym_file_path = File.join(dsym_dir, 'Flutter.framework.dSYM') + #检查dsym文件缓存 + Pod::UserInterface.info "Checking Flutter.framework.dSYM at #{dsym_dir}" + if Dir.exist?(dsym_dir) == false + Pod::UserInterface.info "Flutter.framework.dSYM not found at #{dsym_dir}" + Dir.mkdir(dsym_dir) unless Dir.exist?(dsym_dir) + #下载dsym + remote = Remote.new() + remote.download_flutter_sdk_dsym @flutter_version, engine_hash, dsym_zip_file_path + Pod::UserInterface.info "Flutter.framework.dSYM download success" + Dir.mkdir(dsym_file_path) unless File.exist?(dsym_file_path) + + Pod::UserInterface.info "Start unzip #{dsym_zip_file_path}" + Zip::File.open(dsym_zip_file_path) do |zif_file| + zif_file.each do |entry| + # 通过下句打印可知,entyr是Zip::ZipEntry的对象 + # puts entry.class + # 利用File.join构建文件存放的路径,路径为存放目录加上压缩文件的相对路径 + entry.extract(File.join(dsym_dir, entry::name)) + end + end + #重命名:如果文件名为Flutter.dSYM,则将Flutter.dSYM重命名为Flutter.framework.dSYM,因为cocoapods只识别Flutter.framework.dSYM + File.rename( File.join( dsym_dir, 'Flutter.dSYM'), dsym_file_path ) if File.exist? File.join( dsym_dir, 'Flutter.dSYM') + + Pod::UserInterface.info "Unzip #{dsym_zip_file_path} success" + + end + + #向zip中添加dsym文件 + Pod::UserInterface.info "Add Flutter.framework.dSYM to #{sdk_file}" + zipfile.add_dir "Flutter/Flutter.framework.dSYM", dsym_file_path end [zip_file, sdk_file] end def sdk_download @@ -320,11 +371,11 @@ Digest::MD5.hexdigest url end def download(url, dest) open(url) do |u| File.open(dest, "w+") do |file| - file.write u.read + file.write u.read.force_encoding("UTF-8") end end end home_dir = Dir.home cache_dir = home_dir + "/.cocoapods/.cache" @@ -336,12 +387,12 @@ sdk_file = sdk_dir + "/Flutter.zip" if Dir.exist?(sdk_dir) == false Dir.mkdir sdk_dir download sdk_url, sdk_file end -if File.exist? "Flutter.framework" - `rm -rf Flutter.framework` +if Dir.exist? "Flutter" + `rm -rf Flutter` end `unzip \#{sdk_file} -d \#{Dir.pwd}` CODE ruby_code @@ -368,11 +419,10 @@ remote.upload 'Flutter', @flutter_version, mode.downcase, flutter_sdk end if result Pod::UserInterface.info "Flutter_#{@flutter_version}_#{mode.downcase} was found, skip upload" end - end def ignore_dependency?(name) if name == 'Flutter' return true @@ -412,11 +462,11 @@ s.source = { :http => app_download_url } s.ios.deployment_target = '10.0' s.prepare_command = "ruby download_sdk.rb #{sdk_download_url}" s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64 x86_64' } s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64 x86_64' } - vendored_frameworks = ["App.framework", "Flutter.framework", "FlutterPluginRegistrant.framework"] + vendored_frameworks = ["App.framework", "Flutter/Flutter.framework", "FlutterPluginRegistrant.framework"] @plugins.each do |plugin| vendored_frameworks.append "#{plugin.name}.framework" end s.vendored_frameworks = vendored_frameworks @@ -428,10 +478,10 @@ temp_dir = Dir.tmpdir spec_file = temp_dir + "/#{@module_name}_#{mode.downcase}.podspec.json" File.open spec_file, "w+" do |file| file.write spec.to_pretty_json end - + Pod::UserInterface.info "podspec file path #{spec_file}" Dir.chdir temp_dir do |dir| Pod::Command::Repo::Push.run([@pod_repo, '--skip-import-validation', '--verbose', '--allow-warnings', "--sources=#{@sources.join(',')}"]) File.delete spec_file end