I configure ndk with eclipse in order to build my c++ code automatically. But i have two external .so file inside libs folder. Everytime, eclipse will delete these external .so file automatically when build project. Is it possible to tell eclipse not delete these external file.
The solution is here.
To summarize (and complement):
Copy your external (e.g., libexternal.so) library (or libraries) to another folder inside your 'jni' folder; for example 'myproject/jni/prebuilt'.
Add the following block to your existing 'jni/Android.mk' (one block for each external library):
include $(CLEAR_VARS)
LOCAL_MODULE := libexternal
LOCAL_SRC_FILES := prebuilt/libexternal.so
include $(PREBUILT_SHARED_LIBRARY)
Add 'libexternal' to 'APP_MODULES' in your existing 'jni/Application.mk'. 'APP_MODULES' should already list your JNI module (e.g., 'myjnimodule'):
APP_MODULES := libexternal myjnimodule
Confirm that the following block exists in 'jni/Application.mk'. Use the appropriate target architecture(s):
APP_ABI := armeabi-v7a
The result is that, as part of the invocation to 'ndk-build', the external library is copied to your 'myproject/libs/armeabi-v7a' folder.
The solution given by John Doedoe led me to another possibility, specific to Eclipse (tested on Mars 1 version):
Right click on your project in the project explorer.
Go into properties.
Go into "C/C++ Build".
Go into the "Builder Settings" tab.
Uncheck "Use default build command".
In the "Build command" text box type your target, e.g.: ndk-build APP_ABI="armeabi-v7a"
Apply / Ok
This will avoid changing behavior on a build machine for instance.
Related
im stuck with this problem and dont know what im doing wrong. Please help me out.
Im working on an android project where I have to use 2 native library(.so) file. These 2 files are not generated by me, i just have to use them in my project.
I have placed these .so files under libs->armeabi folder. In the code i have used System.loadLibrary("name") inside a static block to load these library files. After doing this, i clean the project and run the application. I get the following error
java.lang.UnsatisfiedLinkError:
What am i missing. I have unchecked the first two options in build settings as well.
Note: I am not developing the native library. I am just using it. It was being used in a previous version, so I am pretty sure there is nothing wrong in the way the .so files have been generated.
PS: My ultimate requirement is like this,
My android application will have a jar which I am developing. The methods in the jar will make use of these native functions. The main application will not directly access the native functions. Should i place the .so files in the jar or should it be in the main application. How should i package the jar and .so files.
Please help me out, this is my first time using native functions and im totally lost. Links to any materials would be great.
Set PATH to your NDK
Eclipse -> Window -> Preferences -> Android -> NDK -> set path to the NDK
Right click on an Android project and select Android Tools -> Add native support.
Make changes to your Android.mk file to include this .so file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := <module_name>
LOCAL_SRC_FILES := <.so file name>
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../jni/include
include $(PREBUILT_SHARED_LIBRARY)
Clean project and build again
I have an android test project that includes JNI code from elsewhere in my repository. For instance, my Android.mk file resembles the following:
LOCAL_PATH := $(call my-dir)
include $(LOCAL_PATH)/../../../Android.mk
I have opened my project in eclipse, enabled native support, and switched to the Android Native perspective. The project builds and runs correctly.
My problem is that my native c++ code is not present in the eclipse workspace. I can't see it under the jni folder or under any of the project's sub folders. My question is, how do I include the native code in my workspace so that I can edit it, and set breakpoints (via Sequoyah)?
You can add a linked folder to your eclipse project, see http://www.russellbeattie.com/blog/1002305
I have implemented a JNI android application. This application requires a few additional 'Shared Libs' to be packed as part of the APK. Using Ecplise, I have added these libs to the project's '/libs/armeabi' folder.
However, when launching the application (through the integrated debugger), my added 'Shared Libs' are removed from the 'armeabi' folder.
How can I prevent these additional libs from being removed?
How can I make sure the additional required SOs are packed in the APK?
You don't need to copy this libraries to libs folder yourself. This job should be done by the ndk-build.
These two steps should be enough:
Create mylibs (you can use any other name instead) folder on the root level of your project. And put your libraries into this folder.
For each library add the following lines before the include $(CLEAR_VARS) statement replacing mylib with you library name:
include $(CLEAR_VARS)
LOCAL_MODULE:=mylib
LOCAL_SRC_FILES:=../mylibs/libmylib.so
include $(PREBUILT_SHARED_LIBRARY)
(You might need slightly different path for LOCAL_SRC_FILES. It depends on your Eclipse configuration.)
One more note to add in this context is that the path to the external SharedLib MUST BE relative to the jni directory ( or to whatever spcified # LOCAL_PATH ), that is, "LOCAL_SRC_FILES := ../../../Android/ffmpeg/libavcodec/libavcodec.so" will work where the absolute path will not.
I'm using eclipse to develop an android app that also uses the ndk. I vectors in my app and I've done the necessary stuff to get them by including
APP_STL := stlport_static
In my Application.mk
Everything is working fine it compiles and runs but Eclipse keeps giving me errors when I use the vectors
std::vector<int> blah
for example creates an error. If I delete the error and keep going it compiles and runs fine.
I've added
${NDKROOT}/sources/cxx-stl/gnu-libstdc++/include
In my project config under C++ General -> Paths and Symbols -> include
It resolves #include <vector> fine (before I added the path above I had an error for this) but I still get errors using the vectors.
How can I get eclipse to stop giving me errors for this?
EDIT:
example error: Symbol 'vector' could not be resolved
EDIT 2:
I tried to add
using namespace std;
and then using vector blah and that causes a different error:
Invalid template arguments
I've added ${NDKROOT}/sources/cxx-stl/gnu-libstdc++/include
In my project config under C++ General -> Paths and Symbols -> include
Yes, that's it. I've tried to add the same with the same result.
However, if you add stl_port headers
${NDKROOT}/sources/cxx-stl/stlport/stlport
It will do the trick. Of course it is not necessary to change
APP_STL := stlport_static
as it works only in eclipse indexes. It will be usefull until you are going to use something that exists in gnu-libstdc++ and doesn't exist stl-port.
Blockquote
I am suing eclipse indigo rc2.
I added following line in Android.mk
LOCAL_C_INCLUDES += ${NDKROOT}/sources/cxx-stl/stlport/stlport
and Added following line in Application.mk
APP_STL := stlport_static
then automatically my ndk stlport path added in
Properties -> C++ General -> Paths and Symbols -> include
good luck! ^^
At first, we met the same problem with map and tried to add "Paths and Symbols" as suggested, however it still wouldn't work.
Later on, instead of
#include <map>
we used
#include <stl/_map.h>
The error went away and then we switched back to include <map>. Eclipse no longer complained that "Symbol could not be resolved".
It seems eclipse has a cache and somehow it can get messed up unless you specifically tell it the right place to find the symbols.
I do not know at what stage it worked, but:
Add to Application.mk APP_STL := gnustl_static
Add include to Project properties->C/C++ General -> Paths and Symbols 'NDK root path'/'your directory to android platform'/arch-arm/usr/include
'NDK root path'/sources/cxx-stl/gnu-libstdc++/4.9/include
'NDK root path'/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include/bits
Turn off all warnings errors in Project properties->C++ General->Code Analisis.
Project properties->C++ Build-> Builder Settings -> Uncheck use default build command. Build command set empty.
Next configure NDK Builder: Project properties-> Builders-> New-> Program and fill Name (your name build conf), Location (path to NDK root directory), Working directory (path to project dir). -> Refresh and check specific resources (your libs folder in project). -> Build Options check Specify working set of relevant resources and change 'jni' folder with your source.
worked in Ubuntu 15.04. Eclipse 3.8.1. Android NDK r10e.
I have used ndk successfully to build & use a .so file in one project. I need to use this library in another project. I would rather not copy the source there, but just use the library.
Trying to copy & paste the whole libs/armeabi/libcommon.so to the project root does not work, I think because libs/armeabi is an android generated path.
So what would be the best way to do it?
I am using Eclipse-Galileo & ndk5.
There is a much simpler way to do all of this.
Let's say that your prebuilt library is called "libprebuilt.so"
In the project folder of the new project you want to only include the prebuilt library, do something like:
mkdir -p jni/libprebuilt
cp libprebuilt.so jni/libprebuilt
Then, just create a jni/libprebuilt/Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libprebuilt
LOCAL_SRC_FILES := libprebuilt.so
include $(PREBUILT_SHARED_LIBRARY)
Then when you do ndk-build, it will copy this library in to libs/armeabi/ ... that's all!
I figured out a way to do this, so posting it here in case someone else runs into it.
The code to be shared (including the Java JNI wrapper, native code, .so library), should be in a separate project. Convert this to a Library project by right-click on project name --> properties --> Android properties --> check mark "Is Library". This project cannot be executed now but can be referenced by other projects.
In the project which will use the shared object, add a reference to the Libarray project by right-click on project name --> properties --> Android properties --> Library/"Add". This should show up the Library project created in the previous step. Select it.
Now the .so can be referred to easily between different projects.
There is a package name inside all JNI (Java Native Interface) functions names (like JNIEXPORT void JNICALL Java_com_myapp_myclass_funct). So i guess you should rename these funkcions in library a recompile it. Or maybe use it as external package in your app.