Flutter-已有iOS工程中加入Flutter之遠程Pod產物方式集成

相關鏈接,如有需要請移步:
Flutter-已有iOS工程中加入Flutter之Cocoapods+Flutter環(huán)境方式集成
Flutter-已有iOS工程中加入Flutter之遠程Pod產物方式集成
Flutter-遠程Pod集成Flutter腳本優(yōu)化

最近块茁,我研究了下不依賴flutter開發(fā)環(huán)境的方式集成剥险,推送到遠程pod倉庫,以Framework形式在cocoapods中集成狰闪。

開始

1. 創(chuàng)建flutter_module:flutter create -t module flutter_module

KKdeMacBook-Pro:remotepod kaye$ flutter create -t module flutter_module
Creating project flutter_module... androidx: true
flutter_module/test/widget_test.dart (created)
flutter_module/flutter_module.iml (created)
flutter_module/.gitignore (created)
flutter_module/.metadata (created)
flutter_module/pubspec.yaml (created)
flutter_module/README.md (created)
flutter_module/lib/main.dart (created)
flutter_module/flutter_module_android.iml (created)
flutter_module/.idea/libraries/Flutter_for_Android.xml (created)
flutter_module/.idea/libraries/Dart_SDK.xml (created)
flutter_module/.idea/modules.xml (created)
flutter_module/.idea/workspace.xml (created)
Running "flutter pub get" in flutter_module...                      1.7s
Wrote 12 files.

All done!
Your module code is in flutter_module/lib/main.dart.

添加依賴庫梢薪,比如:

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  shared_preferences: ^0.5.6

運行flutter pub get安裝依賴庫

KKdeMacBook-Pro:flutter_module kaye$ flutter pub get
Running "flutter pub get" in flutter_module...                      0.4s
KKdeMacBook-Pro:flutter_module kaye$ 

build獲取產物

KKdeMacBook-Pro:flutter_module kaye$ flutter build ios --debug --no-codesign
Warning: Building for device with codesigning disabled. You will have to manually codesign
before deploying to device.
Building com.example.flutterModule for device (ios)...
Running Xcode build...                                                  
                                                   
 ├─Assembling Flutter resources...                           6.8s
 └─Compiling, linking and signing...                         4.5s
Xcode build done.                                           17.6s
Built /Users/kaye/Desktop/remotepod/flutter_module/build/ios/iphoneos/Runner.app.

產物路徑:


基礎庫路徑.png
依賴插件路徑.png

我們先將各個產品,手動copy出來尝哆,放到一個文件夾ios_frameworks中備用秉撇。
note:這里我們先不用腳本,手動獲取秋泄,驗證一下pod能不能成功

2. 創(chuàng)建Pod:pod lib create KKFlutterPod

KKdeMacBook-Pro:remotepod kaye$ pod lib create KKFlutterPod
Cloning `https://github.com/CocoaPods/pod-template.git` into `KKFlutterPod`.
Configuring KKFlutterPod template.

------------------------------

To get you started we need to ask a few questions, this should only take a minute.

If this is your first time we recommend running through with the guide: 
 - https://guides.cocoapods.org/making/using-pod-lib-create.html
 ( hold cmd and double click links to open in a browser. )


What platform do you want to use?? [ iOS / macOS ]
 > ios

What language do you want to use?? [ Swift / ObjC ]
 > objc

Would you like to include a demo application with your library? [ Yes / No ]
 > no

Which testing frameworks will you use? [ Specta / Kiwi / None ]
 > none

Would you like to do view based testing? [ Yes / No ]
 > no

What is your class prefix?
 > KK

Running pod install on your new library.

Analyzing dependencies
Fetching podspec for `KKFlutterPod` from `../`
Downloading dependencies
Installing KKFlutterPod (0.1.0)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `KKFlutterPod.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

[!] Automatically assigning platform `ios` with version `9.3` on target `KKFlutterPod_Tests` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.

 Ace! you're ready to go!
 We will start you off by opening your project in Xcode
  open 'KKFlutterPod/Example/KKFlutterPod.xcworkspace'

To learn more about the template see `https://github.com/CocoaPods/pod-template.git`.
To learn more about creating a new pod, see `http://guides.cocoapods.org/making/making-a-cocoapod`.
KKdeMacBook-Pro:remotepod kaye$ 

將上一步的ios_frameworks文件夾移動到Pod倉庫中琐馆,目錄結構如下:

