Committed by
GitHub
Add hint for loading model files from SD card on Android. (#2564)
This PR adds a helpful hint for Android developers who are trying to load model files from the SD card instead of the app's assets. The change detects when an absolute path is provided while an asset manager is still being used, which is a common configuration mistake. - Adds validation to detect absolute paths when using Android asset manager - Provides clear error messages guiding users to set assetManager to null for SD card file access - References the related issue for additional context (#2562)
正在显示
1 个修改的文件
包含
14 行增加
和
0 行删除
| @@ -32,6 +32,20 @@ std::vector<char> ReadFile(const std::string &filename) { | @@ -32,6 +32,20 @@ std::vector<char> ReadFile(const std::string &filename) { | ||
| 32 | 32 | ||
| 33 | #if __ANDROID_API__ >= 9 | 33 | #if __ANDROID_API__ >= 9 |
| 34 | std::vector<char> ReadFile(AAssetManager *mgr, const std::string &filename) { | 34 | std::vector<char> ReadFile(AAssetManager *mgr, const std::string &filename) { |
| 35 | + if (!filename.empty() && filename[0] == '/') { | ||
| 36 | + SHERPA_ONNX_LOGE( | ||
| 37 | + "You are using an absolute path '%s', but assetManager is NOT set to " | ||
| 38 | + "null.", | ||
| 39 | + filename.c_str()); | ||
| 40 | + | ||
| 41 | + SHERPA_ONNX_LOGE( | ||
| 42 | + "Please set assetManager to null when you load model files from the SD " | ||
| 43 | + "card"); | ||
| 44 | + | ||
| 45 | + SHERPA_ONNX_LOGE( | ||
| 46 | + "See also https://github.com/k2-fsa/sherpa-onnx/issues/2562"); | ||
| 47 | + } | ||
| 48 | + | ||
| 35 | AAsset *asset = AAssetManager_open(mgr, filename.c_str(), AASSET_MODE_BUFFER); | 49 | AAsset *asset = AAssetManager_open(mgr, filename.c_str(), AASSET_MODE_BUFFER); |
| 36 | if (!asset) { | 50 | if (!asset) { |
| 37 | __android_log_print(ANDROID_LOG_FATAL, "sherpa-onnx", | 51 | __android_log_print(ANDROID_LOG_FATAL, "sherpa-onnx", |
-
请 注册 或 登录 后发表评论