android N load library fail

4,543 views
Skip to first unread message

李小峰

unread,
Jun 2, 2017, 12:37:43 PM6/2/17
to android-ndk
load library failed log like these:
needed or dlopened by "/system/lib/libnativeloader.so" is not accessible for the namespace: [name="classloader-namespace", ld_library_paths="", default_library_paths="", permitted_paths="/data:/mnt/expand"]

why "default_library_paths" is empty? is normal?

these case happened when user update android m to android n, and app load library fail always.

someone help me? 

Alex Cohn

unread,
Jun 5, 2017, 6:08:28 AM6/5/17
to android-ndk
This is kind of documented, see https://developer.android.com/about/versions/nougat/android-7.0-changes.html#ndk. You cannot dlopen system libraries anymore, only the officially white-listed subset.

BR,
Alex Cohn

Martin

unread,
Oct 3, 2017, 11:17:41 AM10/3/17
to android-ndk
Hi Alex, If you cannot put your generated libs in system anymore, where can I put them? I assume this affects >23.

Alex Cohn

unread,
Oct 8, 2017, 5:21:43 AM10/8/17
to android-ndk
Hi Alex, If you cannot put your generated libs in system anymore, where can I put them? I assume this affects >23.
This is a very good question. Let me rephrase it to make it unambiguous:

You build your custom ROM or modify an existing system, and before Nogut, you installed some custom shared libs in `system/lib`, so that non-system apps could load them. Since API 24, this does not work, such apps cannot load these libraries. What can be done?

You should declare the library as 'public', see https://source.android.com/devices/tech/config/namespaces_libraries#adding-additional-native-libraries. Note that Google encourages you to put such libraries under the /vendor library folder (/vendor/lib for 32 bit libraries and, /vendor/lib64 for 64 bit).

BR,
Alex Cohn

Martin

unread,
Oct 9, 2017, 7:54:23 AM10/9/17
to android-ndk
But what if I have a system app, can I still not access libs in /system ?
My current solution is to manually move the jni lib to /data/data/myApp, and define the path in the System.load(). I guess you have to do the same if you place the lib in /vendor? Or can you automatically generate it in /vendor when building the app?
And I don't really understand how to declare it as 'public'. Do you just make a text file named 'public.libraries.txt', and then list your lib in the text file, ex: libmyLib.so, and then manually place the libs in /vendor/lib

Alex Cohn

unread,
Oct 9, 2017, 1:57:23 PM10/9/17
to android-ndk
My answers inlined.

Alex


On Monday, October 9, 2017 at 11:54:23 AM UTC, Martin wrote:
But what if I have a system app, can I still not access libs in /system ?
No, even system app cannot access these libs.
 
My current solution is to manually move the jni lib to /data/data/myApp, and define the path in the System.load(). I guess you have to do the same if you place the lib in /vendor? Or can you automatically generate it in /vendor when building the app?
You probably can add some easy shell script to do it for you.

And I don't really understand how to declare it as 'public'. Do you just make a text file named 'public.libraries.txt', and then list your lib in the text file, ex: libmyLib.so, and then manually place the libs in /vendor/lib
You can find a sample file in AOSP. Actually, if you prefer to keep your libs under /system, then you can simply edit this list which goes into /etc.

J Decker

unread,
Oct 10, 2017, 6:07:14 AM10/10/17
to andro...@googlegroups.com
In general, I don't know why you're so dead-set on making it a 'system' library.
The only library I ran into that was truly a shared library install was OpenCV  (which is pretty complex to interface with)

But this seems to make it look pretty esy to share a library in another project, without requiring it gets installed into a system space or requiring a rooted device....




--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/e0aac152-574c-43ff-ad30-b340e51f7390%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Martin

unread,
Oct 10, 2017, 7:44:41 AM10/10/17
to android-ndk
Well, the only thing I actually want to do is to be able to access a generated jni lib from my system app, and it is very badly documented on how you do that on api >23. I had to manually move the lib, and have to do it everytime I build, which is not so pleasant. I just want everything to happen automatically, just as it was on api <24.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.

To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.

Alex Cohn

unread,
Oct 10, 2017, 10:20:53 AM10/10/17
to android-ndk
You can build your app separately and then add a prebuilt app to AOSP. Looks much easier to me.

Alex

Martin

unread,
Oct 10, 2017, 10:28:03 AM10/10/17
to android-ndk
The problem is that I need to push the lib to the target everytime I build, which I do very often since I am still developing the app and need to debug. And I do not rely on Android Studio, so it is pure .mk on the AOSP.

Philippe Simons

unread,
Oct 10, 2017, 10:30:32 AM10/10/17
to android-ndk
Why can't you just bundle your native libs in the apk then ?

To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.

To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.

Alex Cohn

unread,
Oct 10, 2017, 12:09:40 PM10/10/17
to android-ndk
Martin,

Do you push only the libs, or Java changes too? In any case, do you flash the full ROM image on every iteration? It could be an unjustified overhead. You could  push only the libs and the apk. And while debugging, it's not a big deal to push a modified /etc/public.libraries.txt file.

Alex

Martin

unread,
Oct 10, 2017, 12:39:26 PM10/10/17
to android-ndk
I am just pushing my lib to /data. Because when I build the app, the lib still goes to /system (on the pc), so I have to push the lib to /data (on the target). The Java changes gets pushed whenever I install the apk. I do not flash the target, only building the app (with make command), which generates an apk which I then install on the target.

Martin

unread,
Oct 10, 2017, 12:44:41 PM10/10/17
to android-ndk
I am using Android.mk to build the app, and I haven't seen any mk code that would automatically bundle the libs in the apk. I have tried to manually put the lib in a directory in the app before building the app, but it still cannot open the lib because it is still located in /system. (The app is a system app). And bundling the lib in the apk after building won't do any good. The lib will still be in /system together with the app, and I would have to do this everytime I debug, which I mentioned earlier.

Dan Albert

unread,
Oct 10, 2017, 1:37:38 PM10/10/17
to android-ndk
There's a LOCAL_JNI_SHARED_LIBRARIES or similar that bundles shared libs into your APK. That may not be the exact name, but grep should get you there.

To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.

To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.

Alex Cohn

unread,
Oct 10, 2017, 1:54:43 PM10/10/17
to android-ndk
Here I lost you.

Why don't you push the updated lib to /system? Does your code load the libraries explicitly from non-standard path?

I don't have experience with the new Soong process, but for the old Android.mk build system you could force the libraries packed into APK. The problem was that system apps didn't look for their native libs there: https://groups.google.com/d/msg/android-building/wf6pa0Mnx0s/1LgcYHSssLEJ.

BR,
Alex

Alex Cohn

unread,
Oct 10, 2017, 1:55:37 PM10/10/17
to android-ndk
Some while ago, system apps could not use bundled native libraries, see https://groups.google.com/d/msg/android-building/wf6pa0Mnx0s/1LgcYHSssLEJ.

Martin

unread,
Oct 10, 2017, 1:56:45 PM10/10/17
to android-ndk
I am using this line, and it does not bundle the lib into apk.

Dan Albert

unread,
Oct 10, 2017, 2:15:21 PM10/10/17
to android-ndk, Dan Willemsen
+dwillemsen

To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.

To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
Reply all
Reply to author
Forward
0 new messages