CodeAsset class - code_assets library (original) (raw)
An asset containing executable code which respects the native application binary interface (ABI).
Typical languages which produce code assets that respect the native ABI include C, C++ (with extern "C"), Rust (with extern "C"), and a subset of language features of Objective-C.
Native code assets can be accessed at runtime through native external functions via their asset id:
import 'dart:ffi';
void main() {
final result = add(14, 28);
print(result);
}
@Native<Int Function(Int, Int)>(assetId: 'package:my_package/add.dart')
external int add(int a, int b);
There are several types of native code assets:
- Assets which designate symbols present in the target system (DynamicLoadingSystem), process (LookupInProcess), or executable (LookupInExecutable). These assets do not have a file.
- Dynamic libraries bundled into the application (DynamicLoadingBundled). These assets must provide a file to be bundled.
An application is compiled to run on a specific target CodeConfig.targetOSand CodeConfig.targetArchitecture. Different targets require different assets, so the package developer must specify which asset to bundle for which target.
An asset has different ways of being accessible in the final application. It is either brought in "manually" by having the package developer specify afile path of the asset on the current system, it can be part of the Dart or Flutter SDK (LookupInProcess), or it can be already present in the target system (DynamicLoadingSystem). If the asset is bundled "manually", the Dart or Flutter SDK will take care of copying the asset file from its specified location on the current system into the application bundle.
Properties
The native library to be bundled with the Dart or Flutter application.
final
The hash code for this object.
no setteroverride
The id of this code asset.
final
The link mode for this native code.
final
A representation of the runtime type of the object.
no setterinherited