text
stringlengths
1
372
if (build.version.sdk_int >= Build.VERSION_CODES.S) {
// disable the android splash screen fade out animation to avoid
// a flicker before the similar frame is drawn in flutter.
splashScreen.setOnExitAnimationListener { splashScreenView -> splashScreenView.remove() }
}
super.onCreate(savedInstanceState)
}
}
<code_end>
then, you can reimplement the first frame in flutter
that shows elements of your android launch screen in
the same positions on screen.
for an example of this, check out the
android splash screen sample app.
<topic_end>
<topic_start>
binding to native android code using dart:ffi
flutter mobile and desktop apps can use the
dart:ffi library to call native c APIs.
FFI stands for foreign function interface.
other terms for similar functionality include
native interface and language bindings.
info note
this page describes using the dart:ffi library
in android apps. for information on iOS, see
binding to native iOS code using dart:ffi.
for information in macOS, see
binding to native macOS code using dart:ffi.
this feature is not yet supported for web plugins.
before your library or program can use the FFI library
to bind to native code, you must ensure that the
native code is loaded and its symbols are visible to dart.
this page focuses on compiling, packaging,
and loading android native code within a flutter plugin or app.
this tutorial demonstrates how to bundle C/C++
sources in a flutter plugin and bind to them using
the dart FFI library on both android and iOS.
in this walkthrough, you’ll create a c function
that implements 32-bit addition and then
exposes it through a dart plugin named “native_add”.
<topic_end>
<topic_start>
dynamic vs static linking
a native library can be linked into an app either
dynamically or statically. a statically linked library
is embedded into the app’s executable image,
and is loaded when the app starts.
symbols from a statically linked library can be
loaded using DynamicLibrary.executable or
DynamicLibrary.process.
a dynamically linked library, by contrast, is distributed
in a separate file or folder within the app,
and loaded on-demand. on android, a dynamically
linked library is distributed as a set of .so (elf)
files, one for each architecture.
a dynamically linked library can be loaded into
dart via DynamicLibrary.open.
API documentation is available from the dart dev channel:
dart API reference documentation.
on android, only dynamic libraries are supported
(because the main executable is the JVM,
which we don’t link to statically).
<topic_end>
<topic_start>
create an FFI plugin
to create an FFI plugin called “native_add”,
do the following:
info note
you can exclude platforms from --platforms that you don’t want
to build to. however, you need to include the platform of
the device you are testing on.
this will create a plugin with C/C++ sources in native_add/src.
these sources are built by the native build files in the various
os build folders.
the FFI library can only bind against c symbols,
so in c++ these symbols are marked extern "c".
you should also add attributes to indicate that the
symbols are referenced from dart,
to prevent the linker from discarding the symbols
during link-time optimization.
__attribute__((visibility("default"))) __attribute__((used)).
on android, the native_add/android/build.gradle links the code.
the native code is invoked from dart in lib/native_add_bindings_generated.dart.
the bindings are generated with package:ffigen.
<topic_end>
<topic_start>
other use cases
<topic_end>
<topic_start>
platform library
to link against a platform library,
use the following instructions:
load the library using DynamicLibrary.open.
for example, to load OpenGL ES (v3):
you might need to update the android manifest
file of the app or plugin if indicated by
the documentation.
<topic_end>
<topic_start>
first-party library