Skip to content

Dart

Add the package from pub.dev. It needs Dart 3.11 or later.

Terminal window
dart pub add maplibre_native_ffi

When it builds, the package downloads the C library for your target.

The package uses your platform’s default backend. To choose another, map an operating system to a backend in your app’s pubspec:

pubspec.yaml
hooks:
user_defines:
maplibre_native_ffi:
backend:
android: vulkan

The operating systems are android, ios, linux, macos, and windows. The backends are opengl, metal, and vulkan.

Initialize the library once per process, before you create a runtime, with the calling thread’s JNI environment and an Android Context:

lib/main.dart
initAndroid(NativePointer(jniEnv), NativePointer(context));

Get the JNI environment from package:jni, and the application context from package:jni_flutter.

To link a C library that you built or downloaded, name it in local_build. Name an install prefix, or a directory with prefixes one level down, such as a CMake build root. A relative path is relative to the pubspec. A Git dependency on the package always needs one.

pubspec.yaml
hooks:
user_defines:
maplibre_native_ffi:
local_build: ../maplibre-native-ffi/build

If your builds can’t reach GitHub, copy the release’s archives to a server of your own, in a directory named after the release tag, and name the server’s base URL in release_url. The package still checks each archive against the digest that it pinned at release.

pubspec.yaml
hooks:
user_defines:
maplibre_native_ffi:
release_url: https://mirror.example.com/maplibre-native-ffi