I'm working on an Android NDK project in which I have to use functionalities which needs c++ header files such as iostream , sstream , etc,. I have already did this in linux by adding /usr/include/c++/4.7.. in C++ Paths & Symbols tab. But still din't find a way to do this in Mac. I have tried the following:
I have simply included iostream header #include<iostream> , it shows the following error while build using ndk-build, fatal error: iostream: No such file or directory
Added android-ndk-r9/sources/cxx-stl/gnu-libstdc++/4.8/include in C++ Paths and Symbols->Includes tab->cpp , It doesn't change anything.
In my Android.mk file,
LOCAL_C_INCLUDES := android-ndk-r9/sources/cxx-stl/gnu-libstdc++/4.8/include
it gave the following error:
fatal error: bits/c++config.h: No such file or directory
I have also tried adding prebuilt shared library in Android.mk file , which gave the same error.
Then made a search for the file bits/c++config.h , copied it in to the actual place it is looking for, it shows the same error for osdefines.h , I have copied all the files it is looking for , atlast it asked for bits/memoryfwd.h , but I can't find the file anywhere in my Mac.
What is the actual problem here? What should I do to include those headers in cpp files in my Android NDK project?
Create a file called Application.mk in the directory projet_dir/jni/ (so it is projet_dir/jni/Application.mk).
Add the following line to that file
APP_STL:=stlport_static
If you run into a shared_ptr error, try using APP_STL := gnustl_static instead.
(I had this exact same issue on Linux and the above resolved it for me.)
Related
I'm trying to add libogg to my android NDK project.
I'm using project template that comes with SDL library.
I'm on Windows, so all following scripts were executed under MSYS, a linux terminal emulator.
First, I generated a standalone toolchain.
android-ndk/build/tools/make-standalone-toolchain.sh --platform=android-12 --system=windows-x86_64 --toolchain=arm-linux-androideabi-4.9 --install-dir=Y:/gcc_android_androideabi-4.9_api12/
Then I built the library.
make clean
configure CC="/y/gcc_android_androideabi-4.9_api12/bin/arm-linux-androideabi-gcc" LIBS="-lgnustl_shared" CFLAGS="-mthumb" --host=arm-linux-androideabi
make
Then I copied resulting libogg.so to my project folder and added following to my jni/src/Android.mk:
...
include $(CLEAR_VARS)
LOCAL_MODULE := ogg-prebuilt
LOCAL_SRC_FILES := ../../prebuilt-libs/$(TARGET_ARCH_ABI)/libogg.so
include $(PREBUILT_SHARED_LIBRARY)
...
LOCAL_SHARED_LIBRARIES := ... ogg-prebuilt ...
...
Similar code works fine for another libraries that I use.
ndk-build successfully finds my libraries and adds them to the .apk.
The problem arises when I call System.loadLibrary("ogg"); at runtime. Dynamic linker gives me error message saying something like
Can't find library "libogg.so.0".
I'm sure that my library loading code is ok because it works for other libraries that I have.
Error from the dynamic linker is interesting because make not just generated single libogg.so. It generated 3 completely same files with different names: libogg.so, libogg.so.0 and libogg.so.0.8.2.
I tried to replace libogg.so with libogg.so.0 and adjusted Android.mk properly, but NDK build script yelled at me, saying that prebuilt shared libraries must have .so extension. I tried to just copy libogg.so.0 to libs/ folder, but NDK build script ignored it when building .apk.
Then I opened libogg.so in a hex editor and searched for libogg. I found only one occurence: libogg.so.0[NUL]. I replaced .0 with 2 [NUL]s, so it became libogg.so[NUL][NUL][NUL] and now library loads perfectly.
I can reproduce this error with all toolchains I use: arm-linux-androideabi-gcc-4.9, i686-linux-android-gcc-4.9 and mipsel-linux-android-gcc-4.9. They all are generated using similar scripts.
The error persists if I rename libogg.so.0 or libogg.so.0.8.2 to libogg.so and use it instead of original one. As I said, all three files have same content.
While I can make a sed script to automatically fix library name in .so files when necessary, I wonder if there is a better solution to this problem.
Maybe I have to add some flags to configure?
My slightly less hacky fix for this is to remove the version information from the build system of libogg.
In the directory where you have the libogg source code, open the file src/Makefile.am and change this line:
libogg_la_LDFLAGS = -no-undefined -version-info #LIB_CURRENT#:#LIB_REVISION#:#LIB_AGE#
to
libogg_la_LDFLAGS = -avoid-version
If you don't have automake installed then you can change the generated Makefile after running ./configure. Find the libogg_la_LDFLAGS and make a similar change to the one detailed above. On Linux a sed one-liner like this does the job:
sed -i 's/^libogg_la_LDFLAGS.*/libogg_la_LDFLAGS = -avoid-version/g' src/Makefile
I am trying to create an Android Studio wrapper around C code and am running into a problem with the NDK. Because the C code is from a 3rd party project, I am trying to not move the code location and have the project in a subdirectory of the repository and as such have to not use the build in call to the NDK and its autogenerated make file. The NDK call works correctly, but I get the following error:
make.exe: *** No rule to make target `C:/some_relative_path/jni/../../../../core.c', needed by `C:/some_relative_path/obj/local/armeabi/objs/my_module/C_/some_relative_path/jni/__/__/__/__/core.o'. Stop.
As you can see, the object path has been mangled such that : and .. have been turned into underscores.
I had to add a jni folder to my project and place the Android.mk and Application.mk files in it to satisfy the path appending of the NDK Gradle plugin. As a result the jni folder had no source files in it. Since I found several links on google talking about needing more than one source file, I added two dummy source files to the jni directory.
Among other things, my Android.mk file contains the following:
LOCAL_SRC_FILES := \
$(LOCAL_PATH)/NDKBug1.c \
$(LOCAL_PATH)/NDKBug2.c \
$(LOCAL_PATH)/../../../../core.c \
I'm looking to see if anyone can help me with either this path issue directly, or perhaps suggest an alternative way of setting things up.
The file names in LOCAL_SRC_FILES are supposed to be relative to the local directory, so you need to remove the $(LOCAL_PATH)/ prefix - then it should work.
I haven't heard about a bug requiring to have source files in the local dir though, so I think you can get rid of them.
I have followed tutorials to implement NDK functionality in a test project. Created jni folder and added .mk and .c file. NDK is linked and the C++ make file has link to ndk-build file in NDK folder.
On building project i am getting this error :-
Build of configuration Default for project HomeTestingNDK **
/home/falooka/adt-bundle-linux-x86-20130917/ndk/ndk-build all
Compile thumb : HomeTestingNDK <= native.c
make: /home/falooka/adt-bundle-linux-x86-20130917/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc: Command not found
make: * [obj/local/armeabi/objs/HomeTestingNDK/native.o] Error 127
Build Finished **
Now the issue is that 'make' is going for arm-linux-androideabi-gcc while this file doesn't exist in the folder and instead there is arm-linux-androideabi-gcc-4.6. Now I am totally struck how to solve this issue after googling for a while now.
Thanks in advance.
I was able to resolve my issue by following these multiple steps :
1) For some stupid reason, arm-linux-androideabi-gcc was missing in the ndk directory. So i tried re-installing the zip and extracted it inside the home folder instead of my drive to avoid ownership errors. Now file was there and this error was gone !
2) Then i was getting "Android NDK java.lang.UnsatisfiedLinkError: findLibrary returned null" error which had something to do with libraries missing. After reading some posts, it was prominent that the libs/ folder in project directory should have .so files which were not there. I am using OpenCv with my project so i updated the environment links and put explicit path to ndk-build file in 'make' to make sure it finds ndk-build.
3) I also did this : https://stackoverflow.com/a/7646921/1016544
So finally its compiling and shows building of .so files before installing and runs perfectly.
I transitioned from using Eclipse to Android Studio. I discovered after hours of battle that the project.properties file that used to be generated by Eclipse was necessary for me to build the JNI component of my app.
I'm just looking for someone to explain:
Why is this project.properties file necessary?
Is there a way I can tweak my Android.mk so I don't need it?
The project.properties file that I need has 1 line:
target=android-10
I am doing native window API calls in my JNI code.
Edit:
I just wanted to add...without this properties file my symptoms include not being able to locate header files and libraries, such as this sample output:
Compile++ thumb : videolibs <= video_codec_jni.cpp
/Users/spartygw/vpdsec/src/applications/VideoSend/jni/video_codec_jni.cpp:11:35: error: android/native_window.h: No such file or directory
/Users/spartygw/vpdsec/src/applications/VideoSend/jni/video_codec_jni.cpp:12:39: error: android/native_window_jni.h: No such file or directory
In file included from /Users/spartygw/vpdsec/src/applications/VideoSend/jni/../../../libraries/VideoCodec/H263.h:13,
The easiest workaround would be to put this one-line file in jni/.. directory manually.
You can also add APP_PLATFORM=android-10 to your ndk-build command line.
You can also set it in your Application.mk. Unfortunately, you cannot set this in Android.mk.
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.