In the previous article, The Dependency Flutter Module on iOS Projects -① Local dependencies, we sorted out three local dependency solutions. This article will implement a simple but difficult remote dependency solution. The idea behind the remote dependency is to put the build up to a remote Git or remote file server and do version management. The. Xcframework product is imported into the project via CocoaPods from Git or the file server.

So far I have found four remote dependency solutions. This article covers the first one. If you want to see the other options in advance, go to the portal 🚪.

  1. Rely remotely on the.XCFramework and.PodSpec on Git
  2. Local. Podspec relaying relies on the.XCFramework on remote Git
  3. Local. Podspec relaying relies on the.xcFramework.zip compression file on the remote file server
  4. Local. Podspec relaying depends on other.xcFramework on the remote file server with the Flutter. Xcframework.zip + Git

Rely remotely on the.XCFramework and.PodSpec on Git

Preparation stage

As in the previous post, create a Flutter Module;

cd some/path/
flutter create --template module flutter_module
Copy the code

The structure of the flutter_module directory is as follows… /flutter_module/lib/ is the dart file we wrote.

│ ├─ build │ ├─ flutter_module.iml │ ├─ flutter_module.iml │ ├─ flutter_module.iml │ ├─ flutter_module.iml │ ├─ flutter_module.iml │ ├─ flutter_module_android ├ ─ ─ lib │ ├ ─ ─ pubspec. Lock │ ├ ─ ─ pubspec. Yaml │ └ ─ ─ the testCopy the code

Once you have the Flutter_Module built, add any flutter code and third party components (such as Flutter_boost).

If you want to put the compiled products in remote Git, you need to create a Git repository, such as FlutterModulesdk.git.

starts

First compile flutter_module and specify the path to the local flutterModulesdk.git root. /.. / FlutterModuleSDK /.

cd flutter_module/ flutter build ios-framework --xcframework --no-universal --output=.. /.. /FlutterModuleSDK/Copy the code

After compiling, the following files will be added to the FlutterModuleSDK directory. To reduce the file size, just use the 4.xcFramework under Release. Move the 4.xcFramework to the FlutterModuleSDK root directory. Delete the Debug/Profile/Release3 folder. It is no longer needed.

Xcfromework can be compiled directly with the above instructions or downloaded from the zip file with the following instructions. There is also a cocoapods option in the middle, which I used for my personal tests. Then download the ZIP and unzip it to get Vibe.xcfromeWork.

flutter build ios-framework --cocoapods --xcframework --no-universal --output=.. /.. /FlutterModuleSDK/Copy the code

At this point, there are only a few *.xcfromework files in the FlutterModuleSDK root directory besides.git.

Flutter. Xcfromework App. Xcframework FlutterPluginRegistrant. Xcframework other third-party libraries Such as flutter_boost xcframeworkCopy the code

To remotely rely on CocoaPods, you also need to create a. Podspec file. Create a flutterModulesdk.podspec file in the FlutterModuleSDK root directory. Create a flutterModulesdk.podspec file. The core difference is s.endored_frameworks = ‘*.xcframework’. The library only has.xcFramework files and no other code files.

Pod::Spec.new do |s|
  s.name                  = 'FlutterModuleSDK'
  s.version               = '1.0.2'
  s.summary               = 'Flutter Module SDK'
  s.source                = { :git => 'https://a.gitlab.cn/flutter/FlutterModuleSDK.git', :tag => "#{s.version}" }
  s.platform              = :ios, '8.0'
  s.requires_arc          = true
  s.vendored_frameworks   = '*.xcframework'
end
Copy the code

Then commit git, label it with the corresponding version and push it to the remote repository flutterModulesdk.git

After a long wait... The # Flutter. Xcfromework file is very large and will be slow to upload to GitCopy the code

If the push is successful, the process of pushing the product to the cloud is completed, and the following operations will be performed by the iOS side.

Add a dependency to your Podfile

pod 'FlutterModuleSDK', :git => 'https://a.gitlab.cn/flutter/FlutterModuleSDK.git', :tag => '1.0.1'
Copy the code

Pull the component library, pod Install or Update, and run the project.

summary

In addition to the preparation stage, the main steps of this scheme can be divided into three steps, the trouble is to extract the product, and then upload and download will be slow.

[1. Compile] : Compile FlutterModule [2. Publish] collect products to the cloud Git [3

The pros: All of the developed Framework of the Flutter is in Git for unified versioning. The Development of the Flutter can be independent of iOS development, and not all iOS developers need to install the Flutter development environment, which avoids the problems of inconsistent versions of the Flutter on iOS.

Cons: The upload. xcframework file is too large, not compressed, time consuming to upload to git/download from git clone. If Git has a single file size limit, it won’t Push.

Later in this article, we'll look at ways to rely on remote resources for local PodSpec relaying to avoid the problem of '.xcFramework 'files affecting uploads and downloads too much.Copy the code