PrebuiltCodeAssetBuilder class final

A declarative Builder that resolves prebuilt native libraries from GitHub Releases.

This is the primary public API for consuming packages. It implements the full resolution chain:

  1. User-defined override via hooks.user_defines
  2. Local .prebuilt/ directory
  3. Shared cache (download from release)
  4. Source fallback (local/git/archive → prepare → build)

Example usage in hook/build.dart:

import 'package:hooks/hooks.dart';
import 'package:native_prebuilt/hooks.dart';
import 'package:my_package/src/hook/prebuilts.g.dart';

void main(List<String> args) async {
  await build(args, (input, output) async {
    await PrebuiltCodeAssetBuilder(
      assetName: 'my_bindings_generated.dart',
      libraryStem: 'my_native_lib',
      manifest: myPrebuilts,
      linkModeResolver: (code) => DynamicLoadingBundled(),
      sourceFallback: SourceFallback(
        sources: [LocalSource(paths: ['.'])],
        builder: CallbackSourceBuilder(
          callback: ({
            required source,
            required input,
            required output,
            required logger,
          }) async {
            // build from source.directory
          },
        ),
      ),
    ).run(input: input, output: output, logger: null);
  });
}

For new packages, consider using NativeProjectBuilder directly with a NativeProject definition for a more declarative approach.

Constructors

PrebuiltCodeAssetBuilder({required String assetName, required String libraryStem, required PrebuiltManifest manifest, required LinkMode linkModeResolver(CodeConfig code), SourceFallback? sourceFallback, String localDirectoryName = '.prebuilt', List<PrebuiltResolver>? resolvers})
const

Properties

assetName → String
The asset name passed to CodeAsset.
final
hashCode → int
The hash code for this object.
no setterinherited
libraryStem → String
The library stem without platform prefix or extension.
final
linkModeResolver → LinkMode Function(CodeConfig code)
Returns the LinkMode to use for the current build configuration.
final
localDirectoryName → String
Directory name for local prebuilt overrides.
final
manifest → PrebuiltManifest
The prebuilt manifest containing release and artifact metadata.
final
resolvers → List<PrebuiltResolver>?
Custom resolver chain. If null, uses the default chain: UserDefinePrebuiltResolver, LocalPrebuiltResolver, SharedCacheResolver.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
sourceFallback → SourceFallback?
Optional source-based fallback when no prebuilt is available.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
run({required BuildInput input, required BuildOutputBuilder output, required Logger? logger}) → Future<void>
Runs this build.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited