Posted November 10, 20177 yr 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
November 11, 20177 yr http://whatis.techtarget.com/fileformat/SO-Shared-library-file-Unix-equivalent-to-a-Windows-DLLhttps://superuser.com/questions/71404/what-is-an-so-file A .so file is what is a dll but for Linux, I think it is an impossible task. Edited November 11, 20177 yr by CodeCracker
November 11, 20177 yr Author 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.
November 11, 20177 yr 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?
November 12, 20177 yr Author 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"
November 12, 20177 yr 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".
November 13, 20177 yr Author 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.
November 13, 20177 yr Author Please, i need help, i'm going crazy. I already updated my tools but no changes happen. I attached my new work to this post. I need a working demo project. Project_for_generating_the_so_file.rar Project_where_so_file_is_used.rar
November 13, 20177 yr 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