JNI with Android O, cannot open the jni lib which is placed in /system/lib64

1,295 views
Skip to first unread message

Martin

unread,
Oct 3, 2017, 11:17:41 AM10/3/17
to android-ndk
I am running Android O on my AOSP, with Android.mk environment. I have added the C++ part and Java part correctly so that Android Native JNI should work properly. The problem is that it cannot open the generated jni lib, which is placed in /system/lib64. It is finding it but I get dlopen failed:
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"]

I have seen this problem in this group before, but the answer was that you cannot open system libs anymore in android >23. Source: https://developer.android.com/about/versions/nougat/android-7.0-changes.html#ndk

Then my question is: Where should I put this lib then, and would that solve the problem? Or are there any other solutions to this?
Thanks!

J Decker

unread,
Oct 3, 2017, 1:04:45 PM10/3/17
to andro...@googlegroups.com

--
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/0cdc11fe-de8a-4667-bb96-eab2121d3ecd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Martin

unread,
Oct 3, 2017, 1:52:59 PM10/3/17
to android-ndk
No this does not work. I am working in an AOSP environment with Android.mk, so no gradle nor cmake. The lib is not generated inside the apk. When doing System.loadLibrary() it tries to open the lib in system/lib64 on the target, but it cannot.


Den tisdag 3 oktober 2017 kl. 13:04:45 UTC-4 skrev J Decker:
On Tue, Oct 3, 2017 at 5:16 AM, Martin <mart...@live.com> wrote:
I am running Android O on my AOSP, with Android.mk environment. I have added the C++ part and Java part correctly so that Android Native JNI should work properly. The problem is that it cannot open the generated jni lib, which is placed in /system/lib64. It is finding it but I get dlopen failed:
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"]

I have seen this problem in this group before, but the answer was that you cannot open system libs anymore in android >23. Source: https://developer.android.com/about/versions/nougat/android-7.0-changes.html#ndk

Then my question is: Where should I put this lib then, and would that solve the problem? Or are there any other solutions to this?
Thanks!

--
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...@googlegroups.com.

J Decker

unread,
Oct 3, 2017, 2:19:56 PM10/3/17
to andro...@googlegroups.com
https://stackoverflow.com/questions/35300779/include-prebuilt-shared-library-in-android-aosp
https://developer.android.com/ndk/guides/prebuilts.html#dm

the target path should still be 'lib/<arch>/'
The library must start with 'lib' and must end with '.so' 



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.

Dan Albert

unread,
Oct 3, 2017, 2:33:14 PM10/3/17
to android-ndk
Apps can't load system libraries. This includes system apps.

Martin

unread,
Oct 3, 2017, 2:38:59 PM10/3/17
to android-ndk
Is there a workaround for this? I mean if you cannot load the system libs, how else would you be able to use jni ndk?

--
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...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.

Martin

unread,
Oct 3, 2017, 2:38:59 PM10/3/17
to android-ndk
Yes the generated jni lib starts with 'lib' and ends with '.so'. So you mean that the extra arch directory will give me access to open the system lib, because that is what the problem is.

Dan Albert

unread,
Oct 3, 2017, 2:40:43 PM10/3/17
to android-ndk
Is there a workaround for this? I mean if you cannot load the system libs, how else would you be able to use jni ndk?

System *only* libraries, I should say. Libraries exposed in the NDK are still allowed. It's private implementation details that are not accessible. https://developer.android.com/about/versions/nougat/android-7.0-changes.html#ndk

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.

Martin

unread,
Oct 3, 2017, 2:46:41 PM10/3/17
to android-ndk
I mean since the JNI lib is getting generated into system/libs, using:
LOCAL_JNI_SHARED_LIBRARIES := libnative_lib_jni
include $(BUILD_PACKAGE)
LOCAL_MODULE := libnative_lib_jni
include $(BUILD_SHARED_LIBRARY)
Do you mean that it should still be accessible even though it is in system? Because in my it cannot open the lib.
Is there something I need to do in the Android.mk to make this work? My environment is AOSP Android O, so no gradle or cmake.

J Decker

unread,
Oct 3, 2017, 2:47:46 PM10/3/17
to andro...@googlegroups.com
No, the library is stored in your apk file and is relative to your application.  The avoidance of 'system libs' is to protect you from the system libraries changing, including the library in your relative apk lib folder you can include any.  
It doesn't do automatic dependency loading though, so if your library requires some other library you have to manually load the dependency first.

This has worked for a long long time (12 is when I started) and turns out not loading system lilbraries hasn't affected me at all.

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.

Martin

unread,
Oct 3, 2017, 2:54:43 PM10/3/17
to android-ndk
Yeah. But in my case the libs is not generated in  the .apk. It is generated in system/libs. How can I get it to be generated in the apk? I know it is automatic when you have gradle and cmake setup, but when using Android.mk I can only get it to be generated in shared libs, which is system/lib. I also once tried to place a lib/myGeneratedLib.so on the same level as the .apk (not inside the .apk), but that gave me same error. Note: The app is a system app, might be why, not sure.

J Decker

unread,
Oct 3, 2017, 2:58:22 PM10/3/17
to andro...@googlegroups.com
It doesn't have to be built, just copied into the structure of the apk to zip it into the apprpriate place.
I have never used 'system'... my build process just has a folder 

~/chatment.android-studio\app\src\main\jniLibs\armeabi\   and things in that folder get built into the apk as /lib/armeabi

But different build tools use different methods.... there looks to be plenty of information about how to specify installing an additional 'source' which is really a library binary for ASOP.


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.

Martin

unread,
Oct 3, 2017, 3:06:06 PM10/3/17
to android-ndk
But is your environment android studio with gradle and cmake? Because in that environment you get everything nicely, aka the libs inside your .apk. How do you update your .so lib? Because even if I put the .so lib in the same structure as you, I still need to update it everytime I build. And this might be a line of code in Android.mk that I do not know about.

Alex Cohn

unread,
Oct 8, 2017, 5:29:15 AM10/8/17
to android-ndk
But some libraries may be declared 'public' in in: /vendor/etc/public.libraries.txt, 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
Reply all
Reply to author
Forward
0 new messages