How to render a bitmap in NDK using OpenGL ES 2.0 - android

OS: Windows 7
SDK: adt-bundle-windows-x86-20130717
NDK: android-ndk-r8e
Eclipse ADT: Build: v22.0.4-741630
I'm trying to render a bitmap using OpenGL ES in JNI. I have these headers declared at the top of the file:
#include <android/bitmap.h>
#include <GLES2/gl2.h>
so I don't understand why tokens such as GL_TEXTURE_2D are reported as "could not be resolved" and the project doesn't build. The frustrating part is that functions and variables defined in bitmap.h such as AndroidBitmap_getInfo() and ANDROID_BITMAP_FORMAT_RGB_565 don't cause a problem; they resolve properly.
The C/C++>General>Paths and Symbols properties for the project has this path:
C:\Android\android-ndk-r8e-windows-x86\android-ndk-r8e\platforms\android-9\arch-arm\usr\include
I see the tree structure in the header node of the Eclipse project and I've confirmed that android & GLES2 folders exist at that path location and each contain the appropriate .h file (bitmap.h and gl2.h respectively). How can it be that bitmap.h resolves but gl2.h doesn't? I'm declaring the includes exactly the same way!
Application.mk:
APP_PLATFORM := android-10
APP_ABI := armeabi-v7a
Any troubleshooting tips?
Thanks

Have you ever tried the sample code bitmap-plasma & hello-gl2 in NDK package? you can check relevant Android.mk. make sure you have linked correct libraries
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libgl2jni
LOCAL_CFLAGS := -Werror
LOCAL_SRC_FILES := gl_code.cpp
LOCAL_LDLIBS := -llog -lGLESv2 -lm -ljnigraphics
include $(BUILD_SHARED_LIBRARY)

Related

Linker errors with external NDK library that needs 'cpufeatures'

