Hi, is there a way to a load a native .so library and call its functions without any JNI or Java code?
--
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 view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/c1231854-4744-478d-9c8b-eb7777a90dca%40googlegroups.com.
Hi, is there a way to a load a native .so library and call its functions without any JNI or Java code?
--
int add(int a, int b){
return a + b;
}
void (*add_ptr)(int, int) = &add;
(*add_ptr)(10,10);
LOCAL_LDLIBS := -L$(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI) -lMyLib -llog -landroidyes but you will know function names and parameters and you will load library by your self and call functions by pointer
On Wed, Jan 1, 2020, 7:54 PM Raster Ron <rast...@live.com> wrote:
Hi, is there a way to a load a native .so library and call its functions without any JNI or Java code?--
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 andro...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/dea7a5fc-8cb2-46a8-8f25-4ecb14a6513c%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/dea7a5fc-8cb2-46a8-8f25-4ecb14a6513c%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/e5513b1c-efe6-464f-81c8-c980d3857bab%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/e5513b1c-efe6-464f-81c8-c980d3857bab%40googlegroups.com.
I see. The only loadlibrary method I know is using JNI and Java with System.loadLibrary. Is there pure C/C++ way of doing this with NDK?
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/a78d990a-ef4b-4fcf-b799-9ecb758c2c68%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/a78d990a-ef4b-4fcf-b799-9ecb758c2c68%40googlegroups.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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/5d2afabf-0a39-41f1-a469-534a61736434%40googlegroups.com.
The only real 'gotcha' is that dlopen doesn't seem to include the app's library path; if you have a .so you load that depends on another .so, you will likely have to load the other first (Unless it's a system library in like /usr/lib); I've heard rumors that has been fixed in recent NDK's; I'm going back to 9 or 10... and maybe it depends on other factors.
On Fri, Jan 3, 2020 at 5:19 PM Andrew Esh <andre...@gmail.com> wrote:
--Here is a NDK sample that implements an activity entirely within C++ code. You should be able to do a dlopen from within such code to open your native .so library.https://developer.android.com/ndk/samples/sample_na
On Wednesday, January 1, 2020 at 9:54:37 AM UTC-6, Raster Ron wrote:Hi, is there a way to a load a native .so library and call its functions without any JNI or Java code?
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 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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/7353585d-adcc-4c8b-a119-4c6317e44e1a%40googlegroups.com.
On Tue, Jan 14, 2020 at 2:07 PM Raster Ron <rast...@live.com> wrote:Thanks guys!I can already do Native C++ just with the main file similar to the sample_na from the online android docs.I am still looking for an example perhaps like a Hello World template on how to load a .so file using only pure C/C++ without JNI/Java. I was hoping this has been covered already, but still cannot find any plain and simple example on how its done, also not involving any root access or related method.Really? What happens when you just use dlopen? Does it not find it because the library path isn't part of the path? (could be, I forget....)I find 'myself', that being the library that is currently running with...I read /proc/self/maps and find the memory region containing the current running routine.https://github.com/d3x0r/SACK/blob/master/src/deadstart/android/default_android_main.c#L577-L643 (this one probably)That gives you the full path to the current library, from which you can strip the library name and get the path... then you can use that path to prepend to other libraries you've packaged with your app.I've been told 'DO NOT DO THIS', many times; they claim that there's some magic like the dll's aren't actually installed out of the APK so you can't get it from just the disk... but, if it works, what's the big deal?I also extract all my data assets manually, so i can just use standard file operations for my images, etc...(ExportAssets)Which, all together, read /proc/self/maps, ExportAssets, and then start using dlopen/dlsym to load the libraries.
On Tue, Jan 14, 2020 at 7:21 PM J Decker <d3c...@gmail.com> wrote:On Tue, Jan 14, 2020 at 2:07 PM Raster Ron <rast...@live.com> wrote:Thanks guys!I can already do Native C++ just with the main file similar to the sample_na from the online android docs.I am still looking for an example perhaps like a Hello World template on how to load a .so file using only pure C/C++ without JNI/Java. I was hoping this has been covered already, but still cannot find any plain and simple example on how its done, also not involving any root access or related method.Really? What happens when you just use dlopen? Does it not find it because the library path isn't part of the path? (could be, I forget....)I find 'myself', that being the library that is currently running with...I read /proc/self/maps and find the memory region containing the current running routine.https://github.com/d3x0r/SACK/blob/master/src/deadstart/android/default_android_main.c#L577-L643 (this one probably)That gives you the full path to the current library, from which you can strip the library name and get the path... then you can use that path to prepend to other libraries you've packaged with your app.I've been told 'DO NOT DO THIS', many times; they claim that there's some magic like the dll's aren't actually installed out of the APK so you can't get it from just the disk... but, if it works, what's the big deal?I also extract all my data assets manually, so i can just use standard file operations for my images, etc...(ExportAssets)Which, all together, read /proc/self/maps, ExportAssets, and then start using dlopen/dlsym to load the libraries.snprintf( buf, 256, "%s.code.so", myname );
I've been told 'DO NOT DO THIS', many times; they claim that there's some magic like the dll's aren't actually installed out of the APK so you can't get it from just the disk... but, if it works, what's the big deal?
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CAA2GJqWOLi3BA_vnHcSgyB9wPQ%3DiBd9_5-g0WVVYoP3fMfrFVA%40mail.gmail.com.
I've been told 'DO NOT DO THIS', many times; they claim that there's some magic like the dll's aren't actually installed out of the APK so you can't get it from just the disk... but, if it works, what's the big deal?You're wasting the user's disk space. It only works because your APK is still built with android:extractNativeLibs set to true (the default until targetSdkVersion 29).
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CAFVaGhtxYNt7xQu5V-wfErfiO2HuxNB7a%3DiAUgSiY0WTnJm90w%40mail.gmail.com.
If Android really wanted to not waste space (or for me to) they should just mount my APK in a FUSE mount and allow simple file access without extracting assets... and dlopen would still find it was in a path with other libraries of the correct ABI compilation format in that same path.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CAA2GJqVKafZAnJmx7TyFySP9dM_%2BfDZ3SO45LVuUUz9s9nUNzw%40mail.gmail.com.