Android-NDK build system (building hello-gl2) - android

I downloaded and installed Android-NDK on my Archlinux, using this package.
Got no issues building (and running) the sample hello-jni following the guide on this page, but if I try to do the same with hello-gl2 I get some errors; it looks like it cannot find some header files:
$ ../../ndk-build
/usr/bin/make -f /opt/android-ndk/build/core/build-local.mk
Compile++ thumb : gl2jni <= gl_code.cpp
/opt/android-ndk/samples/hello-gl2/jni/gl_code.cpp:22:23: error: GLES2/gl2.h: No such file or directory
/opt/android-ndk/samples/hello-gl2/jni/gl_code.cpp:23:26: error: GLES2/gl2ext.h: No such file or directory
--- SNIP ---
GLES2/gl2.h and GLES2/gl2ext.h are however present in $(NDK)/platforms/android-4/arch-arm/usr/include/, and it looks like$(NDK)/build/core/setup-toolchain.mk should set such include path.
Has anybody encountered the same issue? How can I compile this sample?
And then, are there other options to easily build Android-NDK applications? This build system seems quite complicated to me, and I'd prefer using cmake to build my applications.

make sure that APP_ABI and APP_PLATFORM is defined in your Application.mk and your APP_PLATFORM should be higher than android-5... check: gl.h & glext.h not found
for example, in Application.mk define:
APP_ABI := armeabi #armeabi-v7a
APP_STL := stlport_static
APP_PLATFORM := android-8

In my case it was missing the file default.properties with such content:
target=android-5
Put this file into the root project directory. It may help.

You need to use a higher SDK. Level 5 is the minimum to build OpenGL ES 2 code.

Related

android ndk project having error when loading the library

