hhstore / blog

My Tech Blog: about Mojo / Rust / Golang / Python / Kotlin / Flutter / VueJS / Blockchain etc.
https://github.com/hhstore/blog/issues
278 stars 22 forks source link

Flutter Plugin/Package: publish a package + reuse native libs #245

Open hhstore opened 3 years ago

hhstore commented 3 years ago

related:

hhstore commented 3 years ago

flutter 开发+发布一个库/插件:

二者区别:

1. 创建包目录:

1.1 package:

创建指令:


 flutter create --template=package hello

1.2 plugin:

创建指令:


# Android: 
flutter create --org com.example --template=plugin --platforms=android,ios -a kotlin hello
flutter create --org com.example --template=plugin --platforms=android,ios -a java hello

# iOS: 
flutter create --org com.example --template=plugin --platforms=android,ios -i objc hello
flutter create --org com.example --template=plugin --platforms=android,ios -i swift hello

flutter create --template=plugin --platforms=web .

2. 发布包:

# 测试:
flutter pub publish --dry-run

# 发布:
flutter pub publish

3. 原生依赖处理:

hhstore commented 3 years ago

flutter platform channels: 编写平台相关代码

数据类型 - 映射表:

image

MethodChannel:

Pigeon:

测试:

hhstore commented 3 years ago

flutter plugin:

参考示例 1:

参考示例 2:

示例3:

查找动态库:

Android 依赖包:

特别说明:

  1. 需要主动在 Android 包平台, 主动发包:

package eu.simonbinder.sqlite3_flutter_libs;
  1. 需要主动在 iOS/macos 包平台主动发包:
hhstore commented 1 year ago

1

hhstore commented 1 year ago

android aar 包平台:

ios/macos 包平台:

hhstore commented 1 year ago

iOS + ffi:

示例配置:

MacOS + ffi:

image

Android + ffi:

Windows + ffi :

示例:

hhstore commented 1 year ago

Mono Repo for Dart:

工具:

mono repo:

# 激活工具: 
dart pub global activate melos

注意事项:


function set.proxy.flutter.cn(){
    # mirror: https://mirrors.tuna.tsinghua.edu.cn/help/flutter/
    # 社区:
    export PUB_HOSTED_URL=https://pub.flutter-io.cn
    export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

    # 清华大学:
    #export FLUTTER_STORAGE_BASE_URL="https://mirrors.tuna.tsinghua.edu.cn/flutter"
    #export PUB_HOSTED_URL="https://mirrors.tuna.tsinghua.edu.cn/dart-pub"

}

# defalut use cn mirror:
set.proxy.flutter.cn

# unset:
function unset.proxy.flutter() {
    unset PUB_HOSTED_URL
    unset FLUTTER_STORAGE_BASE_URL
    export PUB_HOSTED_URL=""
    export FLUTTER_STORAGE_BASE_URL=""
    echo "unset flutter proxy"
}