76 lines
2.0 KiB
Markdown
76 lines
2.0 KiB
Markdown
# flutter plugin
|
||
|
||
创建插件命令
|
||
|
||
```shell
|
||
flutter create --template=plugin --platforms=windows,android yourname
|
||
```
|
||
|
||
--platforms 可以指定支持哪些平台,如 windows,macos,ios,android,linux
|
||
|
||
如果没有创建相应平台目录,可以使用下面的命令开启相应的平台
|
||
|
||
```bash
|
||
flutter config --enable-linux-desktop # 开启linux 桌面
|
||
flutter config --enable-macos-desktop # 开启macos 桌面
|
||
flutter config --enable-ios # 开启ios
|
||
# 更多的命令可以通过help查看
|
||
flutter config --help
|
||
```
|
||
|
||
## Android安卓
|
||
|
||
1. gradle文件配置
|
||
|
||
```gradle
|
||
defaultConfig {
|
||
minSdkVersion 19
|
||
ndk {
|
||
// 只编译arm64
|
||
abiFilters "arm64-v8a"
|
||
}
|
||
|
||
externalNativeBuild {
|
||
// 依赖的自定义cmake路径
|
||
cmake {
|
||
arguments "-DANDROID_ARM_NEON=TRUE", "-DANDROID_STL=c++_shared"
|
||
path "../src/CMakeLists.txt"
|
||
}
|
||
}
|
||
consumerProguardFiles "consumer-rules.pro"
|
||
}
|
||
// 一部分动态库需要安装时一并打包,避免出现找不到依赖的动态库
|
||
sourceSets {
|
||
main {
|
||
// 指定动态库路径 安卓的需要的动态库我放到了../src/bin/arm64-v8a, 在指定时只需要到bin即可,但是一定得放到arm64-v8a里面
|
||
jniLibs.srcDirs = ['../src/bin/']
|
||
}
|
||
}
|
||
```
|
||
|
||
2. cmake 文件
|
||
|
||
```cmake
|
||
# 安卓使用
|
||
cmake_minimum_required(VERSION 3.18)
|
||
|
||
set(PROJECT_NAME "pass_track")
|
||
project(${PROJECT_NAME}) # CXX
|
||
# 包含头文件搜索目录和库的搜索目录
|
||
# 指定所有需要编译的头文件和源文件${all_sources} ${all_headers}
|
||
add_library(${PROJECT_NAME} SHARED
|
||
${all_sources}
|
||
${all_headers}
|
||
)
|
||
|
||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||
CXX_VISIBILITY_PRESET hidden)
|
||
|
||
target_compile_definitions(${PROJECT_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
|
||
target_link_libraries(${PROJECT_NAME} PRIVATE 。。。)
|
||
|
||
|
||
|
||
```
|
||
|
||
|