Pod庫中Framework目錄.png

3. 創(chuàng)建遠程Pod對應的Git倉庫

3.1 創(chuàng)建倉庫

這里自己測試使用的是GitHub,創(chuàng)建過程就不描述了恒序。

3.2 關聯倉庫

tip:或者你也可以先把遠程的Pod倉庫創(chuàng)建好瘦麸,clone下來,然后把創(chuàng)建的KKFlutterPod里面除了.git之外的所有文件拷貝到你clone的git倉庫中歧胁,從而省去關聯的關系

KKdeMacBook-Pro:flutter_module kaye$ cd ../KKFlutterPod/
KKdeMacBook-Pro:KKFlutterPod kaye$ git remote add origin https://github.com/yuyangkk/flutterpod.git

修改KKFlutterPod.podsepc文件,在其末尾添加如下:

s.static_framework = true
p = Dir::open("ios_frameworks")
arr = Array.new
arr.push('ios_frameworks/*.framework')
s.ios.vendored_frameworks = arr
podsepc文件.png
3.3 提交Pod到遠程
git add .
git commit -m "初始化"
git pull origin master
git push -u origin master

git tag -m "v0.1.0" -a 0.1.0
git push --tags
3.4 使用
pod 'KKFlutterPod', :git => 'https://github.com/yuyangkk/KKFlutterPod.git'

4. 腳本化

每次我們修改了flutter代碼滋饲,都要重新打包出來Framework厉碟,然后打上tag推送到遠程,這個過程雖然簡單屠缭,但是重復性很強箍鼓,所以考慮寫成腳本實現,以免有漏掉某些步驟呵曹!
ps:腳本有點不太規(guī)范款咖,是一邊看語法,一遍寫的奄喂,所以铐殃,有問題還請指出來

4.1. 編譯Framework并導出到指定位置
#cd ~/Desktop/remotepod/flutter_module
#獲取當前腳本目錄
projectURL=$(cd $(dirname $0); pwd)

#echo $projectURL

cd ${projectURL}

#out是指將編譯號的文件copy到指定的位置的路徑
if [ -z $out ]; then
    out='../KKFlutterPod/KKFlutterPod/ios_frameworks'
fi

echo "準備輸出所有文件到目錄: $out"

echo "清除所有已編譯文件"
#find . -d -name build | xargs rm -rf
flutter clean
rm -rf $out
rm -rf build

flutter packages get

echo "編譯flutter"
flutter build ios --debug --no-codesign
#如果是release包,將debug改為release
#flutter build ios --release --no-codesign
echo "編譯flutter完成"
mkdir $out

