0

I wrote a System Service, but it fails on boot with the message:

java.lang.UnsatisfiedLinkError: dlopen failed: library "libgojni.so" not found

Basically in the code of the .aar library it tries to load a library using System.loadLibrary() but it fails, even though it is in the aar file. It even works when I try to do it in an android app, but it fails on android.

It may be also worth mentioning that I created the .aar library using gomobile to bind a go-project into an .aar library.

Markusbug
  • 31
  • 6

1 Answers1

1

AFAIK path to load native libraries differs for system and user applications. I think the idea behind it is that system libraries are common for all Android framework and system apps, so the libs can be reused, and each dependent app doesn't need to carry its own copy, probably of different version.

The libraries for system apps are stored in system image.

You may want to look at this tutorial how to add system apps with native code to AOSP build: https://devarea.com/aosp-creating-a-system-application.

The question probably duplicates System.loadLibrary(...) couldn't find native library in my case

Mixaz
  • 4,068
  • 1
  • 29
  • 55
  • The thing is, the jni is inside of the aar file. And it works perfectly fine when I add it to an android app with gradle. I added the aar with: android_library_import. And when I look into the directory where it is unpacked, there is a jni dir with the .so files for all architectures. – Markusbug Jan 03 '22 at 12:56
  • 1
    and what? As I said, the jni dir and .so files there are not added to the path of loaded libraries for a system app/service. It is added only for user apps. This is how AOSP works, and I explained why. If you look at AOSP apps with native code, you won't find the .so files inside aars or apks, but find them inside system libs folders – Mixaz Jan 05 '22 at 00:47