i am very new to the android ndk and opencv
but i have already run some samples/tutorials of opencv projects in Eclipse
therefore the opencv library should not be a problem
Here i want to run this camera project from github, i think it should work
After I downloaded it and import it into the Eclipse,
I encountered a problem :
When I run it it stops and finishes because the library cannot be loaded in the CameraActivity.
-> System.loadLibrary("PanoHDR");
I have tried to search the web for solutions but they either didn't work or I didn't understand them.
Do I need to do something like "ndk-build" at somewhere to make it work?
Could someone please help me? I cannot find any solution.
here is the default android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Tegra optimized OpenCV.mk
include /Users/milmil/Documents/NVPACK/OpenCV-2.4.5-Tegra-sdk-r2/sdk/native/jni/OpenCV-tegra3.mk
# Linker
LOCAL_LDLIBS += -llog
# Our module sources
LOCAL_MODULE := PanoHDR
LOCAL_SRC_FILES := PanoHDR.cpp Panorama.cpp HDR.cpp NativeLogging.cpp
include $(BUILD_SHARED_LIBRARY)
when i try to use ndk-build in cmd in the main dir of the project
it fails
jni/Android.mk:6: /sdk/native/jni/OpenCV.mk: No such file or directory
make: *** No rule to make target `/sdk/native/jni/OpenCV-tegra3'. Stop.
and it should be caused by this line in the Andriod.mk
include /Users/milmil/Documents/NVPACK/OpenCV-2.4.5-Tegra-sdk-r2/sdk/native/jni/OpenCV-tegra3.mk
I try to use the path of my opencv sdk
include /Android/OpenCV-3.1.0-android-sdk/OpenCV-android-sdk/sdk/native/jni/OpenCV.mk
and it returns this in the cmd
Android NDK: WARNING:jni/Android.mk:PanoHDR: non-system libraries in linker flag
s: -lopencv_java3
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_S
TATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependenc
ies of the
Android NDK: current module
[armeabi-v7a] "Compile++ thumb": "PanoHDR <= PanoHDR.cpp"
The system cannot find the path specified.
make: *** [obj/local/armeabi-v7a/objs/PanoHDR/PanoHDR.o] Error 1
Thank you
=========================================================================
WARNING:jni/Android.mk:PanoHDR: non-system libraries in linker flag
s: -lopencv_java3
the above problem is solved by adding "OPENCV_LIB_TYPE=STATIC" in the android.mk, but still has this error "
[armeabi-v7a] "Compile++ thumb": "PanoHDR <= PanoHDR.cpp"
The system cannot find the path specified.
make: *** [obj/local/armeabi-v7a/objs/PanoHDR/PanoHDR.o] Error 1"

How to use a custom toolchain with ndk-build?

I've spent a day on this and can't seem to configure my dev environment for a NDK toolchain that will support standard C++ libraries. The story is I'm trying to cross compile libnfnetlink and libnetfilter_queue for ARM (Android).
First I'm using the following:
Nexus 5 with CyanogenMod 11 (I forget, doesn't matter I'm not even on the device yet)
Ubuntu 12.04 32-bit
Android SDK bundle: adt-bundle-linux-x86-20140702
Android NDK: android-ndk-r10c
There is a great blog on doing this here but its incomplete as Netfilter uses stlc++ and there's no word on a NDK install/setup that would work with simply calling ndk-build. Just copying the files into /jni and calling ndk-build won't work alone.
Anyways, my specific problem is when I straight copy the Netfilter lib source structure into an empty Project's /jni directory, I get this:
user#ubuntu:~/Projects/NetfilterTest/NetfilterNativeTest/jni$ ndk-build
[armeabi] Compile thumb : netfilter_queue <= libnetfilter_queue.c
In file included from /home/user/Projects/NetfilterTest/NetfilterNativeTest/jni/libnetfilter_queue/src/libnetfilter_queue.c:35:0:
/home/user/Projects/NetfilterTest/NetfilterNativeTest/jni/libnetfilter_queue/src/internal.h:4:20: fatal error: config.h: No such file or directory
compilation terminated.
make: *** [/home/user/Projects/NetfilterTest/NetfilterNativeTest/obj/local/armeabi/objs/netfilter_queue/libnetfilter_queue/src/libnetfilter_queue.o] Error 1
The config.h file can't be found. After some googling I realize its because the standard C++ libraries aren't available in the prebuilt tool chains.
Everything points to me creating my own tool chain. So I build my own cross compiler using the scripts that the NDK includes.
cd /home/user/android-ndk-r10c/build/tools
./make-standalone-toolchain.sh --platform=android-19 --ndk-dir=/home/user/android-ndk-r10c/ --install-dir=/home/user/android-ndk-r10c/prebuilt/android-arm/android-19
To confirm that config.h is included in my tool chain I searched for it. It's there:
user#ubuntu:~/Projects/NetfilterTest/NetfilterNativeTest/jni$ find /home/user/android-ndk-r10c/prebuilt/android-arm/android-19/ -iname config.h
/home/user/android-ndk-r10c/prebuilt/android-arm/android-19/sysroot/usr/include/linux/config.h
Naturally I need to setup my environment and the Android.mk
JAVA_HOME=/usr/local/java/jdk1.6.0_45
JRE_HOME=$JAVA_HOME/jre
ANDROID_SDK=/home/user/adt-bundle-linux-x86-20140702
ANDROID_NDK=/home/user/android-ndk-r10c
ANDROID_CHAIN=/home/user/android-ndk-r10c/prebuilt/android-arm/android-19
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$ANDROID_SDK/sdk/platform-tools:$ANDROID_SDK/sdk/tools:$ANDROID_NDK:$ANDROID_CHAIN/bin
SYSROOT=$ANDROID_NDK/platforms/android-19/arch-arm
CC=arm-linux-androideabi-gcc
export CC
export ANDROID_SDK
export ANDROID_NDK
export SYSROOT
export JAVA_HOME
export JRE_HOME
export PATH
Here's my Android.mk (based on Roman10's blog:
LOCAL_PATH:=$(call my-dir)
#####################################################################
# build libnflink #
#####################################################################
include $(CLEAR_VARS)
LOCAL_MODULE:=nflink
LOCAL_C_INCLUDES:= $(LOCAL_PATH)/libnfnetlink/include
LOCAL_SRC_FILES:=\
libnfnetlink/src/iftable.c \
libnfnetlink/src/rtnl.c \
libnfnetlink/src/libnfnetlink.c
include $(BUILD_STATIC_LIBRARY)
#####################################################################
# build libnetfilter_queue #
#####################################################################
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/libnfnetlink/include \
$(LOCAL_PATH)/libnetfilter_queue/include
LOCAL_MODULE:=netfilter_queue
LOCAL_SRC_FILES:=libnetfilter_queue/src/libnetfilter_queue.c
LOCAL_STATIC_LIBRARIES:=libnflink
include $(BUILD_STATIC_LIBRARY)
#####################################################################
# build our code #
#####################################################################
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/libnfnetlink/include \
$(LOCAL_PATH)/libnetfilter_queue/include
LOCAL_MODULE:=nfqnltest
#LOCAL_LDLIBS:=-lstdc++
LOCAL_SRC_FILES:=nfqnl_test.c
LOCAL_STATIC_LIBRARIES:=libnetfilter_queue
LOCAL_LDLIBS:=-llog -lm
include $(BUILD_EXECUTABLE)
I still get config.h not found using ndk-build.
I've read that the ndk-build command leverages a config.mk/setup.mk that Google includes in the NDK and has to be modified to point to an alternative toolchain.
I'm completely floored that Google's own tools can't simply point to a custom toolchain that they give you scripts to create. If anyone has any suggestions on how I can use my toolchain to compile Netfilter or just in general it would be a great help.
Thanks in advance!
I can't find any reference to either internal.h or config.h when I search for a version of libnetfilter_queue.c on the web, so I'm not sure what version of the file you're using - can you point to which one you have?
Also, the config.h it looks for isn't the one you found in your toolchain (which should be included as linux/config.h) but most probably is one that you're expected to generate by running a configure script. So unless you've run the configure script (or have a pregenerated config.h from elsewhere) you can't really build it.
Finally, nothing of this has anything to do with libstdc++ since all your source files seem to be pure C, not C++.

NDK_TOOLCHAIN is defined to the unsupported value

I'm woking on running an irrlicht android sample project in android emulator using android-ndk, When I have tried building that sample , the following error occurred:
/Android/android-ndk-r9/ndk-build V=1 NDK_TOOLCHAIN=arm-2010q1
/Android/android-ndk-r9/build/core/init.mk:555: *** Android NDK: Aborting . Stop.
Android NDK: NDK_TOOLCHAIN is defined to the unsupported value arm-2010q1
Android NDK: Please use one of the following values: arm-linux-androideabi-4.6 arm-linux-androideabi-4.8 arm-linux-androideabi-clang3.2 arm-linux-androideabi-clang3.3 mipsel-linux-android-4.6 mipsel-linux-android-4.8 mipsel-linux-android-clang3.2 mipsel-linux-android-clang3.3 x86-4.6 x86-4.8 x86-clang3.2 x86-clang3.3
Then in config.mk file, I have changed:
TOOLCHAIN_ABIS := armeabi armeabi-v7a
to:
TOOLCHAIN_ABIS := armeabi armeabi-v7a arm-linux-androideabi-4.6
and to:
TOOLCHAIN_ABIS := armeabi armeabi-v7a 4.6
In Application.mk file, Changed:
APP_ABI := armeabi-v7a
to:
APP_ABI := armeabi
and then to:
APP_ABI := arm-linux-androideabi-4.6
Nothing changed. I dint got anything more than this, when I googled it. Does anyone know the solution to this issue. Where can I find arm-2010q1 and how to change it? Any help will be appreciated.
NDK_TOOLCHAIN=arm-2010q1 is passed directly to your ndk-build command, you only need to avoid setting it if you don't have this toolchain and keep the default one.
If you aren't calling the ndk-build script by yourself but from eclipse, you can go into your project properties and revert the C/C++ build settings:

Refactor Android NDK make files into modules

I'm having trouble refactoring some make files into manageable modules.
Following is the structure I try to accomplish:
jni/Android.mk
jni/Application.mk
jni/libobj/Android.mk
jni/libpng/Android.mk
jni/libzip/Android.mk
jni/freetype/Android.mk
jni/ftgles/Android.mk
jni/qcar/Android.mk
jni/imagetargets/Android.mk
Note: I started from the Vuforia SDK ImageTargets example and added
some other libraries like reading OBJ, PNG and ZIP files. I've also
included the freetype and ftgles library.
I call the other make files from my the root Android.mk file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include jni/libobj/Android.mk
include jni/libpng/Android.mk
include jni/libzip/Android.mk
include jni/freetype/Android.mk
include jni/ftgles/Android.mk
include jni/qcar/Android.mk
include jni/imagetargets/Android.mk
You can see all make files in a gist on github.
The compiler gives following error:
Install : libFTGLES.so => libs/armeabi/libFTGLES.so Compile++
arm : ImageTargets <= ImageTargets.cpp
jni/imagetargets/ImageTargets.cpp:44:24: fatal error: libpng/png.h: No
such file or directory compilation terminated. make: *
[obj/local/armeabi/objs/ImageTargets/ImageTargets.o] Error 1
Any idea how to make the libpng (and other modules) headers available for the imagetargets module?
I think that specifying the path to the includes in each sub-makefile using LOCAL_EXPORT_C_INCLUDES would ensure that the headers are available when building the final module.
Check the documentation for this flag in the NDK documentation (available in your NDK directory), but from what I understand, it will do exactly what you're trying to do: automatically export the include path of each sub-module to the final module.

Linker trouble when using LuaJIT prebuilt static library with android under cygwin

I think I spent most of yesterday unsuccessfully wrestling with this, any help would greatly appreciated and make me extremely happy! Even a next step to try to find the root of the issue is something I'm stuck on at the moment!
I have an Android 2.2 project that's trying to reference a prebuilt LuaJIT static library but ndk-build gives me this error:
test_android.cpp:25: undefined reference to `luaL_newstate'
I built LuaJIT as liblua.a, I've placed that in the root of my JNI directory with the relevant headers. I've have one Android.mk as shown below:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := lua
LOCAL_SRC_FILES := liblua.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_CFLAGS := -Werror
LOCAL_SRC_FILES := test_android.cpp
LOCAL_LDLIBS := -llog -lGLESv2
LOCAL_STATIC_LIBRARIES := lua
include $(BUILD_SHARED_LIBRARY)
In test_andrdoid.cpp I've got this code:
extern "C"
{
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
void test()
{
lua_State* lua = lua_open();
}
This seems like a linker error, for some reason the static library file is not being correctly referenced. But, to me, the makefile seems correct.
Any help would be greatly appreciated!
To start with: is there anyway to see how everything is being linked
together and if my shared library module is really get access
to the static library?
Additional Information
Here's extra information that I think could be relevant!
Building the library
Maybe it's the static lib file that's not correct? (Is there anywhere I could download a prebuilt one to check?). I made it with this script (from the LuaJIT website). I'm using the latest stable LuaJIT, 1.1.8
NDK=/cygdrive/c/android-ndk-r8b
NDKABI=8
NDKVER=$NDK/toolchains/arm-linux-androideabi-4.4.3
NDKP=$NDKVER/prebuilt/linux-x86/bin/arm-linux-androideabi-
NDKF="--sysroot $NDK/platforms/android-$NDKABI/arch-arm"
make linux HOST_CC="gcc -m32" CROSS=$NDKP TARGET_FLAGS="$NDKF"
This builds fine and creates a liblua.a in the /src/ directory. (I ran nm on it and it lists out all the function prototypes I'd expect). I don't know if there's anything else I can do to ensure it's really a build for ARM?
NDKABI=8 means I'm targeting Android 2.2
Setting up the test Android Project
I create a brand new 2.2 android project using this command:
android create project --target 3 --name test --path . --activity TestActivity --package com.test
Target 3 maps to Android 2.2 on my system (using android list devices).
I create the jni folder and have a test_android.h and test_android.cpp. Then I use ndk-build to build them - which works fine when I'm not trying to reference LuaJIT. When I do try and use Lua I get the following error:
Full Error Message
Cygwin : Generating dependency file converter script
Compile++ thumb : test <= test_android.cpp
In file included from jni/test_android.h:3:0, from jni/test_android.cpp:2:
C:/android-ndk-r8b/platforms/android-8/arch-arm/usr/include/jni.h:592:13: note:
the mangling of 'va_list' has changed in GCC 4.4
Prebuilt : liblua.a <= jni/
StaticLibrary : libstdc++.a
SharedLibrary : libtest.so
obj/local/armeabi/objs/test/test_android.o: In function `test()':
C:\Users\Grrr\Documents\mycode\static_lib_test/jni/test_android.cpp:25: undefined reference to `luaL_newstate'
collect2: ld returned 1 exit status
/cygdrive/c/android-ndk-r8b/build/core/build-binary.mk:378: recipe for target `obj/local/armeabi/libtest.so' failed make: *** [obj/local/armeabi/libtest.so] Error 1
Most of the issues I've seen searching around are due to the local library include order, as I only have one library this shouldn't be an issue and suggests I've managed to get something more fundamental wrong :)
Update
I've since built normal Lua and added that as prebuilt static library and it works fine. I suspect its how I've built LuaJIT but I'm not sure how to correctly build it, or find a working prebuilt version.
The linking for this was fine, or at least the makefile was.
The problem was the LuaJIT library wasn't built for ARM (I used objdump -a lualib.a, to check this). I downloaded the latest LuaJIT, ran the script under linux and got an ARM library. Everything links nicely now!

Categories

Resources