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.
Related
Android Studio 2.2 introduces cmake external build system. The problem is that documentation is really lacking and I do not know how should I link third party libraries? I've tried cmake directive target_link_libraries:
target_link_libraries(native-lib libs/libSomething.so)
And it "works" in that app compiles but then I get dlopen error at runtime because libSomething.so has not been packaged with application. The libs directory is under "app" if that changes anything and I've started with default JNI project generated by Android Studio 2.2...
[Update]
I've tried putting libSomething.so under app/src/main/jniLibs/armeabi-v7a but now the "main" (native-lib) library is not packaged.
[Update2]
I've added source set config that includes cmake output dir and this works but is ugly as hell and is not really a permanent solution...
sourceSet
{
main
{
jniLibs.srcDirs = [ "libs", ".externalNativeBuild/cmake/debug/obj"]
}
}
For now I ended up copying libSomething.so to cmake library output directory in a post build step. This works because it turns out that Android Studio copies into apk EVERYTHING that is in that directory.
Command in cmake is the following:
add_custom_command(TARGET native-lib POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI}/libSomething.so
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libSomething.so
)
For now, you could also put your shared libs into directory, and configure jniLibs to point to that directory, that will pack it. One sample is here: https://github.com/googlesamples/android-ndk/tree/master/hello-libs, follow gperf see if that helps. This way app not depending on the generated build folders. When android studio added packing libs, the jniLibs workaround is not necessary anymore
I have developed a game in xcode using cocos2d-x 2.2.3 and box2d. Now i am trying to port from ios to android. However i am getting the following error while build through terminal.
In file included from jni/../../Classes/LevelScene.cpp:1:0:
jni/../../Classes/LevelScene.h:6:19: fatal error: Box2D.h: No such file or
directory
compilation terminated.
make: ***
[obj/local/armeabi/objs/cocos2dcpp_shared/__/__/Classes/LevelScene.o] Error 1
Please advice.
I just copied the files which is in box2d folder and placed in classes folder. It worked.
The right way to do this is to allow CMake to find the directory. In the CMakeLists.txt file, use it like this:
set(Box2D_SOURCE_DIR "/path/to/your/folder/liquidfun-1.1.0/liquidfun/Box2D")
include_directories (${Box2D_SOURCE_DIR})
You could also set the directory relatively:
set(Box2D_SOURCE_DIR "..")
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 am trying to make a Live Wallpaper for android that plays an .mp4 video located on the device in android-asset (with the example I am using, it actually copies the file to the sdcard at runtime/doesn't matter)
I found this example
And using this post I was able to get my eclipse set up with NDK and building the project.
When building in eclipse using the NDK plugin I get this error in my problems window:
Description Resource Path Location Type
make: *** [libs/armeabi/libavcodec.so] Error 1 GLWallpaperVideoDemo-master C/C++ Problem
make: *** Deleting file `libs/armeabi/libavcodec.so' GLWallpaperVideoDemo-master C/C++ Problem
I get the same error if I try to run ndk-build from command prompt.
I downloaded the project from the link above and then imported into eclipse. I added the lib GLWallpaperService to the build path, and made sure my NDK was setup. Knowing that the lib folder changed to libs I also tried moving the GLWallpaperService to the libs folder, which didn't help.
The project builds without NDK just fine in eclipse but obviously errors when trying to run the wallpaper because the native libraries were not built.
How can I resolve this error?
The package you get by git clone https://github.com/frankandrobot/GLWallpaperVideoDemo.git is Linux oriented. The file jni\ffmpeg-android\build\ffmpeg\armeabi\lib\libavcodec.so and many others are simply symbolic links to actual files.
To make this all work easily on Windows, I suggest to go to the jni\ffmpeg-android\build\ffmpeg\armeabi\lib folder, and run
del *.so
copy libavcodec.so.52.99.1 libavcodec.so
copy libavcore.so.0.16.0 libavcore.so
copy libavdevice.so.52.2.2 libavdevice.so
copy libavfilter.so.1.69.0 libavfilter.so
copy libavformat.so.52.88.0 libavformat.so
copy libavutil.so.50.34.0 libavutil.so
copy libswscale.so.0.12.0 libswscale.so
The issue might be because of a corrupted so file. Try to build the ffmpeg library again or find another version. Because I have a different error in eclipse when I try to compile the project:
C:/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/arm-linux-androideabi-strip:./libs/armeabi/libavcodec.so: File format not recognized
And when I search for this error it seems like the error is because of a corrupted file: NDK prebuilt shared library file format not recognized
Or the library is not in a format that Android can use:
Error in linking C++ static library with android ndk(Error: file format not recognized)
I am getting error while trying to build android ndk project:
error: jni.h: No such file or directory
But: locate jni.h command show me:
locate jni.h
/usr/lib/jvm/java-6-openjdk-i386/include/jni.h
What is wrong in my actions?
EDIT:
If I hardcode it in the source code it work but I have a lot of files that are using this header. What I need to do that all my files can see /usr/lib/jvm/java-6-openjdk-i386/include/jni.h
?
Try setting the installation location of your NDK in PATH in your rc file, let's say ~/.bashrc:
NDK=/path/to/your/ndk/location
export PATH=$PATH:$NDK
Source the rc file by running source ~/.bashrc.
Now when you run ndk-build, it will setup the whole build environment for you by running make command against a bunch of make files under $NDK/build/core, it will setup correct header file search path for your project depending on the android:targetSdkVersion setting in AndroidManifest.xml.
The jni.h needed by your NDK project is located under $NDK/platforms/android-14/arch-arm/usr/include.
Android NDK projects will not use any JNI header files under your JDK installation, files under /usr/lib/jvm/.... will never be touched.