Sample Android NDK hello-gl2 unable to compile on Android Studio - android

I'm able to run the hello-jni of the samples provided in the NDK but I can't compile the hello-gl2 sample.
Could you help me? (I think is a problem linking with OpenGL)
This are the errors reported by Android Studio:
C:\AndroidstudioProjects\hello-gl2\app\src\main\jni\gl_code.cpp
Error:(39) undefined reference to `glGetError'
Error:(41) undefined reference to `__android_log_print'
Error:(40) undefined reference to `glGetError'
Error:(34) undefined reference to `glGetString'
Error:(35) undefined reference to `__android_log_print'
Error:(58) undefined reference to `glCreateShader'
Error:(60) undefined reference to `glShaderSource'
Error:(61) undefined reference to `glCompileShader'
Error:(63) undefined reference to `glGetShaderiv'
Error:(66) undefined reference to `glGetShaderiv'
Error:(70) undefined reference to `glGetShaderInfoLog'
Error:(72) undefined reference to `__android_log_print'
Error:(75) undefined reference to `glDeleteShader'
...

In your Android.mk file (in the /jni folder), there should be a LOCAL_LDLIBS line. Some of the libraries that come bundled with Android need to be indicated here. Try the following
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM
Or at least add the options -lEGL and -lGLESv1_CM. The first is the EGL library, and the second is the GLES library.
I don't know if the last one is the right version number for your project though.

Finally I used eclipse (for those that are dealing with the same problems) and with Eclipse all went fine.

Related

android cmake undefined reference to properties defined in libuv headers

there is a source code which is built fine (using cmake) for my host platform but when i target android(using android studio cmake) on the same platfrom it gives me the following errors:
Error:error: cannot find -l[/root/libuv-1.x/out/cmake/libuv.a]
Error:error: cannot find -lpthread
Error:(49) undefined reference to 'uv_default_loop'
Error:(84) undefined reference to 'uv_fs_open'
Error:(49) undefined reference to 'uv_now'
...
any reference to properties defined in uv headers creates a undefined reference to x error.
this is how i include uv in the project cmake:
set(UV_INCLUDE_DIR "[/root/libuv-1.x/include/]")
set(UV_LIBRARY "[/root/libuv-1.x/out/cmake/libuv.a]")
find_package(UV REQUIRED)
include_directories("/root/libuv-1.x/include/")
include_directories(${UV_INCLUDE_DIR})
and this is how i compile and link the source code in cmake:
add_library(proto-lib SHARED ${HEADERS} ${SOURCES} ${HTTPD_SOURCES})
target_link_libraries(proto-lib ${UV_LIBRARIES} ${EXTRA_LIBS})
the libuv doesn't seem to be included at all.
how can i fix this?

Undefined reference to isfinite

I had following error when done cross compilation for android.
Cross compiler used SDK/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/arm-linux-androideabi'
./libgpsd.a(libgpsd_core.o):libgpsd_core.c:function gpsd_poll: error: undefined reference to '__isfinite'
./libgpsd.a(libgpsd_core.o):libgpsd_core.c:function gpsd_poll: error: undefined reference to '__isfinite'
./libgpsd.a(libgpsd_core.o):libgpsd_core.c:function gpsd_poll: error: undefined reference to '__isfinite'
./libgpsd.a(libgpsd_core.o):libgpsd_core.c:function gpsd_poll: error: undefined reference to '__isfinite'
The function infinite() is part of C99. Add LOCAL_CFLAGS += -std=c99 to your Android.mk. See question How to set standard c99 for compile android NDK project

Android NDK error: undefined reference

There have been some questions similar to mine, but it seems that their solutions don't work for me.
I'm trying to compile dumpsys source code using Android NDK. I have added a couple of lines to Android.mk to include the libraries.
The final Android.mk file looks like this:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
dumpsys.cpp
LOCAL_SHARED_LIBRARIES := \
libutils \
liblog \
libbinders
ANDROID_SRC="my android source directory"
LOCAL_C_INCLUDES := ${ANDROID_SRC}/frameworks/native/include \
${ANDROID_SRC}/system/core/include
#$(warning $(TARGET_C_INCLUDES))
LOCAL_MODULE:= dumpsys
TARGET_ARCH := arm
TARGET_ARCH_ABI := armeabi-v7a
include $(BUILD_EXECUTABLE)
when I execute ndk-build, I get the following errors:
/home/mahdi/university/androidsource/system/core/include/utils/TypeHelpers.h:144: error: undefined reference to 'android::String16::~String16()'
/home/mahdi/university/androidsource/system/core/include/utils/Vector.h:240: error: undefined reference to 'android::VectorImpl::finish_vector()'
/home/mahdi/university/androidsource/system/core/include/utils/Vector.h:241: error: undefined reference to 'android::VectorImpl::~VectorImpl()'
/home/mahdi/university/androidsource/system/core/include/utils/TypeHelpers.h:135: error: undefined reference to 'android::String16::String16()'
/home/mahdi/university/androidsource/system/core/include/utils/TypeHelpers.h:154: error: undefined reference to 'android::String16::String16(android::String16 const&)'
/home/mahdi/university/androidsource/system/core/include/utils/TypeHelpers.h:166: error: undefined reference to 'android::String16::String16(android::String16 const&)'
/home/mahdi/university/androidsource/system/core/include/utils/String16.h:178: error: undefined reference to 'strzcmp16'
/home/mahdi/university/androidsource/system/core/include/utils/StrongPointer.h:143: error: undefined reference to 'android::RefBase::decStrong(void const*) const'
jni/dumpsys.cpp:32: error: undefined reference to 'android::defaultServiceManager()'
jni/dumpsys.cpp:35: error: undefined reference to '__android_log_print'
/home/mahdi/university/androidsource/system/core/include/utils/Vector.h:224: error: undefined reference to 'android::VectorImpl::VectorImpl(unsigned int, unsigned int)'
/home/mahdi/university/androidsource/system/core/include/utils/Vector.h:224: error: undefined reference to 'android::VectorImpl::VectorImpl(unsigned int, unsigned int)'
/home/mahdi/university/androidsource/system/core/include/utils/Vector.h:245: error: undefined reference to 'android::VectorImpl::operator=(android::VectorImpl const&)'
/home/mahdi/university/androidsource/system/core/include/utils/Vector.h:378: error: undefined reference to 'android::VectorImpl::sort(int (*)(void const*, void const*))'
jni/dumpsys.cpp:49: error: undefined reference to 'android::String16::String16(char const*)'
/home/mahdi/university/androidsource/system/core/include/utils/Vector.h:338: error: undefined reference to 'android::VectorImpl::add(void const*)'
jni/dumpsys.cpp:49: error: undefined reference to 'android::String16::~String16()'
jni/dumpsys.cpp:51: error: undefined reference to 'android::String16::String16(char const*)'
/home/mahdi/university/androidsource/system/core/include/utils/Vector.h:338: error: undefined reference to 'android::VectorImpl::add(void const*)'
jni/dumpsys.cpp:51: error: undefined reference to 'android::String16::~String16()'
jni/dumpsys.cpp:53: error: undefined reference to 'android::String16::String16(char const*)'
/home/mahdi/university/androidsource/system/core/include/utils/Vector.h:338: error: undefined reference to 'android::VectorImpl::add(void const*)'
jni/dumpsys.cpp:53: error: undefined reference to 'android::String16::~String16()'
jni/dumpsys.cpp:66: error: undefined reference to 'android::operator<<(android::TextOutput&, android::String16 const&)'
jni/dumpsys.cpp:81: error: undefined reference to 'android::operator<<(android::TextOutput&, android::String16 const&)'
jni/dumpsys.cpp:89: error: undefined reference to 'android::operator<<(android::TextOutput&, android::String16 const&)'
/home/mahdi/university/androidsource/system/core/include/utils/StrongPointer.h:143: error: undefined reference to 'android::RefBase::decStrong(void const*) const'
jni/dumpsys.cpp:94: error: undefined reference to 'android::aerr'
jni/dumpsys.cpp:94: error: undefined reference to 'android::aout'
collect2: error: ld returned 1 exit status
How should I solve this issue?
Thanks in advance.
I'm working on a similar issue here.
Basically, dumpsys is an AOSP component and intended to be built with the AOSP toolchain. You will need to apply some tweaks to port it to NDK – including stuff from ${ANDROID_SRC} is the first step but not the whole story.
You've successfully included the headers and thus made the compiler happy. Now the linker is complaining because it cannot find the libraries you are linking against. The good news is that they are shared libraries, thus having the libraries around at build time isn't a strict requirement.
The NDK defines a stable API of libraries you can use, which is documented here. liblog is in that list and can be included by adding the following lines to Android.mk:
LOCAL_LDLIBS := \
-llog \
The other two libraries are not part of the stable API. This essentially means that even if your code works on a particular version of Android, it may break on any later version because the API may have changed – you might want to bear this in mind.
Since these libraries are shared, all ld does is check if they actually provide the functions you're using. This question and its accepted answer have instructions for getting rid of the related error messages:
One way is to use something like:
LOCAL_LDFLAGS := -Wl,--unresolved-symbols=ignore-all
However, this will bypass all checks – so if you try to use a function that is indeed absent from the library, ld has no chance of warning you.
The cleaner, but more work-intensive approach, is to provide stub libraries. A stub library is essentially a dummy library which defines the same symbols (functions etc.) as the "real" thing but has no implementation (functions simply return without doing anything). It's enough to make the linker happy, but the libraries are not shipped and their "real" counterparts are used at runtime.
You would need to get the source code for the two libraries, which reside in the following directories: libutils and libbinders
system/core/libutils
frameworks/native/libs/binder
Copy these two dirs into your project's jni dir. Then strip the code down:
* Edit Android.mk, removing all build targets other than BUILD_SHARED_LIBRARY.
* Edit the source code files, replacing all function bodies with a simple return. It doesn't matter what you return, as long as you get the code to compile.
Eventually you will probably need to prevent the stub libraries from getting included in your .apk (I have yet to figure out how to do that).

How to link multiple static libs in android shared lib

I have pre build boost libs for android using standalone tool chain 4.8.
I want to use he following boost libs and added as following in Android.mk
LOCAL_STATIC_LIBRARIES += libboost_atomic \
libboost_date_time \
libboost_exception \
libboost_thread \
libboost_system \
libboost_filesystem
I have adde my own static lib liblocal.a in Android.mk.
I have a mainactivity.cpp file in my JNI folder of android project.
I am including header.h in mainactivity.h. header.h had class declaration for classA which uses boost libs.
while building liblocal.a, I am not getting any link error for boost.
While inclduding header.h in mainactivity.h I am getting the following link error:
../../../3p/boost/android/include/boost/system/error_code.hpp:222: error: undefined reference to 'boost::system::generic_category()'
../../../3p/boost/android/include/boost/system/error_code.hpp:223: error: undefined reference to 'boost::system::generic_category()'
../../../3p/boost/android/include/boost/system/error_code.hpp:224: error: undefined reference to 'boost::system::system_category()'
../../../3p/boost/android/include/boost/system/error_code.hpp:222: error: undefined reference to 'boost::system::generic_category()'
../../../3p/boost/android/include/boost/system/error_code.hpp:223: error: undefined reference to 'boost::system::generic_category()'
../../../3p/boost/android/include/boost/system/error_code.hpp:224: error: undefined reference to 'boost::system::system_category()'
../../../3p/boost/android/include/boost/system/error_code.hpp:224: error: undefined reference to 'boost::system::system_category()'
Thanks,
Birajendu
If liblocal.a depends on functions defined in libboost_foo.a, then it must appear before it in the list of static libraries, i.e.:
LOCAL_STATIC_LIBRARIES += liblocal.a libboost_foo.a # GOOD
Should work, while the following:
LOCAL_STATIC_LIBRARIES += libboost_foo.a liblocal.a # BAD
will not, and result in a link error like the one you described.
A work-around is to use LOCAL_WHOLE_STATIC_LIBRARIES that always forces all content from the listed static libraries to be included in the result (this typically generates bloated binaries, but may be necessary if you have circular dependencies).
Hope this helps.
Solved:
I have added LOCAL_LDLIBS += -L$(RELATIVE_PATH_TO_LIB) -lmylib -lmylib1, this solved this issue.
Where as mylib.a and mylib1.a are my pre build static libs.

Android - error: undefined reference to 'vtable for __cxxabiv1::__si_class_type_info'

Ok, I give up...
I've been trying to compile android's 4.x (x>=1) webkit to bypass the 4.0 bugs.
After a few compilations, of the libwebcore with correct bindings and different namespace, and android.webkit with different namespace and some code fixes to match 4.0 - it compiles, and works, on Android 4.3.
Additional problems came in when trying to run it on 4.0-4.2 - where I found out the libicuuc is incompatible between versions, as versioning occurs in the function names. So the solution is theoretically simple - compile libicuuc statically into the libwebcore, by adding LOCAL_STATIC_LIBRARIES += libicuuc to the Android.mk
This is where hell began: I get errors like error: undefined reference to 'vtable for __cxxabiv1::__si_class_type_info' and error: undefined reference to '__dynamic_cast'.
I tried adding LOCAL_RTTI_FLAG := -frtti but it didn't change anything.
Any ideas?
Thanks!

Categories

Resources