跳到主要内容

安装

确保 Provider / profile 已装好。对应 darra_runtime_ensure / darra_runtime_ensure_cancel。合法 ID 见 运行时

Windows 无 RKNN

edge-rknn 永远不会出现在 Windows 安装列表。在 Windows 上指名它 → AiException.UnsupportedPlatformException

SDK 自动安装 / 升级系统驱动。

方法

AiRuntime.ensure()

public static void ensure()
public static void ensure(String profileOrProviderId)
public static void ensure(String profileOrProviderId,
String offlineZip,
ProgressListener listener)

确保指定 Provider / profile 已装好;没装就探测 → 选包 → 下载 → sha256 校验 → 解压登记。无参 = ensure(null, null, null),按硬件自动选。

参数:

  • profileOrProviderId (String) — 细包 / 场景包;null = 按硬件探测自动选

  • offlineZip (String) — 离线整合包 zip 路径;给定时跳过 manifest/download,仍过内嵌 sha256 清单校验。null = 在线下载

  • listener (ProgressListener) — 进度回调,可为 null

  • 幂等:已装且清单匹配 → 直接成功(回调收到一次 "done", 100)。

  • 进程内串行:并发调用被内部互斥串行化。

  • 事务性:全部步骤成功才登记;取消或任何失败不留半成品。

典型错误:IoNotFoundException(离线包路径错)/ NetworkFailedException / ChecksumMismatchException / IoDeniedException(目标目录需管理员)/ UnsupportedPlatformException / ProviderAbiMismatchException / CancelledException

示例:

AiRuntime.ensure("cpu-only", null, (percent, stage) ->
System.out.printf("\r[%-8s] %5.1f%%", stage, percent));

相关结构:

@FunctionalInterface
public interface ProgressListener {
void onProgress(float percent, String stage);
}

嵌套在 AiRuntimepercent 0..100,每个 stage 内单调不降。stageprobe / manifest / download / verify / install / done。回调在 SDK 内部工作线程触发:回调里禁止调用任何本 SDK 方法(含 ensureCancel),只准记录或转发到调用方自己的 UI 队列。

AiRuntime.ensureCancel()

public static void ensureCancel()

请求取消当前在飞的 ensure(可从任意线程调,含进度回调外的 UI 线程)。没有在飞的 ensure 时为 no-op。被取消的 ensure 抛 CancelledException进度回调内部禁止调用。

示例:

new Thread(AiRuntime::ensureCancel).start();