Jump to content
Tuts 4 You

How to load Prebuilt Libraries ".so" files properly into android studio


ramzi2015

Recommended Posts

Posted

I'm using :

- windows 7 x64  

- Android studio 2.3.3 with offline gradle (gradle-4.2)

- Ndk is installed (android-ndk-r15c-windows-x86_64)

- CMake is installed (cmake-3.10.0-rc4)

- lldb for debuging is installed

Why the native method is always in red?

How to load  Prebuilt Libraries ".so" files properly into android studio?

If possible, i need a demo project for using prebuild libraries.

I attached a sample project for my work and a screen capture for android project.

Forgive me if i can't reply in time, i have a limited internet connection. 

--------------------------------
how to use Android.mk?
--------------------------------

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := foo-prebuilt
LOCAL_SRC_FILES := libfoo.so
include $(PREBUILT_SHARED_LIBRARY)


Thanks for help.

SoApp.rar

Capture.JPG

Posted

Thanks CodeCracker for the reply, but the task is  not impossible.

It was described here hxxps://developer.android.com/ndk/guides/prebuilts.html

The problem is in my version of android studio or in the configuration of my project or something related.

Some persons have already done the task . Under MacOs for example  hxxps://www.youtube.com/watch?v=iVir4N55YQg

I need to do the job under windows. I already tried many tutorials but  always have  something wrong .

I can  load the  library but the native method cause an exception.

Posted

Did you add the necessary prefix to the native method (in the native library) as described in the documentation? What exception does the native method throw?

Posted

Excuse me for being late.

What i'm doing is based to  samples from android ndk.

There is no prefix to add to the method according to officiel docs.

For the exception -------> " java.lang.UnsatisfiedLinkError: Native method not found"

 

Posted

That's because you changed the class name. In the official example (https://github.com/googlesamples/android-ndk/blob/master/hello-jni/app/src/main/java/com/example/hellojni/HelloJni.java) the class is named "HelloJni" and the native method is appropriately named  "Java_com_example_hellojni_HelloJni_stringFromJNI" (https://github.com/googlesamples/android-ndk/blob/master/hello-jni/app/src/main/cpp/hello-jni.c). If you change the name of the class, the prefix of the native method should change as well. This is defined in the JNI documentation (https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/design.html#jni_interface_functions_and_pointers, "Resolving Native Method Names") and perhaps more clearly, in the guide to the HelloJni sample (https://developer.android.com/ndk/samples/sample_hellojni.html, "C-side Implementation"). It should be something like "Java_com_ramzi_soapp_MainActivity_stringFromJNI".

Posted

Thanks for the help, but something is not working for me. Take a look to the attached capture.

And if possible, do you have a working example.

Capture.JPG

Posted

The name of the native method looks better now. I also had trouble getting Android Studio to recognize the native method, but the apps I made still worked despite that. Unfortunately, I don't have them available anymore. Does your app still crash with the same exception when you run it on the phone now?

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...