Reputation: 179
I wrote a demo of NNAPI. But The app crashes with the error "java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol 'ANeuralNetworksModel_identifyInputsAndOutputs'". After I removed the line contains ANeuralNetworksModel_identifyInputsAndOutputs(and remains other lines about NNAPI, such as ANeuralNetworksModel_addOperation and so on), the app doesn't crash anymore.
My minSdkVersion, compileSdkVersion, targetSdkVersion are all 27.
Is it a bug, or just my fault? Could you please help me? Thanks in advance.
Thanks to the excellent solution following, I have written an NNAPI wrapper Library and demo, and published it on GitHub, only four lines are needed to deploy a model on phone. I hope my project would help developers who interested in NNAPI
Upvotes: 0
Views: 515
Reputation: 1
This issue is happening because the SDK package is not correct. Update the SDK package to the latest one. If SDK manager is not showing any updates, then in Android Studio, from the File Menu, Chose the option Invalidate Caches and Restart. Once this is done, Android studio will ask if any pending SDK updates are there. Once the updates are installed, then recreate the new Virtual Device with AVD manager(if you are using Virtual Device). And your program is ready to go...
SDK\system-images\android-27\google_apis\x86\source.properties
Pkg.Desc=System Image x86 with Google APIs.
****Pkg.Revision=2****
Pkg.Dependencies=emulator#26.1.3
****AndroidVersion.ApiLevel=27****
SystemImage.Abi=x86
SystemImage.TagId=google_apis
SystemImage.TagDisplay=Google APIs
SystemImage.GpuSupport=true
Addon.VendorId=google
Addon.VendorDisplay=Google Inc.
Upvotes: 0
Reputation: 10509
Unfortunately there was a change to the NN API that was requested just before the NDK launch that didn't make it into O MR 1 Beta 1 in time. In other words, the NDK is more up to date than the beta image. This will resolve itself when the next O beta (or the release? I'm not actually sure what the timeline is) launches.
In the meantime, the name of that function in the beta is ANeuralNetworksModel_setInputsAndOutputs
. Something like the following should work, and will let you know when you can remove the workaround (note: I haven't tested this because I don't have a device running the beta, so it may require some minor modifications).
// TODO: Remove when O MR1 Beta 2 is available.
__attribute__((weak))
extern "C" int ANeuralNetworksModel_setInputsAndOutputs(
uint32_t inputCount, const uint32_t* inputs, uint32_t outputCount,
const uint32_t* outputs);
extern "C" int ANeuralNetworksModel_identifyInputsAndOutputs(
uint32_t inputCount, const uint32_t* inputs, uint32_t outputCount,
const uint32_t* outputs) {
if (ANeuralNetworksModel_setInputsAndOutputs == nullptr) {
__android_log_print(ANDROID_LOG_ERROR,
"ANeuralNetworkdModel_setInputsAndOutputs not found. Remove workarounds.");
abort();
}
return ANeuralNetworksModel_setInputsAndOutputs(
inputCount, inputs, outputCount, outputs);
}
Upvotes: 3