I'm trying to build and link freeimage to an android project. I'm close but I'm tripping up on some linker errors from that library.
I'm using this repo: https://github.com/jamcar23/FreeImage-Android/blob/master/jni/freeimage/Android.mk
Freeimage uses the internal NDK library 'cpufeatures' to use xeon chipset features. In the project's 'android.mk', there's a reference to the cpufeatures library:
LOCAL_STATIC_LIBRARIES := cpufeatures
and my library, which statically links to this one, also includes cpufeatures in its LOCAL_STATIC_LIBRARIES statement in that project's android.mk:
LOCAL_STATIC_LIBRARIES := tinyxml freetype2 bullet freeimage cpufeatures
also in my android.mk, I link freeimage like this:
#####FREEIMAGE_LIBRARY_DECLARATION##########
include $(CLEAR_VARS)
LOCAL_PATH = $(TPLIBROOT)/FreeImage-Android
LOCAL_MODULE := freeimage
LOCAL_EXPORT_C_INCLUDES := include
LOCAL_SRC_FILES := obj/local/$(TARGET_ARCH_ABI)/libFreeImage.a
include $(PREBUILT_STATIC_LIBRARY)
###############################################
which, taking note of a previous question I had about the NDK, should take care of specific architectures (I've build freeimage using all available architectures)
freeimage .a and .so libraries appear to build fine but on linking to my library when building the .so, I get this error:
[armeabi-v7a] SharedLibrary : libAnthracite.so
jni/freeimage/Source/LibWebP/./src/dsp/dsp.cpu.c:108: error: undefined reference to 'android_getCpuFamily'
jni/freeimage/Source/LibWebP/./src/dsp/dsp.cpu.c:109: error: undefined reference to 'android_getCpuFeatures'
jni/freeimage/Source/LibWebP/./src/dsp/dsp.dec.c:745: error: undefined reference to 'VP8DspInitNEON'
which is odd as both libraries do link cpufeatures, so it really ought to be there.
I'm declaring
APP_PLATFORM := android-14
APP_STL := gnustl_static
in the application.mk files for both projects.
Also, I've tried placing 'LOCAL_STATIC_LIBRARIES' in different positions in the files and linking libraries in different orders, although that's just guesswork.
Does anybody know what might be causing these linker errors?
Please follow the official guide to add cpu-features. TL;NR: add $(call import-module,android/cpufeatures) to your Android.mk.
I finally got it to work by ensuring that all of my 'application.mk' files for all four of the third party libraries I was using shared a common base file that looks like this:
APP_PLATFORM := android-15
APP_STL := c++_static
APP_ABI := all
APP_OPTIM := release
APP_SHORT_COMMANDS := true
Which makes keeping them in line easier, ensuring they're all built against the same libraries.
Also, I changed the STL implementation from 'gnustl_static' to 'c++_static'

How to include a prebuilt "*.a" library (from tensorflow) to my android NDK project with no Android.mk file?

I'm trying to compile my application to use tensorflow C++ library after building lintensorflow_core.a into my NDK application. The application has the main java layer, that communicates with the NDK component. In that NDK component, I'm looking to call the tensorflow as such: using namespace ::tensorflow::ops; // NOLINT(build/namespaces)
I've seen bunch of links on how to do it with Android.mk file. But apparently, that does not gets created anymore in the new version of android studio. If it is possible with just Android.mk and ndk-build command, that would be great as well. However, the combination of Android.mk and ndk-build has also failed me. The output basically nothing.
I did have plenty of variation of Android.mk file and here's one of them:
LOCAL_PATH := $(call my-dir)
TENSORFLOW_HOME := $(LOCAL_PATH)/../../../../../tensorflow
TENSORFLOW_CORE := $(LOCAL_PATH)/../../../../../tensorflow/tensorflow/core
TENSORFLOW_OPS := $(LOCAL_PATH)/../../../../../tensorflow/tensorflow/core/ops
include $(CLEAR_VARS)
LOCAL_MODULE := tensorflow
LOCAL_SRC_FILES := $(TENSORFLOW_HOME)/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a
LOCAL_LDLIBS := -static -Wl,--build-id -Wl,--allow-multiple-definition -Wl,--whole-archive
LOCAL_CFLAGS := -std=c++11 -I$(TENSORFLOW_HOME)
LOCAL_C_INCLUDES := $(TENSORFLOW_OPS)
TARGET_ARCH_ABI := armeabi
include $(PREBUILT_STATIC_LIBRARY)
But this has been a total failure. Could someone point me to the right direction?

Android can't include linux in C program with Android.mk

I'm trying to compile a C program for Android 6. This is my Android.mk:
APP_PLATFORM := android-23
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Enable PIE manually. Will get reset on $(CLEAR_VARS). This
# is what enabling PIE translates to behind the scenes.
LOCAL_CFLAGS += -fPIE -DHAVE_FANOTIFY=1 -DHAVE_SYS_FANOTIFY=0
LOCAL_LDFLAGS += -fPIE -pie
# give module name
LOCAL_MODULE := fsmon
# list your C files to compile
LOCAL_SRC_FILES := inotify.c fanotify.c util.c main.c
# this option will build executables instead of building library for android application.
include $(BUILD_EXECUTABLE)
In the fanotify.c following include is written:
#include <linux/fanotify.h>
When I try to use ndk-build, following error appears:
fsmon/jni/fanotify.c:51:10: fatal error: 'linux/fanotify.h' file not found
#include <linux/fanotify.h>
^
The header fanotify.h is present in the ndk path /Android/Sdk/ndk-bundle/sysroot/usr/include/linux
Any suggestions?
EDIT: Same error if I try to include sys/fanotify.h
You can specify additional include paths for your module using LOCAL_C_INCLUDES.
LOCAL_C_INCLUDES := /Android/Sdk/ndk-bundle/sysroot/usr/include/
https://developer.android.com/ndk/guides/android_mk.html#mdv
The NDK historically didn't backport headers to old releases, but we've reworked things in r14 so this is possible: https://android.googlesource.com/platform/ndk/+/ndk-r14-release/docs/UnifiedHeaders.md
By default in r14 you still get the old form of the headers. The new "unified headers" have the headers you're looking for. If you want to try unified headers, set APP_UNIFIED_HEADERS := true in your Application.mk (settings for other build systems can be found in the link above).
In r15 (first beta due out soon), the default has changed to the new headers, and the option for disabling them has changed (see the same doc in r15 for changes in options: https://android.googlesource.com/platform/ndk/+/ndk-r15-release/docs/UnifiedHeaders.md).

Android NDK cannot find -lGLESv

I am getting the following errors when I try to perform an NDK build, can anyone help me please?
I did the setup instruction exactly like what are written in "Beginning Android C++ Game Development". every step except the 9th:
"Click the NativeActivity node in the Application Nodes window and click Add once more. Enter the Name as android.app.lib_name and the Value as the LOCAL_MODULE name, which can be found in the Android.mk file in the project’s jni folder."
Errors :
10:44:23 ** Incremental Build of configuration Default for project
HelloDroid ** "C:\ndk\ndk-build.cmd" all Android NDK:
WARNING:jni/Android.mk:HelloDroid-Test: non-system libraries in linker
flags: -lGLESv Android NDK: This is likely to result in
incorrect builds. Try using LOCAL_STATIC_LIBRARIES Android NDK:
or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of
the Android NDK: current module [armeabi] SharedLibrary :
libHelloDroid-Test.so
C:/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe:
error: cannot find -lGLESv collect2: ld returned 1 exit status
make.exe: * [obj/local/armeabi/libHelloDroid-Test.so] Error 1
10:44:23 Build Finished (took 226ms)
I found the problem.
I just needed to edit the Android.mk
it now looks like this:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hellodroid
LOCAL_SRC_FILES := hellodroid.cpp
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module, android/native_app_glue)
As the error states, there is no lib GLESv.
Which version of OpenGL ES are you using, 1 or 2?
The linker flags are -lGLESv1_CM and -lGLESv2, respectively.

Error: selected processor does not support ARM mode

I'm trying to build a jni project which generates a shared library using the Android-ndk.
I'm going to code a some part in assembly language as needed, so I configured the project as the following.
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := my_test
LOCAL_SRC_FILES := Test.cpp MyAsm.s
LOCAL_CFLAGS :=
include $(BUILD_SHARED_LIBRARY)
Application.mk:
APP_ABI := armeabi-v7a
APP_STL := stlport_static
Test.cpp:
...
MyAsmFunc();
...
MyAsm.s:
.text
.align 2
.global MyAsmFunc
MyAsmFunc:
...
tbb [PC,R1]
...
cbnz R1,loc_51ACE
...
When I was compiling the project, I've got the following error msg.
MyAsm.s:224: Error: selected processor does not support ARM mode `tbb [PC,R1]'
MyAsm.s:882: Error: selected processor does not support ARM mode `cbnz R1,loc_51ACE'
My question is how to build the project successful. Help me, please.
Thanks in advance.
According to this page,
These 16-bit Thumb instructions are available in ARMv6T2 and above.
There are no ARM or 32-bit Thumb versions of these instructions.
You're compiling for ARMv7-A, so the first part is fine. However, it's trying to interpret the instructions as ARM rather than THUMB/THUMB2. Add .thumb / .thumb_func directives to your assembly source file to set THUMB mode. See also the GNU as docs.

Categories

Resources