導(dǎo)出命令
iOS
gomobile bind -o ./output/xxx.xcframework -target ios ./dir/a ./dir/b
Android
gomobile bind -o ./output/xxx.aar -target android -androidapi 21 ./dir/a ./dir/b
gomobile如何編譯參考該文章:http://www.itdecent.cn/p/c950e3118ac3
注意事項(xiàng)
- 導(dǎo)出的只能是基本數(shù)據(jù)類型、error、指針、interface
- 數(shù)組不能導(dǎo)出,如[]string
- 字典不能導(dǎo)出,如map[string]string
- []byte 可以導(dǎo)出,但是在部分iOS機(jī)器上執(zhí)行會crash,也不要使用
- 導(dǎo)出的方法不能兩個及以上返回參數(shù),會在gomobile時報錯
functions and methods must return either zero or one values, and optionally an error
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x1023ec5f4]
- 需要導(dǎo)出的方法/實(shí)體首字母大寫,同時打包命令里包含該文件或其所在目錄
- 導(dǎo)出方法不能與默認(rèn)方法名沖突,如 xxx.Wait() 會與 android的wait()沖突。
- 不支持同時集成兩個gomobile編譯的framework,會報錯
duplicate symbol - 針對iOS,當(dāng)函數(shù)有多個參數(shù),需要保證interface和implemention的行參名稱一致,因?yàn)闀唇觨c方法