TensorFlowSharp Unity "'TensorflowSharp' does not exist in the current context" issue
See original GitHub issueHi there,
I am tying to build an object detection app using Unity with TensorFlowSharp. The app works when I run it in Unity but I can’t get it to work on my android device. One thing to note is that in one of the scripts there are the following lines:
#if UNITY_ANDROID TensorFlowSharp.Android.NativeBinding.Init(); #endif
but I have to comment these out or else I get an error in both Unity and VS saying:
error CS0103: The name `TensorFlowSharp’ does not exist in the current context.
I tried to build the project by commenting these lines out, copied the APK onto my device and while it runs, it doesn’t detect any objects. It just starts the camera and then that’s it. I read that the above lines of code need to be there in order for this to work on android.
I am completely new to using TensorFlow and TensorFlowSharp in Unity, therefore please let me know if I missed out anything. 😃
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
After searching about this issue, I have found that the project has a missing part on this conditional:
The only thing that I had added was this:
I hope this help you! 😄 BTW: this is the link of the answer : https://stackoverflow.com/questions/46245530/why-is-platform-dependent-compilation-not-working
OK so I managed to fix this issue. I downloaded an older version of the plugin (v0.3) from here: https://github.com/Syn-McJ/TFClassify-Unity
After exporting it I got another error and the project wouldn’t compile. This is the problem that I was facing: https://github.com/Unity-Technologies/ml-agents/issues/979. Basically I couldn’t run the project in the Editor anymore.
The fix was to check the “Editor” option on the TensorFlowSharp.Android import settings when building. In order to run it in the Editor I had to comment out
#if UNITY_ANDROID TensorFlowSharp.Android.NativeBinding.Init(); #endif
line and uncheck the “Editor” option under “Include Platforms section” of the TensorFlowSharp.Android import settings.