cp -r build/ios/Debug-iphoneos/*/*.framework $out
cp -r .ios/Flutter/App.framework $out
cp -r .ios/Flutter/engine/Flutter.framework $out

#本地Pod庫中提交代碼跨新,并修改version富腊,打上標簽,標簽和version保持一致域帐,自增
#上傳到pod蟹肘,請執(zhí)行腳本push_pod_spec.sh

4.2. 將導出的Framework上傳到遠程pod倉庫
projectURL=$(cd $(dirname $0); pwd)

#echo $projectURL

cd ${projectURL}

cd ../KKFlutterPod

echo "準備更新本地倉庫"
git pull

if [ $? -eq 0 ]; then
    echo "拉取遠程代碼成功"
else
    echo "拉取遠程代碼失敗"
    exit 1
fi

cd ${projectURL}

#修改KKFlutterPod.podspec中s.version          = '0.1.0'

# 讀取KKFlutterPod.podspec的第11行
# a=`cat KKFlutterPod.podspec |head -ne12`
# echo $a
a=`sed -n 11p KKFlutterPod.podspec `
# echo $a #s.version = '0.1.4'
# echo "刪除最右邊.開始向及其左邊的數據"
vs=${a##*.}
# echo $vs
oldNum=${vs%%\'*}
# echo '當前版本:'$oldNum
newNum=$((oldNum+1))
# echo '新版本:'$newNum

# echo "替換版本號"
v=0.1.$newNum
version="  s.version          = '$v'"
echo $version
sed -i '' "s/$a/$version/" KKFlutterPod.podspec

# echo "add 并且commit"

# git status
git rm --cached
git add .
git commit -m "修改版本$v"

# echo "添加tag"
git tag -a $v -m "$v"

# echo "連同tag推送到遠程"
git push
git push --tags

自此,差不多應該可以跑起來俯树,run一下試試帘腹,如果遇見build錯誤,請查看一下Xcode的bitcode是否打開了许饿,如果打開請關閉阳欲。

5. 問題

5.1 undefined symbol:OBJC_CLASS$_GeneratedPluginRegistrant
flutter插件編譯錯誤.png

這個問題,是因為導出的包是不支持模擬器的陋率,因為通過flutter開發(fā)環(huán)境導出的包球化,是可以支持模擬器的,所以猜測是我寫的腳本有問題瓦糟,等待后續(xù)優(yōu)化下筒愚,目前是只支持真機。

5.2 有關Framework包的大小

通過flutter build ios-framework --output=導出包路徑菩浙,獲取到debug巢掺、profile、release三種情況下的包劲蜻,其中包含的Flutter.framework的包大小分別是95MB陆淀、66.8MB、369.8MB先嬉,如果用release的包轧苫,推送到遠程pod庫的時候,會超過git的100MB限制疫蔓,可能會失敗,所以我們暫時只用了debug模式下的包,推送到遠程。
當然也有可能是我使用的命令有缺陷,如果有什么可以解決release環(huán)境下叫编,包過大的問題,請務必留言給我,感謝~~~

錯誤待續(xù)。樱哼。哀九。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
  • 序言:七十年代末剿配,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子阅束,更是在濱河造成了極大的恐慌呼胚,老刑警劉巖,帶你破解...
    沈念sama閱讀 212,542評論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件息裸,死亡現場離奇詭異蝇更,居然都是意外死亡,警方通過查閱死者的電腦和手機呼盆,發(fā)現死者居然都...
    沈念sama閱讀 90,596評論 3 385
  • 文/潘曉璐 我一進店門年扩,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人访圃,你說我怎么就攤上這事厨幻。” “怎么了腿时?”我有些...
    開封第一講書人閱讀 158,021評論 0 348
  • 文/不壞的土叔 我叫張陵况脆,是天一觀的道長。 經常有香客問我批糟,道長格了,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,682評論 1 284
  • 正文 為了忘掉前任徽鼎,我火速辦了婚禮盛末,結果婚禮上,老公的妹妹穿的比我還像新娘否淤。我一直安慰自己满败,他們只是感情好,可當我...
    茶點故事閱讀 65,792評論 6 386
  • 文/花漫 我一把揭開白布叹括。 她就那樣靜靜地躺著算墨,像睡著了一般。 火紅的嫁衣襯著肌膚如雪汁雷。 梳的紋絲不亂的頭發(fā)上净嘀,一...
    開封第一講書人閱讀 49,985評論 1 291
  • 那天报咳,我揣著相機與錄音,去河邊找鬼挖藏。 笑死暑刃,一個胖子當著我的面吹牛,可吹牛的內容都是我干的膜眠。 我是一名探鬼主播岩臣,決...
    沈念sama閱讀 39,107評論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼宵膨!你這毒婦竟也來了架谎?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 37,845評論 0 268
  • 序言:老撾萬榮一對情侶失蹤辟躏,失蹤者是張志新(化名)和其女友劉穎谷扣,沒想到半個月后,有當地人在樹林里發(fā)現了一具尸體捎琐,經...
    沈念sama閱讀 44,299評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡会涎,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 36,612評論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現自己被綠了瑞凑。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片末秃。...
    茶點故事閱讀 38,747評論 1 341
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖籽御,靈堂內的尸體忽然破棺而出练慕,到底是詐尸還是另有隱情,我是刑警寧澤篱蝇,帶...
    沈念sama閱讀 34,441評論 4 333
  • 正文 年R本政府宣布贺待,位于F島的核電站,受9級特大地震影響零截,放射性物質發(fā)生泄漏麸塞。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 40,072評論 3 317
  • 文/蒙蒙 一涧衙、第九天 我趴在偏房一處隱蔽的房頂上張望哪工。 院中可真熱鬧,春花似錦弧哎、人聲如沸雁比。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,828評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽偎捎。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間茴她,已是汗流浹背寻拂。 一陣腳步聲響...
    開封第一講書人閱讀 32,069評論 1 267
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留丈牢,地道東北人祭钉。 一個月前我還...
    沈念sama閱讀 46,545評論 2 362
  • 正文 我出身青樓,卻偏偏與公主長得像己沛,于是被迫代替她去往敵國和親慌核。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 43,658評論 2 350

推薦閱讀更多精彩內容