website/docs/manual/integrate/07-library/03-platform-setup/index.md
import V1Notice from '@site/docs/snippets/_v1-notice.mdx';
Unfortunately, at the time of writing, pub.dev has a hard 100 MB upload limit and discourages distributing platform-specific binaries through pub.dev directly. In the future, hopefully with Native Assets, there will be a way to distribute our Rust binaries through pub.dev, or something similar, which will make distribution as a library author much more convenient.
In the meantime, however, we will need to work around these limitations. There are many ways to distribute the binaries ourselves, outside of pub.dev, but in this subsection, we will cover using GitHub releases because it easily integrates with our CI/CD solution, GitHub Actions (more on this later).
If you look in your Flutter wrapper's pubspec (/packages/flutter_library_name/pubspec.yaml),
you should notice the following section near the bottom
(if you don't see this, or it is incomplete, add it now!):
flutter:
plugin:
platforms:
ios:
ffiPlugin: true
macos:
ffiPlugin: true
android:
ffiPlugin: true
linux:
ffiPlugin: true
windows:
ffiPlugin: true
This section of the pubspec tells Flutter that our package is using the newer ffi plugins format instead of the older platform channels Flutter has. This makes the work on our end much simpler, because instead of having to specify platform channels for each platform supported, we now only have to bundle the binaries with our package.
But, the key here is that we still must bundle our binaries along with our package. To do so, we have to follow a certain procedure (read this; it is important):
/scripts/build-*.sh) that build all of our
platform specific binaries into /platform-build and package them up appropriately,
based on the target platform.
Example: on iOS/macOS, this bundle is an XCFramework, on Windows/Linux, it is a .tar.gz.Here are the relevant directories per platform.
This is helpful for if you want to test your library on a real device or emulator locally.
Also note: replace library_name below with your library name, and replace library_tag below with
library_name-vVERSION where VERSION is the current version in your Dart-only pubspec.yaml.
This setup is a bit of a pain to test locally with but I am not sure there is a better way at the moment
(other than creating a melos script to copy over all the binaries for you).
The idea here is that you will do most of your integration tests in CI.
/platform-build to these locations to test locally)
/plaform-build/LibraryName.xcframework.zip): /packages/flutter_library_name/ios/Frameworks/library_tag.zip/platform-build/LibraryName.xcframework.zip): /packages/flutter_library_name/macos/Frameworks/library_tag.zip/platform-build/android.tar.gz): /packages/flutter_library_name/android/library_tag.tar.gz/platform-build/other.tar.gz): /packages/flutter_library_name/windows/library_tag.tar.gz/platform-build/other.tar.gz): /packages/flutter_library_name/linux/library_tag.tar.gz/packages/flutter_library_name/ios/Frameworks//packages/flutter_library_name/macos/Frameworks//packages/flutter_library_name/android/src/main/jniLibs/
aar is, Flutter does something similar for android plug-ins under the hood/packages/flutter_library_name/windows//packages/flutter_library_name/linux/Always use melos to build the latest version(s) of the binaries (e.g. melos run build:android)
before copying the binary archives from /platform-build/ and testing locally!
Also, do not check the /platform-build/ or /target/ directories into source control!