Discussion:
Accessing methods from .so files that are on a device
Steve Malek
2018-05-24 21:52:19 UTC
Permalink
Hello,

I am very new to android ndk and I am having trouble with the following
issue.
I am writing a standalone application which I want for it to be able to
load a .so file that is on my mobile device and call its methods.
Looking online I am not able to find a solution and most of what I find are
based on older versions of Studio and Gradle.

I am familiar enough with NDK to create a simple .so file myself but no
clear on how to access .so files external to my own project.
To be more clear what I need is to be able to call a external .so file from
an Android App without having access to its source code. As noted above an
example would be something on the device that I can load to my app and call.

Can I directly call the .so file that is on my device from an application?
Do I need to pull the .so file and place it in my project?
Or is this not achievable without the source code being available?

Looking for advice on 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.
To post to this group, send email to android-***@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/d99d2e79-779f-4d9f-ad6d-59edd4694d86%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
J Decker
2018-05-25 02:24:29 UTC
Permalink
what you're probably missing is the java->C interface?
it's JNI - ... can google seach 'android jni ndk' maybe?
Post by Steve Malek
Hello,
I am very new to android ndk and I am having trouble with the following
issue.
I am writing a standalone application which I want for it to be able to
load a .so file that is on my mobile device and call its methods.
Looking online I am not able to find a solution and most of what I find
are based on older versions of Studio and Gradle.
I am familiar enough with NDK to create a simple .so file myself but no
clear on how to access .so files external to my own project.
To be more clear what I need is to be able to call a external .so file
from an Android App without having access to its source code. As noted
above an example would be something on the device that I can load to my app
and call.
Can I directly call the .so file that is on my device from an application?
Do I need to pull the .so file and place it in my project?
Or is this not achievable without the source code being available?
Looking for advice on 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
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/d99d2e79-779f-4d9f-ad6d-59edd4694d86%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/d99d2e79-779f-4d9f-ad6d-59edd4694d86%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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 android-***@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/CAA2GJqVx8ogxszPkCAUSTBEgstakCs-fFFRGup0qQm-EzmS0Yw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Steve Malek
2018-05-25 11:19:40 UTC
Permalink
Just to be clear are you suggesting that in order to call a native library
from the device I should do it within the C code using for example the
dlopen() method rather than calling System.loadLibrary and passing a full
path to the native library?
I have tried the latter but method is not being recognized and hence I get
compiler errors, however I have not tried writing a C program to do this.
Problem is I have read that using System.loadLibrary should work fine in
the situation I describe.
I apologize for my confusion.
Post by J Decker
what you're probably missing is the java->C interface?
it's JNI - ... can google seach 'android jni ndk' maybe?
Post by Steve Malek
Hello,
I am very new to android ndk and I am having trouble with the following
issue.
I am writing a standalone application which I want for it to be able to
load a .so file that is on my mobile device and call its methods.
Looking online I am not able to find a solution and most of what I find
are based on older versions of Studio and Gradle.
I am familiar enough with NDK to create a simple .so file myself but no
clear on how to access .so files external to my own project.
To be more clear what I need is to be able to call a external .so file
from an Android App without having access to its source code. As noted
above an example would be something on the device that I can load to my app
and call.
Can I directly call the .so file that is on my device from an
application?
Do I need to pull the .so file and place it in my project?
Or is this not achievable without the source code being available?
Looking for advice on 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
<javascript:>.
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/d99d2e79-779f-4d9f-ad6d-59edd4694d86%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/d99d2e79-779f-4d9f-ad6d-59edd4694d86%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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 android-***@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/74591e48-3440-440b-af4f-f99d5b8c5911%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Alex Cohn
2018-05-26 09:29:33 UTC
Permalink
There are different kinds of .so files on your Android device.

1. libraries automatically installed for your app. They come inside the
APK package and the system installer unpacks them to the app native
libraries directory. These libs can be loaded from Java by
System.loadLibrary(). You must call this API if they are JNI libraries.
Since Lollipop, you don't need to load these libraries in reverse
dependency order, they will be automatically resolved by the system dynamic
linker. These libs are publicly accessible for read, but no app (including
your app) can change them.

Note that since Marshmallow, you can set application/extractNativeLibs
to false in your Manifest, and the native libraries will be used without
unpacking. The APK file itself is also publicly readable.

2. libraries that you install in non-automatic way. E.g. some apps have
different flavors of native libs packaged in their APK, and extract the
correct flavor on activation. These libs typically get unpacked into app
private directory, and can be loaded from Java by System.load(). These libs
are not

3. public system libraries, that are part of NDK, like libc or libdl.
These will be automatically loaded by the system dynamic linker if a loaded
library depends on one of them.

4. non-public system libraries, like libcrypto or libcutil. You should
not use these libraries in your app. Since Nougat, Android actively
protects these libraries from being loaded by user apps.

5. libraries that are installed by other apps (see *1.*). Today, any app
can load native libraries from another app, if it knows the full path to
the lib file.


BR,
Alex
Post by Steve Malek
Hello,
I am very new to android ndk and I am having trouble with the following
issue.
I am writing a standalone application which I want for it to be able to
load a .so file that is on my mobile device and call its methods.
Looking online I am not able to find a solution and most of what I find
are based on older versions of Studio and Gradle.
I am familiar enough with NDK to create a simple .so file myself but no
clear on how to access .so files external to my own project.
To be more clear what I need is to be able to call a external .so file
from an Android App without having access to its source code. As noted
above an example would be something on the device that I can load to my app
and call.
Can I directly call the .so file that is on my device from an application?
Do I need to pull the .so file and place it in my project?
Or is this not achievable without the source code being available?
Looking for advice on 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.
To post to this group, send email to android-***@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/fdc3eee8-b8d5-4b17-b038-cc52a37df183%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...