Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.margelo.nitro.tflite

import androidx.annotation.Keep
import com.facebook.proguard.annotations.DoNotStrip
import com.margelo.nitro.NitroModules
import com.margelo.nitro.core.ArrayBuffer
import com.margelo.nitro.core.Promise
import java.net.URL
Expand All @@ -11,7 +12,21 @@ import java.net.URL
class HybridAssetLoader : HybridAssetLoaderSpec() {
override fun loadAsset(path: String): Promise<ArrayBuffer> {
return Promise.async {
val bytes = URL(path).readBytes()
val bytes = if (path.startsWith("http://") ||
path.startsWith("https://") ||
path.startsWith("file://")) {
URL(path).readBytes()
} else {
// In release builds, RN's AssetSourceResolver returns a bare Android
// resource identifier (e.g. "app_assets_yolo_nas_pose_n_320_gpu_fp16")
// for non-drawable extensions packaged into res/raw. java.net.URL cannot
// read these — resolve via the app Context / Resources instead.
val ctx = NitroModules.applicationContext
?: throw IllegalStateException("No ReactApplicationContext available to resolve asset: $path")
val resId = ctx.resources.getIdentifier(path, "raw", ctx.packageName)
if (resId == 0) throw IllegalArgumentException("Asset not found in res/raw: $path")
ctx.resources.openRawResource(resId).use { it.readBytes() }
}
return@async ArrayBuffer.copy(bytes)
}
}
Expand Down
Loading