ramzi2015 Posted November 10, 2017 Posted November 10, 2017 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
CodeExplorer Posted November 11, 2017 Posted November 11, 2017 (edited) 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, 2017 by CodeCracker
ramzi2015 Posted November 11, 2017 Author Posted November 11, 2017 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.
Zasz Posted November 11, 2017 Posted November 11, 2017 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?
ramzi2015 Posted November 12, 2017 Author Posted November 12, 2017 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"
Zasz Posted November 12, 2017 Posted November 12, 2017 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".
ramzi2015 Posted November 13, 2017 Author Posted November 13, 2017 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.
ramzi2015 Posted November 13, 2017 Author Posted November 13, 2017 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 1
Zasz Posted November 13, 2017 Posted November 13, 2017 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?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now