Workaround permission issue when loading NNAPI model from asset file. (#804)

This commit is contained in:
Kottsone
2021-07-07 13:54:27 -07:00
committed by GitHub
parent fa2ac546af
commit 8a6c06f891
3 changed files with 60 additions and 29 deletions

View File

@@ -44,15 +44,8 @@ Java_com_example_android_basic_MainActivity_initModel(
return 0;
}
env->ReleaseStringUTFChars(_assetName, assetName);
off_t offset, length;
int fd = AAsset_openFileDescriptor(asset, &offset, &length);
SimpleModel* nn_model = new SimpleModel(asset);
AAsset_close(asset);
if (fd < 0) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG,
"Failed to open the model_data file descriptor.");
return 0;
}
SimpleModel* nn_model = new SimpleModel(length, PROT_READ, fd, offset);
if (!nn_model->CreateCompiledModel()) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG,
"Failed to prepare the model.");