MATLAB Answers

Android Studio + MATLAB: Failed to find the required library on java.library.path

27 views (last 30 days)
Qian Xu
Qian Xu on 23 Apr 2020
Answered: Sutanu Maiti on 22 May 2020
I am developing an Android app and try to use some MATLAB libraries. I have built a .jar file called myAdd.jar from my MATLAB code and have copied it and javabuilder.jar to Project->MyApplication->app->libs. Now the class called matlabAdd, which is originally defined in myAdd.jar, already can be used in my Android main function. However, there is still a problem:
When I run my Android code, I got this error which bothers me a few days:
Process: com.example.myapplication, PID: 11568
java.lang.UnsatisfiedLinkError: Failed to find the required library on java.library.path.
This library is typically installed along with MATLAB or the MATLAB Runtime. Its absence may indicate an issue with that installation or
the current path configuration, or a mismatch with the architecture of the Java interpreter on the path.
MATLAB Runtime version this component is attempting to use: 9.7.
Java interpreter architecture: glnxa64.
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$ProxyLibraryDir.get(
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$ProxyLibraryDir.<clinit>(
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration.getProxyLibraryDir(
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$MCRRoot.get(
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$MCRRoot.<clinit>(
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration.getMCRRoot(
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration$ModuleDir.<clinit>(
at com.mathworks.toolbox.javabuilder.internal.MCRConfiguration.getModuleDir(
at com.mathworks.toolbox.javabuilder.internal.MWMCR.<clinit>(
at com.mathworks.toolbox.javabuilder.internal.MWMCR.newInstance(
at myAdd.MyAddMCRFactory.newInstance(
at myAdd.MyAddMCRFactory.newInstance(
at myAdd.matlabAdd.<init>(
at com.example.myapplication.MainActivity.onCreate(
at android.os.Handler.dispatchMessage(
at android.os.Looper.loop(
at java.lang.reflect.Method.invoke(Native Method)
So does anyone know how to fix this problem?
My operation system is Windows10, but this seems like a dynamic link library which works on Linux. And I cannot find this file in my MATLAB installation directory.
If Android Studio and MATLAB cannot work together directly, is there other indirect way for me to call MATLAB funcitons in my Android code?

Answers (1)

Sutanu Maiti
Sutanu Maiti on 22 May 2020
If you can move to Simulink then, Simulink support package for Android Devices can be used to deploy matlab code directly to android phone without doing any java / android coding.
There is also an example Detect Boundaries of Objects Within Video Using MATLAB Function Block on Android Device that describes how to write matlab code that generates code and deploys on Android device.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!