How to link so library from optee client app with android ndk in Android 9

I developed an Android Native Apk. Firstly, I generated an so file (libmyteeapp.so) as using native library. Then, I installed it to /vendor/lib64 . Because, it uses another library (libteec.so) in /vendor/lib64 .

Secondly, I installed my app as system apk in /system/app . I call libmyteeapp.so in my code like this:

System.loadLibrary(‘myteeapp’);

But, my apk can’t load (libmyteeapp.so) library. And, Error:

java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file “/system/app/MyTeeApp/MyTeeApp.apk”],nativeLibraryDirectories=[/system/app/MyTeeApp/MyTeeApp.apk/lib/arm64, /systemapp/MyTeeApp/MyTeeApp.apk!/lib/arm64-v8a, /system/lib64, /system/lib64]]] couldn’t find “libmyteeapp.so”

In previos Android version, my app worked correctly. Because, libteec.so and libmyteeapp.so are in /system/lib64 folder. So, android app could load libmyteeapp.so and this library can use libteec.so

In Android 9, libteec.so is just in /vendor/lib64 .

I searched some examples in Google. In a lot of examples, nativeLibraryDirectories includes vendor/lib64 folder. But, in my example there is no /vendor/lib64 directory. (please, look at the error)

How can I link to /vendor/lib64 directory from my app or how can Android system show /vendor/lib64 for loading library? selinux policy can block /vendor folder for loading library.

Hello, I follow your guard in Developing Native Android Application with Optee.
In order to solve the link error of libc++.so, I install the apk as system APP, I doing this by following steps:

  1. mount the system partition in rw mode
  2. copy-paste the apk into the location(in my case is the /system/priv-app),
  3. set the appropriate permissions using busybox’s chmod and chgrp or through inbuilt tools:
adb shell su -c chmod 644 APK    # replace APK with your apk's absolute location, such as /system/priv-app/xyz.apk
adb shell su -c chown root:root APK   # replace APK as said above
  1. do a reboot.

During the following boot the Android would detect the apk and install it automatically.
And it does works, but I don’t konw where it is be installed because there has not appear a folder containing the native app as expect. So how did you do this step?

after doing this, the load error change to the libtest.so (the same as you have met). I solved this by manually push the libtest.so and libteec.so to /system/lib64 using adb. May be you can try it.
Although it is solved, I don’t think it is a good solution.
BTW Have you solved this problem? could you share your solution if you have a better one?

Hi tesmnorth

Have you solved this problem? could you share your solution if you have a better one?