Module: Pod::Podfile::DSL

Defined in:
lib/cocoapods-binary-flutter/hook/podfile.rb

Instance Method Summary collapse

Instance Method Details

#flutter_post_install(installer, skip: false) ⇒ Object

Run the post-install script to set build settings on Flutter plugins.

Examples:

post_install do |installer|
  flutter_post_install(installer)
end

Parameters:

  • installer (Pod::Installer)

    Passed to the post_install block.

  • skip (boolean) (defaults to: false)

    Do not change any build configurations. Set to suppress “Missing ‘flutter_post_install” exception.



117
118
119
120
121
122
123
124
125
126
127
# File 'lib/cocoapods-binary-flutter/hook/podfile.rb', line 117

def flutter_post_install(installer, skip: false)
  return if skip

  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |build_configuration|
      # flutter_additional_ios_build_settings is in Flutter root podhelper.rb
      # Annotation under invoke for cocoapods-binary-flutter use
      # flutter_additional_ios_build_settings(target)
    end
  end
end

#install_all_lzflutter_pods(flutter_binary_path) ⇒ Object

安装



73
74
75
76
77
# File 'lib/cocoapods-binary-flutter/hook/podfile.rb', line 73

def install_all_lzflutter_pods(flutter_binary_path)
  install_lzflutter_engine_pod(flutter_binary_path)
  install_lzflutter_plugin_pods(flutter_binary_path)
  install_lzflutter_application_pod(flutter_binary_path)
end

#install_lzflutter_application_pod(flutter_binary_path) ⇒ Object

Install Flutter application pod.



104
105
106
# File 'lib/cocoapods-binary-flutter/hook/podfile.rb', line 104

def install_lzflutter_application_pod(flutter_binary_path)
  pod 'App', :path => File.join(flutter_binary_path, 'flutter'), :inhibit_warnings => true
end

#install_lzflutter_engine_pod(flutter_binary_path) ⇒ Object

安装flutter引擎



80
81
82
# File 'lib/cocoapods-binary-flutter/hook/podfile.rb', line 80

def install_lzflutter_engine_pod(flutter_binary_path)
  pod 'Flutter', :podspec => File.join(flutter_binary_path, 'flutter', 'Flutter.podspec'), :inhibit_warnings => true
end

#install_lzflutter_plugin_pods(flutter_binary_path) ⇒ Object

Install Flutter plugin pods.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/cocoapods-binary-flutter/hook/podfile.rb', line 85

def install_lzflutter_plugin_pods(flutter_binary_path)
  # Keep pod path relative so it can be checked into Podfile.lock.
  # Process will be run from project directory.

  #FlutterPluginRegistrant
  pod 'FlutterPluginRegistrant', :path => File.join(flutter_binary_path, 'flutter', 'FlutterPluginRegistrant'), :inhibit_warnings => true
  
  #插件目录
  ios_plugins_directory_pathname = File.join(flutter_binary_path, 'plugins')

  #plugins遍历
  Dir.foreach(ios_plugins_directory_pathname) do |item|
    next if item == '.' or item == '..' or File::directory?(File.join(ios_plugins_directory_pathname, item)) == false
    # do work on real items
    pod item, :path => File.join(ios_plugins_directory_pathname, item, 'ios'), :inhibit_warnings => true
  end
end

#install_remote_flutter_binary(url = nil) ⇒ Object

下载



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/cocoapods-binary-flutter/hook/podfile.rb', line 16

def install_remote_flutter_binary(url = nil)
  #md5
  md5 = Digest::MD5.new               # =>#<Digest::MD5>
  md5 << url
  md5value = md5.hexdigest                        # => "78e73102..."
  flutter_f_home = Dir.home+'/Library/Caches/CocoaPods/Flutter/'
  flutter_binary_home = flutter_f_home+md5value
  flutter_binary_path = flutter_binary_home+'/binary'
  
  #创建目录
  FileUtils.mkdir_p(flutter_binary_home)

  #清除超过30天的缓存
  Dir.foreach(flutter_f_home) do |item|
    next if item == '.' or item == '..' or item == '.DS_Store'
    # do work on real items
    dirpath = flutter_f_home+item
    if File.directory?(dirpath)
      a = File.mtime(dirpath)
      t = Time.new
      if (t-a).round/60/60/24 > 30
        FileUtils.remove_dir(dirpath)
      end
    end  

  end
  
  #判断缓存
  if File::directory?(flutter_binary_path) == false
    #下载
    puts "开始下载 "+url
    uri = URI(url)
    download_file = open(flutter_binary_home+"/binary.zip", "wb")
    Net::HTTP.start(uri.host, uri.port,
      :use_ssl => uri.scheme == 'https', 
      :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|

      request = Net::HTTP::Get.new uri.request_uri
      request.basic_auth 'zhiya_official', '202525631b169f4446103671d4ff0661'
      begin
        http.request(request) do |resp|
          resp.read_body { |segment| download_file.write(segment) }
        end
      ensure
        download_file.close
      end
    end
    #解压
    puts "开始解压"+flutter_binary_home
    system("unzip", "-n", flutter_binary_home+'/binary.zip', "-d", flutter_binary_home)
  end

  #集成
  install_all_lzflutter_pods(flutter_binary_path)
end